Home > Mobile >  Application does't buil whit Android 12 (Firebase.Messaging)
Application does't buil whit Android 12 (Firebase.Messaging)

Time:03-29

I have an Application that use Xamarin.FireBase.Messaging, and it works on all <12 android version.

When I try to buil my App in Android 12 it apears this error:

"*Severity Code Description Project File Line Suppression State Error ADB0010: Mono.AndroidTools.InstallFailedException: Unexpected install output: Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl254956208.tmp/base.apk (at Binary XML file line #40): crc64bb777672d9471d38.CustomFirebaseMessagingService: 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 /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/external/androidtools/Mono.AndroidTools/Internal/AdbOutputParsing.cs:line 357 at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at AndroidDeviceExtensions.d__12.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/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.d__12.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/external/androidtools/Xamarin.AndroidTools/Devices/AndroidDeviceExtensions.cs:line 223 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Xamarin.Android.Tasks.FastDeploy.d__105.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 339 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Xamarin.Android.Tasks.FastDeploy.d__105.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 356 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Xamarin.Android.Tasks.FastDeploy.d__100.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 213 0 *"

I think that I add all the Attributes "android:exported".

This is my manifest:

manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.pushnotifications" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />


<application android:label="PushNotifications.Android" android:theme="@style/MainTheme">
    
    
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" 
              android:exported="false" />
    
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" 
              android:exported="true"
              android:permission="com.google.android.c2dm.permission.SEND">
        
        
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
            <category android:name="${applicationId}" />
        </intent-filter>
        
        
    </receiver>

</application>

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

And this is CustomFirebaseMessagingService class:

[Service(Exported = false)]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class CustomFirebaseMessagingService : FirebaseMessagingService
{
    public readonly ILocalNotificationsService localNotificationsService;

    public CustomFirebaseMessagingService()
    {
        localNotificationsService = new LocalNotificationService();
    }

    public override void OnNewToken(string token)
    {
        base.OnNewToken(token);
        Log.Debug("FMC_SERVICE", token);
    }

    public override void OnMessageReceived(RemoteMessage message)
    {
        var notification = message.GetNotification();
        localNotificationsService.ShowNotification(notification.Title, notification.Body, message.Data);
    }

}

What can I do?

CodePudding user response:

I had created a simple to test your code. When I deleted the (Exported = false), I will meet the same error as yours. But if I used the [Service(Exported = false)], the project worked well.

So the problem shouldn't appear. But you can try to declare the service in the manifest.xml. Such as:

<service android:enabled="true" android:name=".CustomFirebaseMessagingService" android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>
  • Related