【问题标题】:Why does my flutter app doesn't compile when I download dependencies?为什么我下载依赖项时我的 Flutter 应用程序无法编译?
【发布时间】:2019-11-12 08:12:50
【问题描述】:

我有一个新的颤振应用程序(除以下内容外,没有添加或更改任何内容)。我需要使用这些包url_launcherpermission_handlerfirebase_auth。但是只要我在我的 main.dart 文件中导入这些包(在添加 pubsec.yaml 之后)

import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:permission_handler/permission_handler.dart';

编译失败并显示如下错误。

D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
  Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
BUILD FAILED in 7s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See (this link will be in the comment) for more information on the problem and how to fix it.
*******************************************************************************************
Finished with error: Gradle task assembleDebug failed with exit code 1

如何在同一个项目中使用所有这三个包。 (我认为是因为 androidX 兼容性)

在 gradlew.properties 添加以下内容并在 build gradle 中设置 compilerSdkVersion 28 后

android.useAndroidX=true
android.enableJetifier=true
android {
    compileSdkVersion 28
..

现在我收到以下错误。

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0-rc01) and runtime (1.1.0) classpath. You should manually set the same version via DependencyResolution

【问题讨论】:

  • 这是命名冲突。请参考Program type already present
  • 我该怎么办? @user5607081
  • 您需要将项目迁移到 AndroidX。因为软件包使用了 AndroidX,而你在 gradle 中使用了 Support。
  • 检查here
  • @AbhayKoradiya 我使用您的链接解决了问题。将此添加到答案中,以便我接受。还要添加这个link

标签: android flutter firebase-authentication androidx


【解决方案1】:

需要将您的项目迁移到 AndroidX。因为permission_handler 包使用了AndroidX,而你在gradle 中使用了支持库。

检查here

正如@Kshitij Dhakal 所建议的,当不同包中同一库的版本不同时,您还需要应用依赖解析。

喜欢,这个解决方案取自flutter issues

subprojects {
    project.configurations.all {
    resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'androidx.core' 
                       && !details.requested.name.contains('androidx')) {
                  details.useVersion "1.0.1"
            }
       }
    }    
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-09
    • 1970-01-01
    • 1970-01-01
    • 2017-05-13
    • 2019-10-07
    • 1970-01-01
    • 2019-07-21
    相关资源
    最近更新 更多