无法在抖动中合并dex

时间:2018-08-13 19:43:21

标签: android ios flutter

嗨,我正在开发应用程序。当我尝试建立抖动时,会出现错误Unable to merge dex

应用程序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 plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 27

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.xyz"
        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 {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    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'
    implementation 'com.google.firebase:firebase-core:16.0.0'
}

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

模块build.gradle

buildscript {
    ext.kotlin_version = '1.1.51'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.0.0'
    }
}

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
}

有人知道如何解决它吗?

3 个答案:

答案 0 :(得分:3)

尝试在应用程序build.gradle中添加它

android {
defaultConfig {
   multiDexEnabled true
 }
}

更改

classpath 'com.google.gms:google-services:4.0.0' 
implementation 'com.google.firebase:firebase-core:16.0.0'

classpath 'com.google.gms:google-services:4.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'

并在Android Studio和 清洁, 重建或只是运行flutter clean命令

答案 1 :(得分:0)

执行以下步骤:

  1. 通过运行flutter clean
  2. 清理项目
  3. 使用flutter build重建或使用flutter run运行。

我希望这会有所帮助。

答案 2 :(得分:0)

遵循此link后,为我解决了一个非常相似的问题。

**我不必将multiDexEnabled设置为true

首先,我将pubspec.yaml中的依赖项设置为

dependencies:
  flutter:
    sdk: flutter
  cloud_firestore: ^0.8.2 

并在我的IDE终端中运行flutter packages get

我还必须更改最低目标SDK版本:

  1. 打开android / app / build.gradle,然后找到显示以下内容的行 minSdkVersion 16.
  2. 将该行更改为minSdkVersion 21。
  3. 保存文件。

仅此一项就可以解决您的问题;但是,我还必须执行以下操作,因为某些依赖项版本不匹配。

我必须打开android/app/build.gradle,然后将以下行添加为文件的最后一行: apply plugin: 'com.google.gms.google-services'

接下来,我必须打开android/build.gradle,然后在buildscript标记内,添加一个新的依赖项:

buildscript {
   repositories {
       // ...
   }

   dependencies {
       // ...
       classpath 'com.google.gms:google-services:3.2.1'   // new
   }
}

此后,我的应用终于在android模拟器上运行了。

如果遇到困难,link的演练会更完整。