不断版本在build.gradle中碰撞firebase-core。包含firebase-core的最佳方式?

时间:2018-01-08 17:26:10

标签: android firebase gradle build.gradle

app/build.gradle文件中,我觉得我经常需要对Firebase-core进行版本修改。我已按照设置建议包含了Firebase。

apply plugin: 'com.android.application'

android {
  // ...
}

dependencies {
  compile project(':react-native-fetch-blob')
  compile project(':react-native-locale')
  compile project(':react-native-fs')
  compile project(':react-native-view-shot')
  compile project(':react-native-share')
  compile project(':react-native-vector-icons')
  compile project(':react-native-spinkit')
  compile project(':react-native-image-picker')
  compile project(':react-native-device-info')
  compile project(':react-native-camera')
  compile project(':react-native-sqlite-storage')
  compile fileTree(dir: "libs", include: ["*.jar"])
  compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') { transitive = true; }
  compile 'com.android.support:appcompat-v7:23.4.0'
  compile 'com.facebook.react:react-native:+'
  compile 'com.google.firebase:firebase-core:11.8.0'

  // Getting a "Could not find" error? Make sure you have
  // added the Google maven respository to your root build.gradle
}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

如果版本不是最新的,则编译将失败并显示错误。

Dex: Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzfgf;
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzfgf;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
        at com.android.dx.command.dexer.Main.run(Main.java:277)
        at com.android.dx.command.dexer.Main.main(Main.java:245)
        at com.android.dx.command.Main.main(Main.java:106)

:app:transformClassesWithDexForProdDebug FAILED

有没有更好的方法来加入火锅?

1 个答案:

答案 0 :(得分:0)

有一种更容易实现的方式...

我现在在根build.gradle中定义一个变量

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
 ext {
        googlePlayServicesVersion = "16.+"
    }

然后在应用程序的`build.gradle

dependencies {
  implementation "com.google.firebase:firebase-core:${rootProject.ext.googlePlayServicesVersion}"

}

这有点hacky,因为您正在获取次要版本的最新版本/