为什么下载依赖项时flutter的应用程序无法编译?

时间:2019-11-12 08:12:50

标签: android flutter firebase-authentication androidx

我有一个新的flutter应用程序(除以下内容外,没有添加或更改)。我需要使用这些软件包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中设置了editorSdkVersion 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

1 个答案:

答案 0 :(得分:1)

需要将您的项目迁移到AndroidX。因为ArtifactName: dropTest/dist软件包已使用AndroidX,而您在gradle中已使用了支持库。

选中here

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

就像,此解决方案来自flutter issues

permission_handler