I can't import or use AdView for android

荒凉一梦 提交于 2020-06-29 05:30:17

问题


I'm making an android game using libgdx and I want to add ad banners so I followed some instructions online.

// I added this code on build.gradle in the dependencies:
compile "com.google.android.gms:play-services-ads:8.3.0"

then set the minimum sdk to 9, It didn't ask me to sync so I did it manually(btw I'm using intellij) then when I tried to add codes on AndroidLauncher I was not able to use AdView(I can't even import it cause it doesn't appear).

UPDATE my project structure is different

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        compile "com.google.android.gms:play-services-ads:8.4.0"
    }
}

when I highlight the code for compiling the google play services - ads at the bottom it shows this message "Dependency on Play Services, but the SDK installation does not have the "Extras > Google Repository" installed. Open the SDK manager and install it." But I have the google repository installed and it's the latest version.


回答1:


See if this helps: In Android Studio do the following-

  1. Go to File --> Project Structure

  2. On the left hand of the opened window, under Developer Services, select Ads

  3. Check the checkbox next to AdMod. Your window should look like this:

  4. Click OK

This will add the required dependency to the Android's build.gradle, and sync Gradle.

When the sync is done, and just to make sure, clean and rebuild your project:

  1. Build --> Clean Project
  2. Build --> Rebuild Project

Update: In effect, I think what this does is add the "Ad dependency" to the build.gradle file in the android project. So if the above tutorial does not work, try adding

dependencies {
    compile 'com.google.android.gms:play-services-ads:8.4.0'
}

to the bottom of build.gradle file in the android project (not the one under core project).

I hope this helps.




回答2:


Try this:

  1. Remove the dependency and admob code
  2. Do File -> Invalidate cache and restart
  3. Add back the dependency.
  4. Sync with gradle

Also make sure the components are downloaded and updated to the version you are using from Android SDK manager.




回答3:


I resolved the problem by updating my intellij ide from version 14 to 15, it basically reinstalled the ide and I had to import the entire project again.



来源:https://stackoverflow.com/questions/34963633/i-cant-import-or-use-adview-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!