Xamarin deploy manifest in android 12

Viewed 715

I developed an application using Xamarin.Forms 3.4 The application is working, but with the new version of Android 12 this application was automatically removed from the devices and when it has to be installed again from the PlayStore store, an error occurs.

I tried to deploy visual studio to a device with android 12 and the following error occurs:

ADB0010: Mono.AndroidTools.InstallFailedException: Unexpected install output: Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl1472364015.tmp/base.apk (at Binary XML file line #28)
: com.onesignal.GcmBroadcastReceiver: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]

   at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName) in D:\a\_work\1\s\External\androidtools\Mono.AndroidTools\Internal\AdbOutputParsing.cs:line 350
   at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass100_0.<InstallPackage>b__0(Task`1 t) in D:\a\_work\1\s\External\androidtools\Mono.AndroidTools\AndroidDevice.cs:line 803
   at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at AndroidDeviceExtensions.<PushAndInstallPackageAsync>d__12.MoveNext() in D:\a\_work\1\s\External\androidtools\Xamarin.AndroidTools\Devices\AndroidDeviceExtensions.cs:line 206
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at AndroidDeviceExtensions.<PushAndInstallPackageAsync>d__12.MoveNext() in D:\a\_work\1\s\External\androidtools\Xamarin.AndroidTools\Devices\AndroidDeviceExtensions.cs:line 223
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.Android.Tasks.FastDeploy.<InstallPackage>d__101.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 338
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Xamarin.Android.Tasks.FastDeploy.<InstallPackage>d__101.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 355
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Xamarin.Android.Tasks.FastDeploy.<RunTaskAsync>d__96.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 212            0   

Searching the internet I found this article: https://medium.com/androiddevelopers/lets-be-explicit-about-our-intent-filters-c5dbe2dbdce0

This article mention to add export in activity, receiver and ect. I added this attribute but the deploy continues with an error, if I use a device with an android version lower than 12 it works.

My activity is like this:

[Activity(
    Label = "My App",
    Icon = "@drawable/icon",
    Theme = "@style/Theme.Splash",
    MainLauncher = true,
    LaunchMode = LaunchMode.SingleTask,
    Exported = true,
    ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.Locale | ConfigChanges.LayoutDirection
    )
]

Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" package="com.my_app" android:versionCode="78" android:versionName="1.0.4">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
    <permission android:name="com.my_app.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
    <uses-permission android:name="android.permission.INSTANT_APP_FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application android:label="My App" android:largeHeap="@bool/largeheap" android:icon="@drawable/icon" android:requestLegacyExternalStorage="true">
        <provider android:name="android.support.v4.content.FileProvider" android:authorities="com.my_app.fileprovider" android:exported="false" android:grantUriPermissions="true">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
        </provider>
        <receiver android:name="com.onesignal.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.my_app" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.my_app.app.BootBroadcast" android:enabled="true" android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
    </application>
</manifest>

BroadcastReceiver:

[BroadcastReceiver(Name = "com.my_app.app.BootBroadcast", Enabled = true, Exported = false)]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
public class BootBroadcast : BroadcastReceiver

I honestly don't know what else to do

0 Answers
Related