GeofencePlugin icon indicating copy to clipboard operation
GeofencePlugin copied to clipboard

Android 12 intent filter exported requirement

Open dinonovak opened this issue 2 years ago • 7 comments

in multiplatform app iOS app works ok, starts, triggers events for android when trying to run app I am getting Error AMM0000: android:exported needs to be explicitly specified for element <receiver#crc64c554f6b6abc76285.GeofenceBootReceiver>. 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.

I tried fixing this issue by adding below to AndroidManifest.xml under application section

            <receiver
            android:name="crc64c554f6b6abc76285.GeofenceBootReceiver"
            android:enabled="true"
            android:exported="true" /> 

After that app starts OK, but is crashing when trying to start monitoring CrossGeofence.Current.StartMonitoring(geoSetup);

error is: Object reference not set to an instance of an object. in Plugin.Geofence

at Plugin.Geofence.GeofenceImplementation.RequestMonitoringStart () [0x00000] in <70d71c13fc584d2a938433caf7e25ac4>:0 
  at Plugin.Geofence.GeofenceImplementation.StartMonitoring (Plugin.Geofence.GeofenceCircularRegion region) [0x00061] in <70d71c13fc584d2a938433caf7e25ac4>:0 
  at geofencetest2.MainPage.OnButtonClicked (System.Object sender, System.EventArgs args) [0x0006f] in /geofencetest2/geofencetest2/geofencetest2/MainPage.xaml.cs:34 
  at Xamarin.Forms.Button.Xamarin.Forms.Internals.IButtonElement.PropagateUpClicked () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Button.cs:187 
  at Xamarin.Forms.ButtonElement.ElementClicked (Xamarin.Forms.VisualElement visualElement, Xamarin.Forms.Internals.IButtonElement ButtonElementManager) [0x0001f] in D:\a\1\s\Xamarin.Forms.Core\ButtonElement.cs:61 
  at Xamarin.Forms.Button.SendClicked () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Button.cs:173 
  at Xamarin.Forms.Platform.Android.ButtonElementManager.OnClick (Xamarin.Forms.VisualElement element, Xamarin.Forms.IButtonController buttonController, Android.Views.View v) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\ButtonElementManager.cs:25 
  at Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer.Android.Views.View.IOnClickListener.OnClick (Android.Views.View v) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\FastRenderers\ButtonRenderer.cs:72 
  at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x00010] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-30/mcw/Android.Views.View.cs:2260 
  at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V (_JniMarshal_PPL_V callback, System.IntPtr jnienv, System.IntPtr klazz, System.IntPtr p0) [0x00005] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:121 
  at (wrapper native-to-managed) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(intptr,intptr,intptr)

tried changing android:exported="true" to false, but same error.

dinonovak avatar Oct 07 '22 14:10 dinonovak

hi, were you able to get a resolve to this? From the code here there was a fix added, but I get the same error as you do above

Maniacy2k avatar Nov 30 '22 15:11 Maniacy2k

Are there any plans to update the nuget package once this fix is working properly? After 1/1/2023 Android 12 is required, and I will not be able to update my app. I will need to look for another geofence solution.

alanhoman avatar Dec 18 '22 17:12 alanhoman

Are there any plans to update the nuget package once this fix is working properly? After 1/1/2023 Android 12 is required, and I will not be able to update my app. I will need to look for another geofence solution.

I would like the answer to this question as well. This is the most up-to-date geofence package on NuGet, that I could find, and it hasn't been updated since 2021.

TheWatchfulOne avatar Sep 18 '23 02:09 TheWatchfulOne

I was able to update my app to android 12. Hopefully this will resolve the above error/ at least point in the right direction

Edit - 26/09/23:

You need to set your own AndroidManifext.xml in Droid project -> Properties as defined here.

In the AndroidManifext.xml amend/ add the following:

<manifest.... >
   <uses-sdk android:targetSdkVersion="31" />
   <!-- uses permission such as grant grant location permissions -->
   <uses-permission .... />
   <application android:label="App  name" android:icon="@drawable/icon">      
      <!-- might not be need but added just in case
      <meta-data android:name="com.google.android.geo.API_KEY" android:value="{key}" />
      <uses-library android:name="org.apache.http.legacy" android:required="false" /> -->
      <receiver android:enabled="true" android:exported="false" android:name="crc64c554f6b6abc76285.GeofenceBootReceiver"></receiver>
   </application>
</manifest.... >

Maniacy2k avatar Sep 18 '23 11:09 Maniacy2k

I was able to update my app to android 12. Hopefully this will resolve the above error/ at least point in the right direction

In the AndroidManifext.xml amend/ add the following:

<manifest.... >
   <uses-sdk android:targetSdkVersion="31" />
   <!-- uses permission such as grant grant location permissions -->
   <uses-permission .... />
   <application android:label="App  name" android:icon="@drawable/icon">      
      <!-- might not be need but added just in case
      <meta-data android:name="com.google.android.geo.API_KEY" android:value="{key}" />
      <uses-library android:name="org.apache.http.legacy" android:required="false" /> -->
      <receiver android:enabled="true" android:exported="false" android:name="crc64c554f6b6abc76285.GeofenceBootReceiver"></receiver>
   </application>
</manifest.... >

Thanks for the suggestion, but that is not a fix. The AndroidManifest.xml is automatically generated. Therefore, any changes you make manually will be lost. CrossGeeks needs to update their NuGet package.

TheWatchfulOne avatar Sep 18 '23 16:09 TheWatchfulOne

I was able to update my app to android 12. Hopefully this will resolve the above error/ at least point in the right direction In the AndroidManifext.xml amend/ add the following:

<manifest.... >
   <uses-sdk android:targetSdkVersion="31" />
   <!-- uses permission such as grant grant location permissions -->
   <uses-permission .... />
   <application android:label="App  name" android:icon="@drawable/icon">      
      <!-- might not be need but added just in case
      <meta-data android:name="com.google.android.geo.API_KEY" android:value="{key}" />
      <uses-library android:name="org.apache.http.legacy" android:required="false" /> -->
      <receiver android:enabled="true" android:exported="false" android:name="crc64c554f6b6abc76285.GeofenceBootReceiver"></receiver>
   </application>
</manifest.... >

Thanks for the suggestion, but that is not a fix. The AndroidManifest.xml is automatically generated. Therefore, any changes you make manually will be lost. CrossGeeks needs to update their NuGet package.

Sorry @TheWatchfulOne missed the bit about the one you would create as defined here

edited my comment

The AndroidManifest is automatically generated but merges in the AndroidManifest.xml you set in the Droid project -> Properties.

Maniacy2k avatar Sep 26 '23 13:09 Maniacy2k

@Maniacy2k I have now converted my project to Maui, so the editable AndroidManifest.xml is now located in the Platforms/Android folder. Your suggestion appears to have helped, thanks!

TheWatchfulOne avatar Nov 20 '23 07:11 TheWatchfulOne