Home > Blockchain >  Android 12 APK throws invalid package upon install
Android 12 APK throws invalid package upon install

Time:02-08

I have an Azure build pipeline which is producing an APK which installs (via AppCenter) just fine on Android 10 but pops up the error:

App not installed as package appears to be invalid

on Android 12.

The AndroidManifest.xml in the solution looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.app.myapplocal" android:installLocation="auto" android:versionCode="1" android:versionName="1.1">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <application android:label="L MyApp" android:icon="@drawable/icon" android:largeHeap="true"></application>
</manifest>

When I examine the manifest via Android Studio's APK Analyze option, I see this:

<uses-sdk
    android:minSdkVersion="21"
    android:targetSdkVersion="31" />

<uses-permission
    android:name="android.permission.FLASHLIGHT" />

<uses-permission
    android:name="android.permission.INTERNET" />

<uses-permission
    android:name="android.permission.CAMERA" />

<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:label="D MyApp"
    android:icon="@ref/0x7f07015e"
    android:name="crc646948444ac10504e5.MainApplication"
    android:debuggable="true"
    android:allowBackup="true"
    android:largeHeap="true"
    android:extractNativeLibs="true">

    <meta-data
        android:name="com.google.android.gms.vision.DEPENDENCIES"
        android:value="barcode" />

    <activity
        android:theme="@ref/0x7f0d0001"
        android:label="MyApp"
        android:icon="@ref/0x7f07015e"
        android:name="crc646948444ac10504e5.MainActivity"
        android:screenOrientation="1"
        android:configChanges="0x680" />

    <activity
        android:theme="@ref/0x7f0d0000"
        android:name="crc646948444ac10504e5.SplashActivity"
        android:exported="true"
        android:screenOrientation="1"
        android:noHistory="true">

        <intent-filter>

            <action
                android:name="android.intent.action.MAIN" />

            <category
                android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:label="Web Authenticator"
        android:name="crc641e66d166111bdf3e.FormAuthenticatorActivity" />

    <activity
        android:label="Web Authenticator"
        android:name="crc641e66d166111bdf3e.WebAuthenticatorActivity" />

    <activity
        android:label="Web Authenticator Native Browser"
        android:name="crc641e66d166111bdf3e.WebAuthenticatorNativeBrowserActivity"
        android:launchMode="1" />

    <activity
        android:name="com.microsoft.windowsazure.mobileservices.authentication.RedirectUrlActivity" />

    <service
        android:name="crc64a98abb514ffad9f1.KeepAliveService" />

    <receiver
        android:label="Essentials Connectivity Broadcast Receiver"
        android:name="crc64a0e0a82d0db9a07d.ConnectivityBroadcastReceiver"
        android:enabled="true"
        android:exported="false" />

    <receiver
        android:name="crc643f46942d9dd1fff9.PowerSaveModeBroadcastReceiver"
        android:enabled="true"
        android:exported="false" />

    <provider
        android:name="mono.android.MultiDexLoader"
        android:exported="false"
        android:authorities="com.app.myapp.mono.android.MultiDexLoader.__mono_init__"
        android:initOrder="1999999999" />

    <provider
        android:name="mono.MonoRuntimeProvider"
        android:exported="false"
        android:authorities="com.app.myapp.mono.MonoRuntimeProvider.__mono_init__"
        android:initOrder="1999999998" />

    <activity
        android:theme="@ref/0x01030010"
        android:name="com.google.android.gms.common.api.GoogleApiActivity"
        android:exported="false" />

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@ref/0x7f090008" />
</application>

<uses-permission
    android:name="android.permission.ACCESS_NETWORK_STATE" />

I had previously thought that the problem with Android 12 was that the android:targetSdkVersion was set to 29 but changing this in the solution's manifest and changing the project file's TargetFrameworkVersion from v11.0 to v12.0 did not help either. (This was updated in Visual Studio using the project properties' Application > Compile using Android version value.)

What might I be missing in order to allow installing on recent Android devices? (I am not familiar with Xamarin or Android, I'm afraid.)

CodePudding user response:

If you have bumped the compile version to 31, then you need to add

android:exported="true"

To your activities, services and receivers. See here.

In your case

<uses-sdk
    android:minSdkVersion="21"
    android:targetSdkVersion="31" />

<uses-permission
    android:name="android.permission.FLASHLIGHT" />

<uses-permission
    android:name="android.permission.INTERNET" />

<uses-permission
    android:name="android.permission.CAMERA" />

<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:label="D MyApp"
    android:icon="@ref/0x7f07015e"
    android:name="crc646948444ac10504e5.MainApplication"
    android:debuggable="true"
    android:allowBackup="true"
    android:largeHeap="true"
    android:extractNativeLibs="true">

    <meta-data
        android:name="com.google.android.gms.vision.DEPENDENCIES"
        android:value="barcode" />

    <activity
        android:theme="@ref/0x7f0d0001"
        android:label="MyApp"
        android:icon="@ref/0x7f07015e"
        android:name="crc646948444ac10504e5.MainActivity"
        android:screenOrientation="1"
        android:configChanges="0x680"
        android:exported="true"/>

    <activity
        android:theme="@ref/0x7f0d0000"
        android:name="crc646948444ac10504e5.SplashActivity"
        android:exported="true"
        android:screenOrientation="1"
        android:noHistory="true">

        <intent-filter>

            <action
                android:name="android.intent.action.MAIN" />

            <category
                android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:label="Web Authenticator"
        android:name="crc641e66d166111bdf3e.FormAuthenticatorActivity" 
        android:exported="true"/>

    <activity
        android:label="Web Authenticator"
        android:name="crc641e66d166111bdf3e.WebAuthenticatorActivity" 
        android:exported="true"/>

    <activity
        android:label="Web Authenticator Native Browser"
        android:name="crc641e66d166111bdf3e.WebAuthenticatorNativeBrowserActivity"
        android:launchMode="1"
        android:exported="true"/>

    <activity
        android:name="com.microsoft.windowsazure.mobileservices.authentication.RedirectUrlActivity"
        android:exported="true"/>

    <service
        android:name="crc64a98abb514ffad9f1.KeepAliveService"
        android:exported="true"/>
    <receiver
        android:label="Essentials Connectivity Broadcast Receiver"
        android:name="crc64a0e0a82d0db9a07d.ConnectivityBroadcastReceiver"
        android:enabled="true"
        android:exported="false" />

    <receiver
        android:name="crc643f46942d9dd1fff9.PowerSaveModeBroadcastReceiver"
        android:enabled="true"
        android:exported="false" />

    <provider
        android:name="mono.android.MultiDexLoader"
        android:exported="false"
        android:authorities="com.app.myapp.mono.android.MultiDexLoader.__mono_init__"
        android:initOrder="1999999999" />

    <provider
        android:name="mono.MonoRuntimeProvider"
        android:exported="false"
        android:authorities="com.app.myapp.mono.MonoRuntimeProvider.__mono_init__"
        android:initOrder="1999999998" />

    <activity
        android:theme="@ref/0x01030010"
        android:name="com.google.android.gms.common.api.GoogleApiActivity"
        android:exported="false" />

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@ref/0x7f090008" />
</application>

<uses-permission
    android:name="android.permission.ACCESS_NETWORK_STATE" />

Please be wary of what really needs to be exported or not and change accordingly.

It could also be the case that App Center as of Android 11 requires a mandatory app signer, see here, here, and just in case, here is the snippet

As of Android 11, it's mandatory to use the APK signer (if you use API level 30) as it will set some extra schemes "APK Signature Scheme v2 now required". App Center now (since Dec 17, 2020) signs Android applications using APK signer internally, instead of JAR signer which was used previously. As part of the feature to enable APK signer in App Center, Android signing task V3 was implemented, and requirements for new Signing task were to change how keystore file is saved - to store the keystore file in an AzDO secure file (Android signing build and release task - Azure Pipelines | Microsoft Docs).

Warning Any build configurations that had their keystore files uploaded prior to Dec 17, 2020 still use the APK Signature Scheme v2 signing method (jarsigner). To use the APK Signature Scheme v3 signing flow, users just have to re-upload their keystore files and save their branch configuration.

CodePudding user response:

It may be that it doesn't like the install location "auto", resulting in:

android:installLocation="0"

Which should be one of:

android:installLocation=["auto" | "internalOnly" | "preferExternal"]
  •  Tags:  
  • Related