capacitor-admob
capacitor-admob copied to clipboard
import android.support.design.widget.CoordinatorLayout;
Having difficulties getting my project to build on Android when using this plugin.
The forth line of the AdMob.java file has this line:
import android.support.design.widget.CoordinatorLayout;
with an error on design saying cannot resolve symbol 'design'
and a build error of error: package android.support.design.widget does not exist
I've added this line to my build.gradle file and it's made no difference.
implementation 'com.android.support:design:28.0.0'
I'm having to use AndroidX due to another plugin but migrating using the migrate function in Android Studio doesn't help.
Any thoughts? Is this long term issue or just my mistake somewhere (I have a web dev and iOS Swift background so building Android projects is quite alien to me, hence using Ionic)
Thanks
I had the same issue after migrating to AndroidX. You would want to use new classes and artifacts. You can find mappings here.
That line you referred to in particular should be
import androidx.coordinatorlayout.widget.CoordinatorLayout;
And in admob gradle
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
Thanks for this, seems to have gotten me a step closer (and also helped me find the AdMob Gradle files - shift shift if my friend!)
Now I have 5 errors in from MainActivity.java file on build:
error: cannot access AppCompatActivity class file for androidx.appcompat.app.AppCompatActivity not found
error: method does not override or implement a method from a supertype
error: cannot find symbol variable super
error: cannot find symbol class AdMob
error: cannot find symbol variable this
Make sure you have proper dependencies in your gradle
implementation 'androidx.appcompat:appcompat:1.1.0'
Awesome, nearly there I think, now I just get the one error
error: cannot find symbol class AdMob
from the line the docs say to add in the mainActivity add(AdMob.class); // Add AdMob as a Capacitor Plugin
It also says to import it. Did you?
import app.xplatform.capacitor.plugins.AdMob;
Whoops, missed that line. it now builds but dies immediately with errors around finding: android.support.design.widget.CoordinatorLayout
looks like it is still looking for the pre AndroidX package. I've tried running Migrate to AndroidX but that's doesn't seem to want to run/can't find anything.
2020-03-24 17:27:37.265 6799-6799/com.skbarker.calwod E/AndroidRuntime: FATAL EXCEPTION: main Process: com.skbarker.calwod, PID: 6799 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.skbarker.calwod/com.skbarker.calwod.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) 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) Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.CoordinatorLayout" on path: DexPathList[[zip file "/data/app/com.skbarker.calwod-GvHxGyN-CFiO0FgM1s7RGA==/base.apk"],nativeLibraryDirectories=[/data/app/com.skbarker.calwod-GvHxGyN-CFiO0FgM1s7RGA==/lib/x86, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at android.view.LayoutInflater.createView(LayoutInflater.java:606) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:56) at com.skbarker.calwod.MainActivity.onCreate(MainActivity.java:17) at android.app.Activity.performCreate(Activity.java:7136) at android.app.Activity.performCreate(Activity.java:7127) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) 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)
Feel like you are slowly dragging my butt to the finish line 😀
You also need to change it in your XML. CTRL+SHIFT+F (in Android Studio) can help you. This and other class mappings are here.
For the one you have, you need to change
android.support.design.widget.CoordinatorLayout
to
androidx.coordinatorlayout.widget.CoordinatorLayout
Ah man, that's got it - thank you so much. I really had no idea there would be so much work to get this to compile for Android, think I might take a crash course in Android Development to work through these kinds of issues. On iOS it could not have been simpler!
You are a super hero, is there someway I can thank you? Amazon/iTunes/Google voucher? Toilet paper? (hopefully you get that COVID-19 reference, I'm not a weirdo!)
Glad it worked, you are welcome!
Hey @rdlabo can you update the module to use AndroidX dependencies? i have to make these changes everytime I do a build and sync with android.
I did the hole process above and i could export my app but, when i install my app it fails
wow working like a charm, you are a super hero @LeXXik
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
where we need to add this ???
Hello, My name is Jatinder, I have implemented capacitor-adMob plugin in ionic+react app. and follow all process you have mentioned in this issues list. but i have facing a issue.please help me.
jave.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.addView(android.view.View)' on aa null object reference at app..xplatform.capacitor.plugin.AdMob$2.run(AdMob.java:207) at android.os.Handler.handleCallback(Handler.java:754) at android.os.Handler.dispatchMessage(Handler:java95) at android.os.Looper.loop(Looper.java:163) at android.app.ActivityThread.main(ActivityThread.java:6338) at java.lang.reflect.method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
sincerely i am lost, i am stocked in this same issue.
where do i add implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0' ??
Open android folder in android stuido under the gradle scripts build.gradle(module.app)
@shinesamuel90 thanks for ur response, i have updated that, i still have the following error when i try to build.
package does not exists - android.support.design.widget.CoordinatorLayout
change android to andridx //import android.support.design.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout; in AdMob class
Added this -> import androidx.coordinatorlayout.widget.CoordinatorLayout; But still package Cordinator layout does not exist error I am also getting same issue
I am facing the same problem. After do that https://github.com/rahadur/capacitor-admob/issues/35#issuecomment-603425302
before:
.../node_modules/capacitor-admob/android/src/main/java/app/xplatform/capacitor/plugins/AdMob.java:4: error: package android.support.design.widget does not exist
import android.support.design.widget.CoordinatorLayout;
after:
.../node_modules/capacitor-admob/android/src/main/java/app/xplatform/capacitor/plugins/AdMob.java:4: error: package androidx.coordinatorlayout.widget does not exist
import androidx.coordinatorlayout.widget.CoordinatorLayout;
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 am using an Ionic bundle and and the App still crashed after following the steps above:.
- Adding to build.gradle (capacitor-admob):
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
- Replaced the
CoordinatorLayout
import inAdMob.java
:
android.support.design.widget.CoordinatorLayout
with
androidx.coordinatorlayout.widget.CoordinatorLayout
- The App crashed on startup but this solved the issue:
npm install jetifier
npx jetify
Hope it helps.
Were you able to get it to actually show ads? I spent quite awhile but couldn't get it working.
Were you able to get it to actually show ads? I spent quite awhile but couldn't get it working.
Yes, it works for me.
Thanks a million it works
roidx.coordinatorlayout:coordinatorlayout:1.1.0'
i already have correct configuration but not working getting same error