【问题标题】:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug' in flutter颤动中任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败
【发布时间】:2019-02-15 06:52:11
【问题描述】:

我正在尝试使用 firebase,并且我按照确切的说明进行操作,但是当我运行我的应用程序时出现此错误:

What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 10s

这是我的 build.gradle 文件:

buildscript {
    repositories {
        google()
        jcenter()
    }

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

    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

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

这是我的 android\app\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 "com.both"
        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'
}

configurations.all {
    resolutionStrategy {
        force 'com.google.android.gms:play-services-location:15.0.1'
    }
}

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

我尝试清理并重建,但没有成功。我还在 build.gradle 文件(模块:app)中尝试了 multiDexEnabled true。

有什么帮助吗? 提前致谢。

【问题讨论】:

    标签: android firebase flutter dart gradle


    【解决方案1】:

    由于 android 的 Flutter 默认最小 sdk 版本为 16 ,因此您必须在应用程序级别的 gradle 文件中添加以下依赖项以启用 multidex,如文档中所述 https://developer.android.com/studio/build/multidex

    android {
        defaultConfig {
            ...
            minSdkVersion 16 
            targetSdkVersion 27
            multiDexEnabled true
        }
        ...
    }
    
    dependencies {
      compile 'com.android.support:multidex:1.0.3' 
    }
    

    我尝试了上述解决方案,它对我有用

    【讨论】:

    • 感谢您的评论,在使用编译时出现问题,我使用了实现,并且出现错误:不推荐使用 registerResGeneratingTask,使用 registerGeneratedFolders(FileCollection) FAILURE: Build failed with an exception。 * 出了什么问题:任务 ':app:processDebugGoogleServices' 执行失败。 > 找不到与包名称“com.last”匹配的客户端 * 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。 * 在help.gradle.org获得更多帮助
    • 您是否将您从 Firebase 控制台下载的 google-services.json 文件放置在应用程序目录中,如果是,请确保您的应用程序 ID 或包名称与您在 Firebase 控制台中提供的应用程序 ID 匹配,然后转到tool > flutter > flutter clean ,然后再次构建应用程序
    • 是的,我这样做了!并确保 applicationId 与我在 firebase 控制台中编写的包名相同。还是不行
    • 在重新启动可视化代码并包含您的所有建议后,它终于可以工作了,非常感谢。
    【解决方案2】:

    转到android/app/build.gradle 并添加multiDexEnabled true

    android {
        defaultConfig {
            ...
            multiDexEnabled true
        }
    }
    

    【讨论】:

      【解决方案3】:

      如果您不覆盖 Application 类,请编辑清单文件以在 <application> 标记中设置 android:name,如下所示:

      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.myapp">
          <application
                  android:name="androidx.multidex.MultiDexApplication" >
              ...
          </application>
      </manifest>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-04
        相关资源
        最近更新 更多