突然间,我无法构建一个本机应用程序。问题标题中提到的任务失败,并显示以下消息:
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzmu;
我的android/build.gradle
:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
来自android/app/build.gradle
的依赖关系部分:
dependencies {
compile project(':react-native-keychain')
compile project(':react-native-fbsdk')
compile project(':react-native-randombytes')
compile project(':react-native-barcodescanner')
compile project(':react-native-camera')
compile project(':rn-splash-screen')
compile project(':react-native-code-push')
compile project(':react-native-vector-icons')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile(project(":react-native-google-signin")){
exclude group: "com.google.android.gms"
}
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile project(':react-native-vector-icons')
compile project(':react-native-code-push')
compile project(':react-native-onesignal')
}
我听说它是由于冲突而发生的(例如谷歌游戏服务宣布两次,或者在一个地方宣布为特定服务,在另一个地方宣布为整体)但无法弄清楚是什么问题是。这里有什么问题,我该如何解决?
答案 0 :(得分:0)
我对Android的有限理解告诉我,您正在包含以某种方式共享方法名称的单独依赖项。我发现这些错误通常指向我的依赖关系树中的版本不匹配 - 在这种情况下,看起来您有多个项目,具体取决于com.google.android.gms:play-services-auth
。
您听说过的冲突似乎有问题...... exclude group
可能无法按您的意愿行事。
查看node_modules/react-native-google-signin/android/build.gradle
内部,并根据项目play-services-auth
中的play-services-auth
比较app/build.gradle
的版本。考虑到版本9.4.0的依赖关系列表点,您可以尝试设置react-native-google-signin依赖关系版本以匹配,反之亦然。
dependencies {
compile "com.google.android.gms:play-services-auth:9.4.0"
compile "com.facebook.react:react-native:+"
}
答案 1 :(得分:0)
清理gradle然后重新构建。
cd android
然后./gradlew clean