androidxamarin.androidintentfilterandroid-12targetsdkversion

Targeting S+ (version 31 and above) error still after adding android:exported=false


I upgraded the project to targetSDKVersion="31" and installed that version in VS.

I get the following error when trying to run project with a phone with Android 12:

Error       ADB0010: Mono.AndroidTools.InstallFailedException: Unexpected install output: Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl803710359.tmp/base.apk (at Binary XML file line #93): crc6496621e99a539ca61.SomeAppLaunchActivity: 

Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]

I also tried the instructions from: https://developer.android.com/google/play/requirements/target-sdk One of the main things it mentions is adding to the manifest file the android:exported="false" which I did, as seen below:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.arc.ourproject.something" android:versionName="126.01.0" android:installLocation="auto" android:versionCode="107">
    <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="31" />       
    <uses-permissions here....>
    <uses-feature android:name="android.hardware.camera" android:required="true" />
    <application android:label="Project" android:debuggable="false" android:theme="@style/OURTheme" android:icon="@drawable/our_icon_180px" android:requestLegacyExternalStorage="true" android:exported="false">
        <provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}" android:exported="false" android:grantUriPermissions="true">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
        </provider>
    </application>
</manifest>

AppLaunchActivity.cs has:

[IntentFilter(new[] { Intent.ActionView }, AutoVerify = true, Categories = new[]
    {
        Intent.CategoryDefault,
        Intent.CategoryBrowsable
    }

Solution

  • At first, all the activities, services and broadcast receivers which has the intent filter in the app which target version is Api 31 need to declare the android: exported=. You can declare it in the Attribute, such as [Activity(Exported = false)] or in the AndroidManifest.xml, such as:

    <activity android:enabled="true" android:name=".ActivityName" android:exported="false">
        <intent-filter>
            <action android:name="...."/>
        </intent-filter>
    </activity>
    

    According to the error message, there is an activity named SomeAppLaunchActivity in your app need to declare the android:exported. If it is created by yourself, you declare it use the method above.

    Or it may be created by the nuget package in your app, if so, you have to check the version of the package and update to the version which support the android Api 31.

    Update

    Please declare the AppLaunchActivity's exported such as:

     [Activity(Exported=true)]
     [IntentFilter(new[] { Intent.ActionView }, AutoVerify = true, Categories = new[]
    {
        Intent.CategoryDefault,
        Intent.CategoryBrowsable
    }
     public class AppLaunchActivity : Activity{}