5

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?

5
  • Tried setting it to false? Jan 27, 2022 at 10:11
  • No help still cannot. I have nuget added, I wonder if those nuget would add any activity or service which is not set?
    – TPG
    Jan 27, 2022 at 10:50
  • 3
    Look at the resulting AndroidManifest in the obj/Debug/Android folder and see what is actually being exported Jan 27, 2022 at 10:52
  • looking at the output manifest file in obj/Debug/Android i find the service with "intent-filter" but that not have "android:exported" set
    – Ricko..
    Jan 28, 2022 at 17:03
  • When you find the activity or service from the Manifest inside the obj/Debug/Android, you should copy and paste it into your original Manifest and simply add the "android:exported = false" attribute. Nov 23, 2022 at 14:29

5 Answers 5

11

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.

1
  • You are my HERO! Welcome to Ukraine! Sep 19, 2022 at 14:43
9

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);
        });
    }
}
3
  • 2
    This should be considered as the right solution because adding the android exported in a generated AndroidManifest.xml does not make sense if the file will be auto-generated again. Thanks for your solution!
    – B0r1
    Jan 20, 2023 at 13:37
  • 1
    @B0r1 this is in the .cs file, not the manifest, therefore, no, it would not be re-generated.
    – Napoli
    Nov 28, 2023 at 14:21
  • already fixed that but thanks for mentioning! xD
    – B0r1
    Dec 4, 2023 at 18:55
1

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.

1
  • This was helpful, thank you. FWIW, I only copied the specific stanzas that needed to be annotated with android:exported="true".
    – hcd00045
    Apr 3, 2023 at 20:15
0

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.

-1

A Detailed output MSBuild project output verbosity did the trick.

enter image description here

When I turned on this feature I discovered a NotificationPushService and a TokenService element needed to add a android:exported="true" tag.

1
  • This is not the solution for the problem we are having. Nov 19, 2023 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.