简体   繁体   中英

Error using AdMob and Google Play Game Services at the same time

I am using libgdx and Android studios. I have successfully implemented google play game services (leaderboards etc). Now I want to implement admob, but I get errors.

This is part of my build.gradle:

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-arm64-v8a"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
    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-arm64-v8a"
    natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
    natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
    compile 'com.google.android.gms:play-services-games:11.2.0'
    compile 'com.google.android.gms:play-services-ads:11.2.0'
    //compile 'com.google.android.gms:play-services:10.0.1'
    compile fileTree(dir: '../libs', include: '*.jar')
    compile project(":BaseGameUtils")
}

}

If I press build->clean projects, everything seems fine, but when I want to run the app on my android phone, I get this error:

Error:Execution failed for task 
':android:transformClassesWithJarMergingForRelease'.
> com.android.build.api.transform.TransformException: 
java.util.zip.ZipException: duplicate entry: 
com/google/android/gms/internal/zzqv.class

It is the compile 'com.google.android.gms:play-services-ads:11.2.0' part that messes things up. If i remove that line, everything works as before, but I cant use AdMob.

Anyone knows what the problem might be?

When I used Eclipse, I included the google-play-service library as a project, and did not need to add anything to the build.gradle... why is it different in AndroidStudios?

It's due to artifact mismatch/version conflict.

Remove

compile 'com.google.android.gms:play-services-games:11.2.0'

from your android dependencies tag of root build.gradle file, BaseGameUtils already have that that dependency. Check supporting version in build.gradle of BaseGameUtils module.

Also It's better to use artifact from repo insted of from libs folder.

You can also inject tween engine

repositories {
    maven { url "https://jitpack.io" }
}

compile 'com.github.arcnor:universal-tween-engine:6.3.4'
compile 'com.github.arcnor:universal-tween-engine:6.3.4:sources'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM