Home > database >  xamarin uploading app to play store with android 12 set eported=true issue
xamarin uploading app to play store with android 12 set eported=true issue

Time:11-25

I am developing using Xamarin Forms and updated api to 31 and target framework to v12, uploading to the play store I am facing the error "You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without '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". But when I set android:exported=false or true in activity attribute above my activity then I am unable to get even local build with attribute duplication error. I am stuck on this issue and I am getting no idea what to do please guide.

I am developing using Xamarin Forms and updated api to 31 and target framework to v12, uploading to the play store I am facing the error "You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without '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". But when I set android:exported=false or true in activity attribute above my activity then I am unable to get even local build with the error "

Severity    Code    Description Project File    Line    Suppression State
Error       System.InvalidOperationException: Duplicate attribute.
   at System.Xml.Linq.XElement.AddAttributeSkipNotify(XAttribute a)
   at System.Xml.Linq.XContainer.AddContentSkipNotify(Object content)
   at System.Xml.Linq.XContainer.Add(Object content)
   at Xamarin.Android.Tasks.ManifestDocument.AddLauncherIntentElements(XElement activity)
   at Xamarin.Android.Tasks.ManifestDocument.<>c__DisplayClass99_0.<ActivityFromTypeDefinition>b__1(ActivityAttribute aa, XElement element)
   at Xamarin.Android.Tasks.ManifestDocument.ToElement[TAttribute](TypeDefinition type, String name, Func`2 parser, Func`2 toElement, Action`2 update)
   at Xamarin.Android.Tasks.ManifestDocument.ActivityFromTypeDefinition(TypeDefinition type, String name, Int32 targetSdkVersion)
   at Xamarin.Android.Tasks.ManifestDocument.Merge(TaskLoggingHelper log, TypeDefinitionCache cache, List`1 subclasses, String applicationClass, Boolean embed, String bundledWearApplicationName, IEnumerable`1 mergedManifestDocuments)
   at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res)
   at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
   at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/builder/azdo/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17  Infinity.Android"           

. I am stuck on this issue and I am getting no idea what to do please guide.

CodePudding user response:

can you show your manifest.xml? Yesterday I had the same problem, here are some reference links. Xamarin.Android without the 'android:exported' property set error

Here are the changes that made it work for me, all within the android project in AndroidManifest.xml in the tags "provider, receiver, activity" you have to add

android:exported="false/true"

sample

In other services that you have in the android project you also have to add

[Service(Exported = true)] 
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })] 
public class MessagingService : FirebaseMessagingService 
{

}

--------------

[Service(Exported = true)] 
[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })] 
public class FireBaseIdInstance : FirebaseInstanceIdService 
{
} 

MainActivity.cs

Exported = true

[Activity(Label = "", Icon = "@mipmap/icon_new", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, Name = "com.audaztec.abscard.MainActivity", Exported = true)] 
[IntentFilter(new[] { "com.audaztec.ABSCard_OPEN_GIFT_PAGE", "com.audaztec.ABSCard_OPEN_CHAT_PAGE", "com.audaztec.ABSCard_OPEN_REQUEST_PAGE", "com.audaztec.ABSCard_DEFAULT", "android.intent.action.VIEW" }, Categories = new[] { "android.intent.category.DEFAULT", "android.intent.category.BROWSABLE" })] 
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity 
{
 
}

CodePudding user response:

and updated api to 31 and target framework to v12

After this, you can try to run your peoject on the Android 12 emulator or the physical device. And the visual studio logcat will show the error message to tell you which component does't declare the android:exported attribute and cause the issue.

There are two situations:

  1. One is the component created by yourself didn't declare it. You can declare it just like Kelvyn Sinhorini said.
  2. The other is the component is in the nuget packages you added in your project. You can update the nuget packages in your project to the last version to resolve it.
  • Related