2016-07-04 21 views
20

我遇到一个问题与火力地堡整合。首先,我已经添加规则到根级build.gradle文件:多DEX文件定义LCOM /谷歌/火力/ FirebaseException

buildscript { 
    repositories { 
     maven { url "http://dl.bintray.com/populov/maven" } 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.2' 
     classpath 'com.google.gms:google-services:3.0.0' 
    } 
} 

allprojects { 
    repositories { 
     maven { url "http://dl.bintray.com/populov/maven" } 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

和模块摇篮文件:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 24 
    buildToolsVersion "24" 

    defaultConfig { 
     applicationId "com.example.app" 
     minSdkVersion 14 
     targetSdkVersion 24 
     versionCode 2 
     versionName "0.9" 
    } 
    buildTypes { 
     /// 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile 'com.google.firebase:firebase-core:9.0.2' 
    compile 'com.google.firebase:firebase-crash:9.0.2' 
} 

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

在项目的建设,我得到的错误:

Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/FirebaseException;

错误的原因是明确的,但我没有任何编译库的两倍。我应该从构建过程手动排除FirebaseException类吗?如果是这样,怎么样?也许这是Firebase依赖关系中的一个错误?

谢谢。

回答

3

看起来你已经达到methods count limit。尝试删除firebase依赖和检查方法计算你的应用程序(例如,使用this gradle plugin(如果不删除这些依赖关系,你将不能够在所有的建设项目,因此,使用的方法计数插件)。 。

火力地堡is a HUGE library - 17K +方法这取决于吨的东西有一两件事你可以做的是通过点击“methodscount.com”按钮检查依存列表: enter image description here

如果你已经有一些这些在你的项目,你可以尝试将它们排除在外:

compile ('com.google.firebase:firebase-core:9.0.2') { 
    exclude module: 'play-services-base' 
    exclude module: 'support-v4' 
    exclude module: 'support-annotations' 
} 

如果这没有帮助,那么你可能想为你的项目configure multidex

13

我有这个问题react-native-google-signin模块。由于说明如何修改build.gradle通常不是最新的,不完整的或只是在多个不相关的项目中定义的,项目只有在复制react-native-google-signin示例项目中的设置后才编译。原来声明的顺序很重要,以及exclude group命令。最后的结果看起来是这样(在app/build.gradle):

dependencies { 
    ... 
    compile 'com.google.android.gms:play-services-auth:9.2.1' 
    compile(project(":react-native-google-signin")) { 
     exclude group: "com.google.android.gms" 
    } 
} 

task copyDownloadableDepsToLibs(type: Copy) { 
    from configurations.compile 
    into 'libs' 
} 

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

顶部build.gradle包括另外gms类路径和往常一样:

buildscript { 
    repositories { 
     jcenter() 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.2' 
     classpath 'com.google.gms:google-services:3.0.0' 
    } 
} 

这些更改后建立一个没有任何Multiple dex错误结束。 2.0.0:

+3

也有这个问题的反应本机推送通知库 –

+0

也有这由于来自AirBnB的react-native-maps。 – mxcl

+0

谢谢,我创建了PR => https://github.com/joonhocho/react-native-google-sign-in/pull/25 – SaroVin

-2

请的build.gradle

dexOptions { 
    preDexLibraries = false 
} 
+0

错误:将字节码转换为dex时出错: 原因:java.lang.RuntimeException :翻译已被中断 – Khan

0

里面添加这个机器人的代码,我当我使用火力的UI遇到此错误。我设法降级到'com.firebaseui:firebase-ui:1.2.0'来解决它,并添加了项目一级的build.gradle以下行:

allprojects { 
    repositories { 
     jcenter() 

     // Add the following 
     maven { 
      url 'https://maven.fabric.io/public' 
     } 
    } 
} 
2

火力是一个巨大的图书馆,所以你需要让你的应用程序multidex支持。

dependencies { 
    compile ('com.google.firebase:firebase-core:9.0.2') { 
     exclude module: 'play-services-base' 
     exclude module: 'support-v4' 
     exclude module: 'support-annotations' 
    } 
    compile 'com.android.support:multidex:1.0.1' 
} 

defaultConfig { 
     // Enabling multidex support. 
     multiDexEnabled true 
} 
+0

这对我有效! – marchinram

1

在情况下,它可以帮助任何人,我被击中了类似的问题,它是由摇篮插件谷歌服务带来与火力地堡相冲突的依赖造成的。

在我最顶层的build.gradle我有,在buildscript:

classpath 'com.google.gms:google-services:3.0.0' 

其中又引进(自动)的依赖,其用矛盾的,在我的应用程序的的build.gradle:

compile 'com.firebaseui:firebase-ui-auth:2.2.0' 

有点混乱,因为我只有一个编译依赖关系,正在摸索着我的脑袋,可能会发生冲突。

我删除了google-services gradle插件,它解决了这个问题。我想我也可以找到正确的版本:)

0

感谢this post,只需检查并升级您的谷歌依赖版本到最新版本。

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.

0

我使用反应,本机地图反应母语 - 谷歌 - 登入。

而且,我得到多DEX文件定义LCOM /谷歌/火力/ FirebaseException

娄我的解决方案。

开放的build.gradle(反应 - 本机地图)

dependencies { 
    provided "com.facebook.react:react-native:+" 
    compile "com.google.android.gms:play-services-base:10.2.4" 
    compile "com.google.android.gms:play-services-maps:10.2.4" 
} 

的版本是10.2.4

继续开放的build.gradle(反应母语 - 谷歌式登入)

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile "com.android.support:appcompat-v7:23.0.1" 
    compile 'com.google.android.gms:play-services-auth:9.2.1' <- change here 
    compile "com.facebook.react:react-native:+" 
} 

它使用9.2.1版本,这就是原因。

将其更改为10.2.4版本将

compile 'com.google.android.gms:play-services-auth:10.2.4' 

接下来,打开的build.gradle(应用程序),并添加一个新的

compile 'com.google.android.gms:play-services-auth:10.2.4' 

现在你有。

compile 'com.google.android.gms:play-services-auth:10.2.4' 
compile(project(":react-native-google-signin")){ 
    exclude group: "com.google.android.gms" 
} 

运行命令cd android & gradlew clean & cd .. UTIL没有错误,则运行react-native run-android。 希望可以提供帮助。

0

这是因为您的某些库使用其他库的不同版本。

查看您最近添加的库并排除。 对于我的项目是“反应 - 本地 - 垛”。

compile(project(':react-native-firestack')){ 
    exclude group: "com.google.android.gms" // very important 
} 
相关问题