Android 12 APK throws invalid package upon install
Asked Answered
S

4

8

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.)

Stinkpot answered 7/2, 2022 at 16:54 Comment(1)
You have to grab a logcat on install time to get more details about an error, because package appears to be invalid isn't helpful at allDamnify
S
10

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.

Shaun answered 7/2, 2022 at 17:11 Comment(8)
Trying to identify what the activity, service or receiver entry in my manifest is. Could you indicate which line contains those, please?Stinkpot
The link posted shows an exampleShaun
I understand that the produced manifest contains those things, just not what they are in my solution's manifest. I have posted the complete manifest from the APK. Should I be adding entries into my solution manifest's <application> element and decorating them with android:exported?Stinkpot
I will update my answer with the corrected manifest you have providedShaun
I understand that the resulting manifest file in the apk should look like what you've posted, but if you see the manifest in my actual solution, it contains very little. How do I configure it for activities, service and receivers when I do not know what they are? AFAIK they are being added during compilation.Stinkpot
Hmm, ok, understood. I added an extra solution in the case that this would be your issueShaun
@Shaun legend. In my case, simply re-uploading the exact same keystone file within App Center did the trick.Rabelais
You only have to add android:exported="true" in tags which contain an <intent-filter>, not in all tags. Check the doc hereSikorski
S
2

App Not Installed As Package Appears To Be Invalid [Fixed]

After changing compileSdkVersion , targetSdkVersion to 31 , If anyone getting this above error on Android 12 / 13 preview version. Update all of your dependencies to latest one and Please add -

android:exported="true"

to any <activity>, <activity-alias>,<service>, or <receiver> components that have <intent-filter>s declared in the app’s inside AndroidManifest.xml file. After that do gradlew clean and to test the changes create a new device with android 12/13 configuration in your android emulator and to install this app from release version you have to run this command npx react-native run-android --variant=release

Slat answered 7/2, 2023 at 13:56 Comment(0)
S
0

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"]
Sciatic answered 7/2, 2022 at 17:19 Comment(2)
If I read the documentation you linked to correctly, the two allowed values for that property are auto and preferExternal. I have auto.Stinkpot
Without console output, this basically is a duplicate of: stackoverflow.com/search?q=INSTALL_FAILED_INVALID_APKSciatic
L
0

Make sure that compileSdkPreview = "UpsideDownCake" is commented out within your app build.gradle.

Like that:

//compileSdkPreview = "UpsideDownCake"

Lyle answered 23/1, 2024 at 9:23 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.