Reputation: 3219
When Xamarin.Android is set to Android 12, I received
"You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without the 'android:exported' property set. This file can't be installed on Android 12 or higher. See: developer.android.com/about/versions/12/behavior-changes-12#exported"
error while uploading the APK to the Google Play Console for new release.
I have added the the Exported attribute to my activities and services, yet still setting this error.
[Activity(Label = "@string/AppDrawerName", Icon = "@mipmap/ic_launcher", RoundIcon = "@mipmap/ic_launcher_round", Theme = "@style/MainTheme", MainLauncher = true, Exported = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
Service
[Service(Exported = true)]
public class BarcodeService : IBarcodeService
{
From the compile output I can see the message below
Namespace 'com.google.android.gms.stats' used in: AndroidManifest.xml, AndroidManifest.xml.
android:exported needs to be explicitly specified for element <service#crc640921eac73192168e.PNMessagingService>. Apps targeting Android 12 and higher are required to specify an explicit value for
android:exported
when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
Then I go into the "obj/Debug" folder to open the Manifest, I can see the below service is auto generated
<service android:name="crc640921eac73192168e.PNMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
Anybody know how can I set [Service(Exported = true)]
for this service since it's auto generated?
Upvotes: 5
Views: 7506
Reputation: 89
A friend advised me not to use API 31 as it had known issues. I first had to upgrade my Visual Studio then installed API 33. After that I cleaned and rebuilt the Xamarin [Android] project. When I tried to Archive it, the process failed and it gave an error this time around. Apparently, there is another generated AndroidManifest.xml file. This time I got the error and realised it was coming from a service I had created in the [ProjectName].Droid.Services. All I had to do was to add Exported = true
as follows:
using Firebase.Messaging;
using System;
using System.Collections.Generic;
namespace MyApp.Droid.Services
{
[Service(Exported = true)]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class AppFirebaseMessagingService : FirebaseMessagingService
{
// code here
}
}
I then clean, rebuilt, and archived successfully. The upload to Google Play Store was also successful.
Upvotes: 0
Reputation: 11
problem solution
1 - copy the generated androidManifest in the obj/debug/android/AndroidManifest.xml folder, copy and paste it in the application's main androidManifest
2- include android:exported="true" in:
activity receiver service
This solution solved the problem for me.
Upvotes: 1
Reputation: 1403
I decorated my FirebaseIIDService.cs file in my Android project with
[Service(Exported = true)]
which did the trick. If you cannot find this file in your project, just search for com.google.firebase.MESSAGING_EVENT
[Service(Exported = true)]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class FirebaseIIDService : FirebaseMessagingService
{
public override void OnNewToken(string token) {
System.Threading.Tasks.Task.Run(async () => {
//
// this call will only work once we have valid configuration data populated
// upon first install, false will be returned
await Umbraco.UpdateFirebaseToken(token);
});
}
}
Upvotes: 9
Reputation: 3219
After got the info from the "obj/Debug" AndroidManifest.xml of the below
I added it into my project's Manifest manually under the tag, finally it's working. Please see below for the Manifest in project.
<application android:label="XXXXX">
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/notification_icon" />
<meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/super_red" />
<service android:name="crc640921eac73192168e.PNMessagingService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
It's good to check the Manifest on the obj/ folder to ensure all has exported set in the parent.
Upvotes: 11
Reputation: 171
A Detailed output MSBuild project output verbosity did the trick.
When I turned on this feature I discovered a NotificationPushService and a TokenService element needed to add a android:exported="true" tag.
Upvotes: -1