admob-plus / admob-plus

Trustable AdMob Plugin for Cordova, Capacitor, Ionic, React Native
https://admob-plus.github.io
MIT License
361 stars 150 forks source link

Didn't find class "admob.plus.cordova.AdMob"@version 2 #615

Open danieldanielecki opened 8 months ago

danieldanielecki commented 8 months ago

The version 2 doesn't work on Android device/simulator. Didn't try iOS, yet, and I'm gonna to keep on 1.28.0.

While being on the latest version (that time 2.0.0-alpha.8) I've noticed several errors while trying to launch the AdMob ads:

W/System.err: java.lang.ClassNotFoundException: admob.plus.cordova.AdMob

Caused by: java.lang.ClassNotFoundException: Didn't find class "admob.plus.cordova.AdMob" on path: DexPathList[[zip file "/data/app/~~zyU1wTzxUpuk86KhTdLJMA==/com.doyban.tappyplane-bUbLCwmlqbk6iIzUjeslaQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~zyU1wTzxUpuk86KhTdLJMA==/com.doyban.tappyplane-bUbLCwmlqbk6iIzUjeslaQ==/lib/arm64, /system/lib64, /system_ext/lib64]] W/System.err: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:379) W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

java.lang.ClassNotFoundException: admob.plus.cordova.AdMob

Error adding plugin admob.plus.cordova.AdMob. W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CordovaPlugin.privateInitialize(java.lang.String, org.apache.cordova.CordovaInterface, org.apache.cordova.CordovaWebView, org.apache.cordova.CordovaPreferences)' on a null object reference W/System.err:

I had to revert back to 1.28.0 in https://github.com/Doyban/TappyPlane/commit/cab533f5e1db34a519c242ab2243ebae675ca578 to get AdMob working.

I'm aware it's just alpha, but from the docs I understood it's working, but that's not the case.

bonjourjoel commented 8 months ago

Hi, I have read your message and found it useful for another reason. So thanks 🥇 But since i'm already here, i can give you a hint maybe: i am testing the version 2.0.0-alpha.13 and i could show an interstitial on my android device. And i don't have any compiling error on cordova/android. So maybe you can try 2.0.0-alpha.13, or maybe uninstall/re-install cordova + plugin + platform andoid? I have cordova 12.0.0 (cordova-lib@12.0.1) + platform cordova-android 12.0.1 + admob-plus-cordova 2.0.0-alpha.13. Maybe give it a try. Cheers.

danieldanielecki commented 8 months ago

Thanks @bonjourjoel, I haven't seen anything to fix the problem in release notes, so just decided to leave the working solution; with Cordova plugins it's always the moment everyone is waiting for - to get it working:)

jellomaster commented 7 months ago

Daniel. The 2.0 alpha plugin was written in Kotlin so you'll need to enable Kotlin in your project. Adding the following line to config.xml should do the trick: <preference name="GradlePluginKotlinEnabled" value="true" />

The installation docs just need updating.

1n3JgKl9pQ6cUMrW commented 7 months ago

Daniel. The 2.0 alpha plugin was written in Kotlin so you'll need to enable Kotlin in your project. Adding the following line to config.xml should do the trick:

The installation docs just need updating.

Line not visible 😀

jellomaster commented 7 months ago

Apologies... didn't mark the line as code. Now it should appear just fine. Add that line in your config.xml under the AndroidXEnabled line and you'll get rid of the Didn't find class "admob.plus.cordova.AdMob" errors.

cauboy commented 4 months ago

Note: After submitting the comment, I managed to resolve the issue on my own. I have updated my comment to reflect the solution.


Adding that line helped. But I have an incompatibility issue with cordova-plugin-firebasex I assume. As adding

<preference name="GradlePluginKotlinEnabled" value="true" />

results in a build error:

> Task :app:compileDebugKotlin
e: /Users/john-doe/.gradle/caches/transforms-3/1ee3f7841abe9979797edc39b62bd26a/transformed/jetified-firebase-auth-22.2.0-api.jar!/META-INF/java.com.google.android.gmscore.integ.client.firebase-auth-api_firebase-auth-api.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
e: /Users/john-doe/.gradle/caches/transforms-3/dade25bead44bca314189166709326d8/transformed/jetified-play-services-measurement-api-21.5.0-api.jar!/META-INF/java.com.google.android.gmscore.integ.client.measurement_api_measurement_api.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.

> Task :app:compileDebugKotlin FAILED

When I specify the Gradle version to 1.9.0 as follows:

<preference name="GradlePluginKotlinEnabled" value="true" />
<preference name="GradlePluginKotlinVersion" value="1.9.0" />

The build now fails with

> Task :app:compileDebugKotlin
e: The Android extensions ('kotlin-android-extensions') compiler plugin is no longer supported. Please use kotlin parcelize and view binding. More information: https://goo.gle/kotlin-android-extensions-deprecation

> Task :app:compileDebugKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

I could fix this by commenting out the 'kotlin-android-extensions line in android/app/build.gradle:

if (cordovaConfig.IS_GRADLE_PLUGIN_KOTLIN_ENABLED) {
  apply plugin: 'kotlin-android'
  // apply plugin: 'kotlin-android-extensions'
}

After doing so, everything worked for me.