TransformException:多个dex文件定义Lcom / google / android / gms / internal / zzcaw;

时间:2018-04-11 22:12:34

标签: java android firebase gradle flutter

我尝试过关注Google的Flutter Firebase Codelab。我们根据他们的建议添加了依赖关系,但是当我将apply plugin: 'com.google.gms.google-services'行添加到 app / build.gradle 时,我的应用停止了编译,并出现以下错误:

Dex: Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzcaw;
    UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzcaw;

com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzcaw;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
        at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
        at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
        at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzcaw;

根据我对其他类似线程的研究,这个异常意味着某些内容不止一次定义,但我很难识别出某些东西,因为异常中的zzcaw部分每次都不同。

我的应用程序是一个空的新项目,没有其他依赖项,而不是codelab建议的项目。其中一个主题提到我需要更新Google Play工具,但SDK管理员说我没有任何更新。我也尝试更改google-services软件包的版本,项目开始构建版本< = 2.2.0但应用程序无法启动:

的build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.2.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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

应用/的build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "my.app.id"
        multiDexEnabled true
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

}

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

正如您可能猜到的,我已尝试启用multiDexEnabled并升级gradle作为GitHub建议的问题之一,但无济于事。

颤动 - 医生

[√] Flutter (Channel master, v0.2.10-pre.39, on Microsoft Windows [Version 10.0.16299.371], locale en-US)
    • Flutter version 0.2.10-pre.39 at E:\VSProjects\Flutter\flutter
    • Framework revision d121cbc80d (3 days ago), 2018-04-08 09:46:11 -0700
    • Engine revision d2b69fec75
    • Dart version 2.0.0-dev.46.0.flutter-09e1766e6c

[!] Android toolchain - develop for Android devices (Android SDK 26.0.3)
    • Android SDK at D:\AndroidSDK
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 26.0.3
    • ANDROID_HOME = D:\AndroidSDK
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b01)
    X Android license status unknown.

[√] Android Studio (version 3.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b01)

[√] VS Code, 64-bit edition (version 1.22.1)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Dart Code extension version 2.11.2

[√] Connected devices (1 available)
    • Android SDK built for x86 64 • emulator-5554 • android-x64 • Android 7.1.1 (API 25) (emulator)

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  google_sign_in: "^3.0.0"

P.S。

在构建或运行没有引用google-services插件的扑动应用时,我没有任何问题。

1 个答案:

答案 0 :(得分:0)

好的,经过几天的实验,我终于明白了。正如@ cricket_007和@rmtmckenzie在问题评论中提到的那样,我没有将任何Google / Firebase服务添加到 pubspec.yaml 文件中。

我为启动器添加了firebase_analytics但它没有帮助。通过反复试验,我发现我必须将com.google.gms:google-services的版本降低到3.1.0。现在我可以编译打开我的应用程序。