Mixing Google Play games with Firebase

2019-05-24 03:45发布

问题:

I added leaderboards to my android game using google games api. Now I wanted to add banner ads using the Firebase 'Wizard' of Android Studio. It builds fine, but when I try to create an apk, I get the following error:

Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzqv;

After using the wizard, my build.gradle file looks like this:

    apply plugin: 'com.android.application'

    android {
        compileSdkVersion 22
        buildToolsVersion "22.0.1"
        defaultConfig {
        applicationId "xxx"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
     }
     buildTypes {
         release {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
         }
     }
  }

  dependencies {

       compile fileTree(dir: 'libs', include: ['*.jar'])


       compile project(':BaseGameUtils')

       androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',     {
    exclude group: 'com.android.support', module: 'support-annotations'
})

      compile 'com.google.android.gms:play-services-games:10.0.1'
      compile 'com.google.firebase:firebase-ads:10.0.1'

      testCompile 'junit:junit:4.12'
   }


   apply plugin: 'com.google.gms.google-services'

I tried/read all things related to the multiple dex files problem, but nothing worked for me. Anyone has a hint for me? Do I have to use Firebase for leaderboards as well? Couldn't find how...

Thanks for any help/hints pettersson

回答1:

thanks to Clayton Wilkinson's comment, I could fix my problem. The problem was that BaseGameUtils was still using/referencing an older version of play-services. Added the correct version, and it works now. Guess I will omit BaseGameUtils for my next project.

Thanks a lot



回答2:

Sure, there are some conflicts... But, the thing is that if you talk in general terms, I mean, you use compile 'com.google.android.gms:play-services:X.X.X', it's done.



回答3:

I had the same error, just enabling proguard worked (change false to true) :

buildTypes {
    release {
        minifyEnabled true //Here change false to true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
    }
}