Flutter的Multidex问题 [英] Multidex issue with Flutter

查看:451
本文介绍了Flutter的Multidex问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android Studio中使用Flutter使用gradle编译时遇到以下错误:

I'm getting the following error compiling with gradle using Flutter in Android Studio:

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

[... stacktrace omitted for brevity ...]

* 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/zzcew;

简短版本

这仅在我添加了足够的依赖项时才会发生,这可能是预期的.我已按照指令启用了multidex并在Android项目build.gradle文件中添加了multidex依赖项( https://developer.android.com/studio/build/multidex.html ),但不确定为Flutter应用程序执行为Multidex配置应用程序"中的第2步,甚至不确定是否遗漏了该步骤是问题所在.

The short version

This only occurs if I add enough dependencies, as might be expected. I've enabled multidex and added the multidex dependency in the Android project build.gradle file as per instructions (https://developer.android.com/studio/build/multidex.html), but wasn't sure what to do about step 2 in "Configure your app for multidex" for a Flutter App, or even whether the omission of that step was the problem.

  1. 从工具栏中选择File/New/New Flutter Project
  2. 选择"Flutter应用程序"
  3. 包括Kotlin&迅捷支持
  4. 检查应用程序可编译并运行
  5. 将以下内容添加到pubspec.yaml中的依赖项:

  1. Select File/New/New Flutter Project from the toolbar
  2. Select "Flutter Application"
  3. Include Kotlin & Swift support
  4. Check the app compiles and runs
  5. Add the following to dependencies in pubspec.yaml:

dependencies:
  flutter_google_place_picker: "^0.0.1"
  location: "^1.2.0"

  • 在Android Studio中点击Packages Get或在项目目录中运行flutter packages get
  • 修改android/app/build.gradle在适当的位置添加以下部分:

  • Hit Packages Get in Android Studio or run flutter packages get in the project directory
  • Modify android/app/build.gradle to add the following sections in the appropriate places:

    dependencies {
      compile 'com.android.support:multidex:1.0.1'
    }
    android {
        defaultConfig {
            multiDexEnabled true
        }
    }
    

  • 从工具栏中选择Run/Run
  • Select Run/Run from the toolbar
  • 我尝试过的其他事情

    1. 用以下每个替换build.gradle中的编译"依赖项:

    compile 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:multidex:1.0.1'
    implementation 'com.android.support:multidex:1.0.3'
    

  • 为我的每个依赖项执行multidex步骤;即修改其build.gradle文件,启用multidex并添加multidex依赖项.

  • Following the multidex steps for each of my dependencies; i.e. modifying their build.gradle files, enabling multidex and adding the multidex dependency.

    完全不启用multidex(即,跳过重新创建的步骤7).这将导致以下错误:

    Not enabling multidex at all (i.e. skipping step 7 of recreating). This results in the following error:

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

  • Flutter Doctor输出

    $ flutter doctor -v
    [√] Flutter (Channel beta, v0.2.8, on Microsoft Windows [Version 10.0.16299.371], locale en-GB)
        • Flutter version 0.2.8 at D:\flutter
        • Framework revision b397406561 (2 weeks ago), 2018-04-02 13:53:20 -0700
        • Engine revision c903c217a1
        • Dart version 2.0.0-dev.43.0.flutter-52afcba357
    
    [√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
        • Android SDK at C:\Users\Dave\AppData\Local\Android\sdk
        • Android NDK location not configured (optional; useful for native profiling support)
        • Platform android-27, build-tools 27.0.3
        • Java binary at: D:\AndroidDev\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
        • All Android licenses accepted.
    
    [√] Android Studio (version 3.1)
        • Android Studio at D:\AndroidDev
        • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
    
    [√] Connected devices (1 available)
        • Android SDK built for x86 64 • emulator-5554 • android-x64 • Android 5.1.1 (API 22) (emulator)
    
    • No issues found!
    

    推荐答案

    您的两个软件包似乎在传递依存关系上存在分歧.一个想要11.6.+,另一个想要11. +的某些播放服务依赖性.由于11.6.2和11.8.0都在那儿,所以最终将导致冲突.

    Your two packages seem to disagree on their transitive dependencies. One wants 11.6.+, the other wants 11.+ of some play-services dependencies. Since both 11.6.2 and 11.8.0 are out there, this is going to end up with a conflict.

    如果在android/文件夹中运行./gradlew androidDependencies,则会得到依赖关系解析结果的列表,其中包括以下内容:

    If you run ./gradlew androidDependencies in your android/ folder, you get a listing of the result of dependency resolution, containing, among others, the following:

    +--- :flutter_google_place_picker (variant: release)
    +--- com.google.android.gms:play-services-location:11.8.0@aar
    +--- com.google.android.gms:play-services-places:11.6.2@aar
    +--- com.google.android.gms:play-services-maps:11.6.2@aar
    +--- com.google.android.gms:play-services-base:11.8.0@aar
    +--- com.google.android.gms:play-services-tasks:11.8.0@aar
    +--- com.google.android.gms:play-services-basement:11.8.0@aar
    

    这些11.6.2和11.8.0软件包不能一起使用.要解决此问题,您需要修补依赖项以使其彼此一致,或者将依赖项覆盖添加到android/app/build.gradle文件的顶层,并希望做到最好:

    These 11.6.2 and 11.8.0 packages are not going to work together. To resolve this, you need to patch your dependencies to be consistent with each other, or add a dependency override to the top level of your android/app/build.gradle file and hope for the best:

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

    这篇关于Flutter的Multidex问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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