MTAdmob icon indicating copy to clipboard operation
MTAdmob copied to clipboard

App crashes when targetSdk is 31

Open prok155 opened this issue 2 years ago • 10 comments

Describe the bug App crashes when I set targetSdk to 31 and target framework Android 12. Bug occurs only when I try to run my project on phones and emulators with android 12. Error log: 'com.companyname.mypackagename: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.'

To Reproduce Steps to reproduce the behavior:

  1. Install visual studio 2022
  2. Create new Xamarin project
  3. Install MTAdmob nuget package
  4. Run project on emulator or a phone with Android 12 installed
  5. The app will crash and you will see above error log.

Expected behavior App doesn't crash on devices with Android 12

Smartphone (please complete the following information):

  • google pixel 4 xl
  • android 12

Additional context Here are changes to pending intents when app is targeting Android12. https://developer.android.com/about/versions/12/behavior-changes-12#pending-intent-mutability

prok155 avatar Jan 21 '22 13:01 prok155

I was looking at his page: https://groups.google.com/g/google-admob-ads-sdk/c/fmbPnkUCIe8?pli=1 and in particular at this (for native android):

dependencies { implementation 'com.google.android.gms:play-services-ads:20.4.0'

// For apps targeting Android 12, add WorkManager dependency. 
constraints { 
    implementation('androidx.work:work-runtime:2.7.0') { because '''androidx.work:work-runtime:2.1.0 pulled from play-services-ads has a bug ...'' } 
}

}

It seems that this is a well known problem and the solution they found was to use androidx.work:work-runtime:2.7.0. I've tried to install the version available for android but that doesn't solve the problem.

marcojak avatar Jan 21 '22 20:01 marcojak

Following, currently experiencing the same problem when using on API 31

jl-mobitech avatar Apr 05 '22 14:04 jl-mobitech

Following, experiencing same issue on my app as will on android 12 device

kelvin526 avatar Apr 05 '22 14:04 kelvin526

@prok155 @marcojak @kelvin526 , I managed to fix this while running on Android 12. You just need to install these two packages on your Android project: image

Can you please verify on your side? Thanks

Update: Xamarin.AndroidX.Work.Runtime 2.7.1.3 won't work. It needs to be only on 2.7.0. I don't know why the latest version won't work.

jl-mobitech avatar Apr 06 '22 09:04 jl-mobitech

I've installed only Xamarin.AndroidX.Work.Runtime 2.7.0 and it solved issue. @jl-memosoft thank you for solution!

prok155 avatar Apr 06 '22 12:04 prok155

@jl-memosoft I can't install those package as my app dev in xamarin form which have compatibility issue. Anyone else have workaround? TIA

-Update on 9/4/2022- Found a way to install the Xamarin.AndroidX.Work.Runtime 2.7.0 and now it solved the issue. Thanks!!!

kelvin526 avatar Apr 07 '22 12:04 kelvin526

I've installed only Xamarin.AndroidX.Work.Runtime 2.7.0 and it solved issue. @jl-memosoft thank you for solution!

Same here! I was trying to install the latest one (2.7.1.4) and it wasn't installing due to incompatible versions. Your and jl-memesoft advice saved me, thanks!

davidblaine228 avatar Jun 15 '22 00:06 davidblaine228

@jl-memosoft, @davidblaine228 Is it still required with v1.8.0 update ?

gsgou avatar Jul 06 '22 16:07 gsgou

@jl-memosoft, @davidblaine228 Is it still required with v1.8.0 update ?

Unfortunately, can't really tell

davidblaine228 avatar Jul 19 '22 23:07 davidblaine228

@jl-memosoft, @davidblaine228 Is it still required with v1.8.0 update ?

For me, it is required

BlyZeYT avatar Aug 18 '22 11:08 BlyZeYT