我有一个新的flutter应用程序(除了以下内容,没有添加或更改)。我需要使用这些包url_launcher,permission_handler和firebase_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
需要将您的项目迁移到AndroidX。因为permission_handler
程序包使用了AndroidX,并且您在gradle中使用了支持库。
在这里检查。
正如@Kshitij Dhakal所建议的,当同一库的版本在不同的程序包中不同时,您还需要应用依赖项解析。
就像,此解决方案是从抖动问题中获取的。
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'androidx.core'
&& !details.requested.name.contains('androidx')) {
details.useVersion "1.0.1"
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句