任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败 [英] Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug' in flutter

查看:286
本文介绍了任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Firebase,但我遵循了确切的说明进行操作,但是当我运行我的应用程序时,出现此错误:

I am trying to use firebase and i followed the exact instructions to do so, but when i run my app i get this error:

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文件:

This is my build.gradle file:

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:

And this is my 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.

I tried clean and rebuild, but it did not work. I also tried multiDexEnabled true in the in build.gradle file (Module: app).

有帮助吗? 预先感谢.

Any help? Thanks in advance.

推荐答案

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

since flutter default min sdk version for android is 16 , you have to add the following dependancies in your app level gradle file to enable multidex as mentioned in documentation https://developer.android.com/studio/build/multidex

android {
    defaultConfig {
        ...
        minSdkVersion 16 
        targetSdkVersion 27
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.3' 
}

我尝试了上述解决方案,对我来说很有效

i tried the above solution and it's works for me

这篇关于任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆