我是新手,我会建立一个非常小的应用程序,显示当前的纬度和经度,这需要我在pubspec.yaml中添加两个依赖项: -
location和simple_permissions获取当前用户位置并询问位置权限。
但是当我运行应用程序时,它显示以下错误: -
Gradle task 'assembleDebug'...
D8: Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback
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: /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/2.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/3.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/4.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/5.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/6.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/7.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/8.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/9.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/10.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/11.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/12.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/13.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/14.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/15.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/16.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/17.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/18.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/19.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/20.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/21.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/22.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/23.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/24.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/25.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/26.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/27.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/28.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/29.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/30.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/31.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/32.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/33.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/34.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/35.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/36.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/37.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/38.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/39.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/40.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/41.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/42.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/43.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/44.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/45.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/46.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/47.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/48.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/49.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/50.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/51.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/52.jar, /home/letsdoit/IdeaProjects/location/build/app/intermediates/transforms/dexBuilder/debug/53.jar
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 9s
Finished with error: Gradle task assembleDebug failed with exit code 1
我认为这是因为添加了两次库,但我没有手动添加依赖项,所以它内部是一个颤动的错误。
请告诉我它的解决方案
输出./gradle app:依赖关系如下: -
+--- project :location
| \--- com.google.android.gms:play-services-location:15.+ -> 15.0.1
| +--- com.google.android.gms:play-services-base:[15.0.1,16.0.0) -> 15.0.1
| | +--- com.google.android.gms:play-services-basement:[15.0.1] -> 15.0.1
| | | \--- com.android.support:support-v4:26.1.0 -> 27.1.1
| | | +--- com.android.support:support-compat:27.1.1
| | | | +--- com.android.support:support-annotations:27.1.1
| | | | \--- android.arch.lifecycle:runtime:1.1.0
| | | | +--- android.arch.lifecycle:common:1.1.0
| | | | \--- android.arch.core:common:1.1.0
| | | +--- com.android.support:support-media-compat:27.1.1
| | | | +--- com.android.support:support-annotations:27.1.1
| | | | \--- com.android.support:support-compat:27.1.1 (*)
| | | +--- com.android.support:support-core-utils:27.1.1
| | | | +--- com.android.support:support-annotations:27.1.1
| | | | \--- com.android.support:support-compat:27.1.1 (*)
| | | +--- com.android.support:support-core-ui:27.1.1
| | | | +--- com.android.support:support-annotations:27.1.1
| | | | +--- com.android.support:support-compat:27.1.1 (*)
| | | | \--- com.android.support:support-core-utils:27.1.1 (*)
| | | \--- com.android.support:support-fragment:27.1.1
| | | +--- com.android.support:support-compat:27.1.1 (*)
| | | +--- com.android.support:support-core-ui:27.1.1 (*)
| | | +--- com.android.support:support-core-utils:27.1.1 (*)
| | | +--- com.android.support:support-annotations:27.1.1
| | | +--- android.arch.lifecycle:livedata-core:1.1.0
| | | | +--- android.arch.lifecycle:common:1.1.0
| | | | +--- android.arch.core:common:1.1.0
| | | | \--- android.arch.core:runtime:1.1.0
| | | | \--- android.arch.core:common:1.1.0
| | | \--- android.arch.lifecycle:viewmodel:1.1.0
| | \--- com.google.android.gms:play-services-tasks:[15.0.1] -> 15.0.1
| | \--- com.google.android.gms:play-services-basement:[15.0.1] -> 15.0.1 (*)
| +--- com.google.android.gms:play-services-basement:[15.0.1,16.0.0) -> 15.0.1 (*)
| +--- com.google.android.gms:play-services-places-placereport:[15.0.1,16.0.0) -> 15.0.1
| | \--- com.google.android.gms:play-services-basement:[15.0.1,16.0.0) -> 15.0.1 (*)
| \--- com.google.android.gms:play-services-tasks:[15.0.1,16.0.0) -> 15.0.1 (*)
+--- project :simple_permissions
| \--- com.android.support:support-v4:27.1.1 (*)
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.71
\--- org.jetbrains.kotlin:kotlin-stdlib:1.2.71
+--- org.jetbrains.kotlin:kotlin-stdlib-common:1.2.71
\--- org.jetbrains:annotations:13.0
我的应用程序的build.gradle如下: -
//noinspection GradleCompatible
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "ab"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.support:multidex:1.0.3"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
pubspec.yaml: -
name: a
description: b
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
permission_handler: ^2.2.0
location: ^2.0.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.io/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.io/custom-fonts/#from-packages
这个gradle错误信息很难解决......好吧我有这样的问题,我写了我如何解决here。无论如何,我建议你使用pubspec中更新的软件包。 simple_permissions包已经有一段时间没有更新,请尝试使用permission_handler包。其他一点,以避免未来的构建问题是将您的应用程序迁移到androidX并使用已经使用androidX的依赖项,许多官方插件正在迁移到它,当我们在同一项目中将支持库与androidX混合时,构建过程可悲地失败。如果你计划在你的应用程序中包含google_maps我真的建议你迁移做androidX而不是避免它。
AndroidX是原始的支持库包和带有其他命名空间的类。完整描述here。
您可以手动迁移到androidx,也可以使用有时失败的android-studio迁移工具。有关android-studio工具的迁移过程已经详细介绍了here。
要手动迁移,您需要通过各自的androidx软件包替换所有支持库依赖项。一个例子是:
dependencies {
// using support library
implementation 'com.android.support:appcompat-v7:$version'
}
必须替换为
dependencies {
// using androidx
implementation 'androidx.appcompat:appcompat:$version' //androidx artifact
}
可以找到Androidx工件映射here在你的gradle.properties文件中你需要在下面插入这两行
android.enableJetifier=true
android.useAndroidX=true
并确保您的flutter依赖项也使用orroix。
看看this flutter页面,它谈到androidX兼容性和迁移。
我希望它有所帮助。