本文介绍了D8:程序类型已经存在:android.support.v4.media.MediaBrowserCompat $ CustomActionCallback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我是不熟悉flutter的人,我构建了一个很小的应用程序来显示当前的纬度和经度,这需要我在pubspec.yaml中添加两个依赖项:-

I am new to flutter and i build a very little app showing current latitude and longitude which required me to add two dependencies in pubspec.yaml :-

location和simple_permissions可以获取当前用户的位置并请求位置权限.

location and simple_permissions to get current user location and asking for location permission.

但是当我运行该应用程序时,它显示以下错误:-

but when i ran the app it shows following error:-

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

我认为这是因为两次添加了一个库,但是我没有手动添加依赖项,因此内部出现了抖动错误.

i think it is because of adding a library two times but i am not adding dependencies manually so it is flutter error inside.

请告诉我解决方法

./gradlew app:dependecies的输出如下:-

Output Of ./gradlew app:dependecies is as follows:-

+--- 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如下:-

build.gradle for my app is as follows :-

//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:-

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错误消息是如此难以解决...好吧,我遇到了这样的问题,并写了解决方法.无论如何,我建议您在pubspec中使用更新的软件包. simple_permissions软件包已有一段时间没有更新,请尝试使用 permission_handler 软件包.避免将来出现构建问题的另一点是将您的应用程序迁移到androidX并使用已经使用androidX的依赖项,很多官方插件也正在迁移到该依赖项,并且当我们在同一项目中将支持库与androidX混合使用时,构建过程会失败.如果您打算在您的应用程序中包含google_maps,我真的建议您迁移到androidX,而不要避免使用它.

This gradle error messages are so hard to solve... Well I had some problems like this and I wrote how I solved here. Anyway I advise you to use updated packages in your pubspec. simple_permissions package has been a while there is no updates, try permission_handler package instead. Other point to avoid future build problems is migrate your app to androidX and use dependencies which already using androidX too, a lot of official plugins are migrating to it and when we mix support library with androidX in the same project the build process fails sadly. If you are planning include google_maps in you app I really recommend you migrate to androidX instead avoid it.

AndroidX是原始的支持库程序包和带有其他命名空间的类.完整说明此处.

AndroidX is the original support library packages and classes with other namespace. Full description here.

您可以手动迁移到androidx,也可以使用有时会失败的android-studio迁移工具.在此处中已描述了使用android-studio工具进行的迁移过程详细信息.

You can migrate to androidx manually or you can use android-studio migration tool that some times fails. A migration process with android-studio tools has been already described here in details.

要手动迁移,您需要用相应的androidx软件包替换所有支持库依赖项.一个例子是:

To migrate manually you need replace all your support library dependencies by respective androidx package. An example is:

dependencies {
   // using support library
   implementation 'com.android.support:appcompat-v7:$version'
}

必须替换为

dependencies {
       // using androidx
       implementation 'androidx.appcompat:appcompat:$version' //androidx artifact
    }

可以在此处找到Androidx工件映射在gradle.properties文件中,您需要在下面插入这两行

Androidx artifact mappings can be found hereIn your gradle.properties file you need insert this two lines below

android.enableJetifier=true
android.useAndroidX=true

并确保您的flutter依赖项也正在使用androix.

And make sure your flutter dependencies are using androix too.

看看扑朔迷离的页面关于androidX的兼容性和迁移.

Take a look at this flutter page it talks about androidX compatibility and migration.

希望对您有帮助.

这篇关于D8:程序类型已经存在:android.support.v4.media.MediaBrowserCompat $ CustomActionCallback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 18:04