问题
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-
Go to File --> Project Structure
On the left hand of the opened window, under Developer Services, select Ads
Check the checkbox next to AdMod. Your window should look like this:
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:
- Build --> Clean Project
- 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:
- Remove the dependency and admob code
- Do File -> Invalidate cache and restart
- Add back the dependency.
- 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