【问题标题】:error with flutter and android gradle :Execution failed for task ':app:checkDebugDuplicateClasses'颤振和android gradle错误:任务':app:checkDebugDuplicateClasses'的执行失败
【发布时间】:2020-10-10 22:02:17
【问题描述】:

我已经在我的项目中实现了flutterDownloader(它是一个用于在flutter中下载文件的包),当我像文档所说的那样将它添加到android清单时,当我这样做时,gradle会显示这个错误

**错误:**


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules guava-26.0-android.jar (com.google.guava:guava:26.0-android) and listenablefuture-1.0.jar (com.google.guava:listenablefuture:1.0)

  Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.


* 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 3m 15s
Exception: Gradle task assembleDebug failed with exit code 1

我的安卓清单-> Android 清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.kivoc99.mscmu">
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="mscmu"
        android:icon="@mipmap/ic_launcher">
        <provider
            android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider"
            android:authorities="${applicationId}.flutter_downloader.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>
        <provider
            android:name="androidx.work.impl.WorkManagerInitializer"
            android:authorities="${applicationId}.workmanager-init"
            tools:node="remove" />

        <provider
            android:name="vn.hunghd.flutterdownloader.FlutterDownloaderInitializer"
            android:authorities="${applicationId}.flutter-downloader-init"
            android:exported="false">
            <!-- changes this number to configure the maximum number of concurrent tasks -->
            <meta-data
                android:name="vn.hunghd.flutterdownloader.MAX_CONCURRENT_TASKS"
                android:value="5" />
        </provider>
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />

    </application>
</manifest>

bulid.gradle:app

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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.kivoc99.mscmu"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        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 'com.android.support:multidex:1.0.3'
}

buildgradle:android

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath 'com.google.gms:google-services:4.3.4'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这里有什么问题?我已经尝试完全按照文档所说的去做,有什么帮助吗?

【问题讨论】:

  • 问题可能出在 firebase 插件上,请查看 this 并发布您的 build.gradle。
  • 哪个 build.gradle :app 或 android ?
  • 我的意思是android/build.gradle,因为它有android gradle 工具版本。
  • 显然这是一个已知问题,参考this您可以通过将implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'添加到您的依赖项来解决它。
  • 将此行添加到 bulid.gradle:app 文件底部的依赖项中,就在 multidex 行的下方。 implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'

标签: android flutter


【解决方案1】:

检查您的 pubspec.yaml 并在依赖项下找到重复项。 例如:您可能在同一个项目中使用条形码扫描仪和图像选择器。条码扫描仪内部有一个图像选择器。所以会出现这样的问题。

【讨论】:

    【解决方案2】:

    尝试将implementation 'com.google.guava:guava:28.2-android' 添加到您的bulid.gradle:app。请参考thisthis 了解更多信息。

    【讨论】:

    • 这是唯一对我有用的东西。您需要在 android stusio 中打开 gradle 文件并同步
    【解决方案3】:

    如果您使用的是 androidX 或 jetifier,您的项目中需要有以下内容android/gradle.properties

    android.useAndroidX=true
    android.enableJetifier=true
    

    【讨论】:

      猜你喜欢
      • 2021-08-11
      • 2022-10-20
      • 2020-05-30
      • 2021-08-30
      • 1970-01-01
      • 2022-09-23
      • 2019-10-05
      • 2020-03-29
      • 2021-10-09
      相关资源
      最近更新 更多