Admob crash app on device

Hello,

I have an app with Admob plugin and working fine on device when builded with Corona 2018.3326, but when I try to build with 2019.3540 and run on device it crashes immediately.

From adb logcat the problem seems Admob:

/dalvikvm( 4962): Could not find method android.content.pm.PackageManager.isInstantApp, referenced from method com.google.android.gms.common.wrappers.PackageManagerWrapper.isCallerInstantApp W/dalvikvm( 4962): VFY: unable to resolve virtual method 979: Landroid/content/pm/PackageManager;.isInstantApp (Ljava/lang/String;)Z D/dalvikvm( 4962): VFY: replacing opcode 0x6e at 0x002d D/AndroidRuntime( 4962): Shutting down VM W/dalvikvm( 4962): threadid=1: thread exiting with uncaught exception (group=0x416bebc0) E/AndroidRuntime( 4962): FATAL EXCEPTION: main E/AndroidRuntime( 4962): Process: com.sanga.admobapp, PID: 4962 E/AndroidRuntime( 4962): java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException: E/AndroidRuntime( 4962): E/AndroidRuntime( 4962): \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* E/AndroidRuntime( 4962): \* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers \* E/AndroidRuntime( 4962): \* should follow the instructions here: https://goo.gl/fQ2neu to add a valid \* E/AndroidRuntime( 4962): \* App ID inside the AndroidManifest. Google Ad Manager publishers should \* E/AndroidRuntime( 4962): \* follow instructions here: https://goo.gl/h17b6x. \* E/AndroidRuntime( 4962): \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* E/AndroidRuntime( 4962): E/AndroidRuntime( 4962): E/AndroidRuntime( 4962): at android.app.ActivityThread.installProvider(ActivityThread.java:5196) E/AndroidRuntime( 4962): at android.app.ActivityThread.installContentProviders(ActivityThread.java:4788) E/AndroidRuntime( 4962): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4728) E/AndroidRuntime( 4962): at android.app.ActivityThread.access$1500(ActivityThread.java:166) E/AndroidRuntime( 4962): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1343) E/AndroidRuntime( 4962): at android.os.Handler.dispatchMessage(Handler.java:102) E/AndroidRuntime( 4962): at android.os.Looper.loop(Looper.java:136) E/AndroidRuntime( 4962): at android.app.ActivityThread.main(ActivityThread.java:5584) E/AndroidRuntime( 4962): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 4962): at java.lang.reflect.Method.invoke(Method.java:515) E/AndroidRuntime( 4962): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) E/AndroidRuntime( 4962): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) E/AndroidRuntime( 4962): at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 4962): Caused by: java.lang.IllegalStateException: E/AndroidRuntime( 4962): E/AndroidRuntime( 4962): \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* E/AndroidRuntime( 4962): \* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers \* E/AndroidRuntime( 4962): \* should follow the instructions here: https://goo.gl/fQ2neu to add a valid \* E/AndroidRuntime( 4962): \* App ID inside the AndroidManifest. Google Ad Manager publishers should \* E/AndroidRuntime( 4962): \* follow instructions here: https://goo.gl/h17b6x. \* E/AndroidRuntime( 4962): \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* E/AndroidRuntime( 4962): E/AndroidRuntime( 4962): E/AndroidRuntime( 4962): at com.google.android.gms.internal.ads.zzabh.attachInfo(Unknown Source) E/AndroidRuntime( 4962): at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(Unknown Source) E/AndroidRuntime( 4962): at android.app.ActivityThread.installProvider(ActivityThread.java:5193) E/AndroidRuntime( 4962): ... 12 more

I already added the Admob app_id into build.settings

settings = { android = { applicationChildElements = { [[\<meta-data android:name="com.google.android.gms.ads.APPLICATION\_ID" android:value="ca-app-pub-XXXXXXXXXXXXXXXX~YYYYYYYYYY"/\>]], } }, plugins = { ["plugin.admob"] = { publisherId = "com.coronalabs" }, } }

I think could not be the Admob init code because it’s not into main.lua, and the app crash before Corona splash screen.

main.lua load settings -> show custom splash.lua -> show game.lua where Admob init code called. 

local function adListener( event ) -- Successful initialization of AdMob if ( event.phase == "init" ) then native.setActivityIndicator( true ) admob.load( "banner", { adUnitId=\_G.bannerID} ) admob.load( "interstitial", { adUnitId=\_G.interstitialID} ) admob.load( "rewardedVideo", { adUnitId=\_G.rewardedVideoID} ) elseif ( event.phase == "loaded" ) then if admob.isLoaded( "banner" ) and admob.isLoaded( "interstitial" ) then native.setActivityIndicator( false ) end if tostring(event.type) == "banner" then admob.show( "banner" ) end elseif ( event.phase == "closed" ) then if tostring(event.type) == "interstitial" then native.setActivityIndicator( true ) admob.load( "interstitial", { adUnitId=\_G.interstitialID} ) elseif tostring(event.type) == "rewardedVideo" then --native.setActivityIndicator( true ) admob.load( "rewardedVideo", { adUnitId=\_G.rewardedVideoID} ) end elseif ( event.phase == "displayed" ) then if tostring(event.type) == "rewardedVideo" then native.setActivityIndicator( false ) end elseif ( event.phase == "reward" ) then --reward -- The ad failed to load elseif ( event.phase == "failed" ) then native.setActivityIndicator( false ) end end admob.init( adListener, { appId=\_G.appID, testMode=false } )

Thanks to anyone who has suggestions for understanding the problem.

Federico

Is this:

"ca-app-pub-XXXXXXXXXXXXXXXX~YYYYYYYYYY"

the actual string or did you change the values for this post to protect them?

XXX and YYY are dummy values, the string provided is the real app_id.

I’ve forwarded this to Engineering to see if Admob is doing anything when it’s required. The error message seems to be quite clear that you don’t have the AdMob app id in build.settings correctly.  Is that your entire build.settings?

Rob

It can be tricky to get this right. Try some demo ID, like “ca-app-pub-3940256099942544~3347511713”, also, it may be tied to bundle ID.

Tried the demo id but the problem persists.

How can I check if the id is included correctly into AndroidManifest.xml?

There are quite a bit of methods, most described here: https://stackoverflow.com/questions/4191762/how-to-view-androidmanifest-xml-from-apk-file

My favorite is to open your APK with Android Studio (you can drag & drop APK on Android Studio and them select manifest, and it will show XML values in manifest).

If you don’t want to download whole Android Studio, command line would do. Depends if you’re on mac or on windows. On macOS run this command:

~/"Library/Application Support/Corona/Android Build/sdk/build-tools/28.0.3/aapt2" dump --file AndroidManifest.xml&nbsp; ~/Projects/Builds/Appodeal.apk

Obviously, you’ll have different path to APK. This will dump it in weird format, but you still looking for something like

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A: http://schemas.android.com/apk/res/android:name(0x01010003)="com.google.android.gms.ads.APPLICATION\_ID" (Raw: "com.google.android.gms.ads.APPLICATION\_ID") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A: http://schemas.android.com/apk/res/android:value(0x01010024)="ca-app-pub-3940256099942544~3347511713" (Raw: "ca-app-pub-3940256099942544~3347511713")

On Windows, I don’t remember location of Android Build directory, but it’s somewhere in %APPDATA%

Finally found the solution!

The problem was my build.settings of course, i have 2 “android” sections like this

android = { applicationChildElements = { [[\<meta-data android:name="com.google.android.gms.ads.APPLICATION\_ID" android:value="ca-app-pub-2229071158628999~5052244537"/\>]], } }, android = { versionCode = "6", largeHeap = true, usesPermissions = { "android.permission.INTERNET", "android.permission.ACCESS\_NETWORK\_STATE", }, },

and the app id not included into AndroidManifest.xml

Put all settings into a single “android” section and everything works fine!

Thanks Rob and Vlads for the help.