marcojak / MTAdmob

Admob plugin for Xamarin Android and iOS
https://www.xamarinexpert.it/admob-made-easy/
160 stars 26 forks source link

App crashes when targetSdk is 31 #89

Open prok155 opened 2 years ago

prok155 commented 2 years ago

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):

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

marcojak commented 2 years ago

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.

jl-mobitech commented 2 years ago

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

kelvin526 commented 2 years ago

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

jl-mobitech commented 2 years ago

@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.

prok155 commented 2 years ago

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

kelvin526 commented 2 years ago

@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!!!

davidblaine228 commented 2 years ago

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!

gsgou commented 2 years ago

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

davidblaine228 commented 2 years ago

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

Unfortunately, can't really tell

BlyZeDev commented 2 years ago

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

For me, it is required