capacitor-admob icon indicating copy to clipboard operation
capacitor-admob copied to clipboard

import android.support.design.widget.CoordinatorLayout;

Open simonbarker opened this issue 4 years ago • 26 comments

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

simonbarker avatar Mar 22 '20 16:03 simonbarker

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'

LeXXik avatar Mar 23 '20 17:03 LeXXik

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

simonbarker avatar Mar 23 '20 18:03 simonbarker

Make sure you have proper dependencies in your gradle implementation 'androidx.appcompat:appcompat:1.1.0'

LeXXik avatar Mar 23 '20 19:03 LeXXik

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

simonbarker avatar Mar 23 '20 20:03 simonbarker

It also says to import it. Did you? import app.xplatform.capacitor.plugins.AdMob;

LeXXik avatar Mar 24 '20 11:03 LeXXik

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 😀

simonbarker avatar Mar 24 '20 17:03 simonbarker

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

LeXXik avatar Mar 24 '20 18:03 LeXXik

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

simonbarker avatar Mar 24 '20 18:03 simonbarker

Glad it worked, you are welcome!

LeXXik avatar Mar 24 '20 19:03 LeXXik

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.

mukeshsolanki avatar Apr 14 '20 14:04 mukeshsolanki

I did the hole process above and i could export my app but, when i install my app it fails

AlexitoReyes54 avatar Apr 21 '20 13:04 AlexitoReyes54

wow working like a charm, you are a super hero @LeXXik

shinesamuel1990 avatar Apr 23 '20 11:04 shinesamuel1990

implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'

where we need to add this ???

JatinderSingh16 avatar May 07 '20 15:05 JatinderSingh16

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)

JatinderSingh16 avatar May 08 '20 06:05 JatinderSingh16

sincerely i am lost, i am stocked in this same issue.

where do i add implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0' ??

shoutershub avatar May 23 '20 20:05 shoutershub

Open android folder in android stuido under the gradle scripts build.gradle(module.app)

shinesamuel90 avatar May 24 '20 08:05 shinesamuel90

@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

shoutershub avatar May 24 '20 17:05 shoutershub

change android to andridx //import android.support.design.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout; in AdMob class

shinesamuel90 avatar May 25 '20 13:05 shinesamuel90

Added this -> import androidx.coordinatorlayout.widget.CoordinatorLayout; But still package Cordinator layout does not exist error I am also getting same issue

developerakkoo avatar Jun 10 '20 11:06 developerakkoo

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;

maykon-oliveira avatar Sep 15 '20 15:09 maykon-oliveira

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

inspire22 avatar Sep 18 '20 05:09 inspire22

I am using an Ionic bundle and and the App still crashed after following the steps above:.

  1. Adding to build.gradle (capacitor-admob):
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
  1. Replaced the CoordinatorLayout import in AdMob.java :
android.support.design.widget.CoordinatorLayout

with

androidx.coordinatorlayout.widget.CoordinatorLayout
  1. The App crashed on startup but this solved the issue:
npm install jetifier
npx jetify

Hope it helps.

xErik avatar Oct 23 '20 13:10 xErik

Were you able to get it to actually show ads? I spent quite awhile but couldn't get it working.

inspire22 avatar Oct 23 '20 22:10 inspire22

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.

xErik avatar Oct 28 '20 11:10 xErik

Thanks a million it works

okenwa avatar Feb 02 '21 05:02 okenwa

roidx.coordinatorlayout:coordinatorlayout:1.1.0'

i already have correct configuration but not working getting same error

ibalaji777 avatar Jul 07 '21 18:07 ibalaji777