为什么我的 flutter 应用程序在下载依赖项时无法编译?
Why does my flutter app doesn't compile when I download dependencies?
我有一个新的 flutter 应用程序(除以下内容外没有添加或更改)。我需要使用这些包 url_launcher, permission_handler and 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 并在构建中设置 compilerSdkVersion 28 后 gradle
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.
中使用了支持库
检查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"
}
}
}
}
我有一个新的 flutter 应用程序(除以下内容外没有添加或更改)。我需要使用这些包 url_launcher, permission_handler and 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 并在构建中设置 compilerSdkVersion 28 后 gradle
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.
检查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"
}
}
}
}