Open JesusJoseph opened 4 years ago
Same problem a few weeks ago.
I suppose the issue below is useful for you. https://github.com/rahadur/capacitor-admob/issues/35.
If your app will crash after the fix, check my issue. https://github.com/rahadur/capacitor-admob/issues/59
Good luck!
Same problem a few weeks ago.
I suppose the issue below is useful for you.
35.
If your app will crash after the fix, check my issue.
59
Good luck!
Hi awesomerainbows, thanks for your reply.
I tried as mentioned in issue #35 but I am getting a similar error as below. package androidx.coordinatorlayout.widget does not exists
STEPS I did now,
STEP 1 Change the import statement in AdMob.java as below from //import android.support.design.widget.CoordinatorLayout; to import androidx.coordinatorlayout.widget.CoordinatorLayout;
STEP 2 add below 2 lines in build.gradle
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0' implementation 'androidx.appcompat:appcompat:1.1.0'
But still getting compile-time error.
Any help will be appreciated.
Thanks,
I get the same exact thing ^
On Step2 did you add the lines on build.gradle for capacitor-admob, not app build.gradle ?
On Step2 did you add the lines on build.gradle for capacitor-admob, not app build.gradle ?
Thanks for your help. Sorry, I missed that, now I did step 2 correctly the app open successfully.
BUT the APP is CRASH when I try to open the banner. From the log, I can see the app crashed with null pointer exception from below line inside AdMob.java
mViewGroup.addView(mAdViewLayout);
Can you please help me to solve this issue. thanks for your help.
### FULL EXCEPTION
2020-06-18 12:52:34.716 542-542/io.ionic.starter E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.ionic.starter, PID: 542
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.addView(android.view.View)' on a null object reference
at app.xplatform.capacitor.plugins.AdMob$2.run(AdMob.java:208)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2020-06-18 12:52:34.808 542-542/io.ionic.starter I/Process: Sending signal. PID: 542 SIG: 9
Also, add below 2 lines in AndroidManifest.xml
I recently upgrade to AndroidX as well, and encounter a series of issues related to this. Let me summarise what I encountered and what I did to fix.
After migrate to AndroidX, I am getting error I am getting error as "package android.support.design.widget does not exists" in AdMob.java
. So what I did is
a. Change the import statement in AdMob.java as below from
import android.support.design.widget.CoordinatorLayout;
to
import androidx.coordinatorlayout.widget.CoordinatorLayout;
This AdMob.java file is located at node_modules/capacitor_admob, and therefore every time i reinstall node_modules, I will have to redo this step.
b. In the admob build.gradle (located at node_modules/capacitor_admob), I added
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
Step 1 actually fix the issue with this plugin, but because in my application, I do have other capacitor plugins and those are giving me the same error. So to do that, I search this entire application for android.support.design.widget.CoordinatorLayout;
and replace them with androidx.coordinatorlayout.widget.CoordinatorLayout;
One thing to take note is that these changes are in node_modules files, and therefore not committed to source control (for my case). Therefore, every time node_modules are reinstalled, I will need to re do all these manually.
On Step2 did you add the lines on build.gradle for capacitor-admob, not app build.gradle ?
Thanks for your help. Sorry, I missed that, now I did step 2 correctly the app open successfully.
BUT the APP is CRASH when I try to open the banner. From the log, I can see the app crashed with null pointer exception from below line inside AdMob.java
mViewGroup.addView(mAdViewLayout);
Can you please help me to solve this issue. thanks for your help.
### FULL EXCEPTION
2020-06-18 12:52:34.716 542-542/io.ionic.starter E/AndroidRuntime: FATAL EXCEPTION: main Process: io.ionic.starter, PID: 542 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.addView(android.view.View)' on a null object reference at app.xplatform.capacitor.plugins.AdMob$2.run(AdMob.java:208) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 2020-06-18 12:52:34.808 542-542/io.ionic.starter I/Process: Sending signal. PID: 542 SIG: 9
Also, add below 2 lines in AndroidManifest.xml
you are missing the AdMob.initialize("your-key") before the showBanner. i spend three hours in the same stupid thing. LOL
On Step2 did you add the lines on build.gradle for capacitor-admob, not app build.gradle ?
Thanks for your help. Sorry, I missed that, now I did step 2 correctly the app open successfully. BUT the APP is CRASH when I try to open the banner. From the log, I can see the app crashed with null pointer exception from below line inside AdMob.java
mViewGroup.addView(mAdViewLayout);
Can you please help me to solve this issue. thanks for your help. ### FULL EXCEPTION2020-06-18 12:52:34.716 542-542/io.ionic.starter E/AndroidRuntime: FATAL EXCEPTION: main Process: io.ionic.starter, PID: 542 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.addView(android.view.View)' on a null object reference at app.xplatform.capacitor.plugins.AdMob$2.run(AdMob.java:208) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 2020-06-18 12:52:34.808 542-542/io.ionic.starter I/Process: Sending signal. PID: 542 SIG: 9
Also, add below 2 lines in AndroidManifest.xml
you are missing the AdMob.initialize("your-key") before the showBanner. i spend three hours in the same stupid thing. LOL
I have the same issue. I added the AdMob.initialize("your-key"), but still there.
There's a npm to help update plugins to android X https://github.com/mikehardy/jetifier
npm install jetifier
npx jetify
npx cap sync android
I try to setup Admob for android but I am getting error as "package android.support.design.widget does not exists" in AdMob.java Working perfectly with ios but having this issue for last 2 days but couldn't fix it. Any guidance will be appreciated. Thanks
Followed the below steps to get this error.
create new ionic 5 project
npx cap add android
Install capacitor-admob plugin using below command npm install --save capacitor-admob
ionic build
npx cap copy 6.npx cap open android -> this opens the project in Android Studio.
Build the project and getting error as below
../node_modules/capacitor-admob/android/src/main/java/app/xplatform/capacitor/plugins/AdMob.java package android.support.design.widget does not exist package CoordinatorLayout does not exist package CoordinatorLayout does not exist package CoordinatorLayout does not exist package CoordinatorLayout does not exist
### build.gridle content
apply plugin: 'com.android.application'
android { compileSdkVersion rootProject.ext.compileSdkVersion defaultConfig { applicationId "io.ionic.starter" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
repositories { flatDir{ dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs' } }
dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion" implementation project(':capacitor-android') testImplementation "junit:junit:$junitVersion" androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion" androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion" implementation project(':capacitor-cordova-android-plugins') }
apply from: 'capacitor.build.gradle'
try { def servicesJSON = file('google-services.json') if (servicesJSON.text) { apply plugin: 'com.google.gms.google-services' } } catch(Exception e) { logger.warn("google-services.json not found, google-services plugin not applied. Push Notifications won't work") }