【问题标题】:Execution failed for task ':app:checkDebugDuplicateClasses'. Ionic4 Android任务 ':app:checkDebugDuplicateClasses' 执行失败。离子4安卓
【发布时间】:2019-11-05 01:10:48
【问题描述】:

我目前正在开发 ionic4 应用程序,但最近在将 https://ionicframework.com/docs/native/fcm 插件添加到应用程序后,在 android realll 设备上构建应用程序时它停止工作。

起初它抱怨结构密钥,但我从未打算在我的应用程序上使用结构崩溃分析。

错误日志:

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.IResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.ResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.ResultReceiver$1 found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)

  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 21s

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
35 actionable tasks: 5 executed, 30 up-to-date
cmd: Command failed with exit code 1 Error output:
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 android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.IResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.ResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.ResultReceiver$1 found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)
  Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:27.1.1)

  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 21s
[ERROR] An error occurred while running subprocess cordova.

        cordova run android exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.

android/app/build.gradle

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' } // Fabrics Maven repository from cordova-plugin-firebase
    }
    dependencies {

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.android.tools.build:gradle:3.4.0+'
        classpath 'com.google.gms:google-services:4.2.0' // google-services dependency from cordova-plugin-firebase
        classpath 'io.fabric.tools:gradle:1.+' // fabric dependency from cordova-plugin-firebase
    }
}

allprojects {
    repositories {

        jcenter()
        google() // Google's Maven repository from cordova-plugin-firebase
    }
    //This replaces project.properties w.r.t. build settings
    project.ext {
      defaultBuildToolsVersion="28" //String
      defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
      defaultTargetSdkVersion=28 //Integer - We ALWAYS target the latest by default
      defaultCompileSdkVersion=28 //Integer - We ALWAYS compile with the latest by default
    }
}

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

cordova-plugin-firebase/raihan-build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
       classpath 'com.android.tools.build:gradle:3.4.0+'
        classpath 'com.google.gms:google-services:4.2.0'
    }
}


dependencies {
    compile 'me.leolin:ShortcutBadger:1.1.4@aar'
    compile 'com.google.firebase:firebase-auth:+'
    compile('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
       transitive = true
    }
}
cdvPluginPostBuildExtras.add({
    // apply plugin: 'com.google.gms.google-services'
    apply plugin: 'io.fabric'
})

cordova-plugin-fcm-with-dependecy-updated/raihan-FCMPlugin.gradle

buildscript {
    repositories {
       google()
        jcenter()
        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0+'
        classpath 'com.google.gms:google-services:4.2.0'
    }
}
repositories {
    google()
    jcenter()
}
dependencies {
    compile 'com.google.firebase:firebase-core:16.0.8'
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
// apply plugin: com.google.gms.googleservices.GoogleServicesPlugin

android/project.properties

 target=android-27
    android.library.reference.1=CordovaLib
    android.library.reference.2=app
    cordova.gradle.include.1=cordova-android-support-gradle-release/raihan-cordova-android-support-gradle-release.gradle
    cordova.system.library.1=com.squareup.okhttp3:okhttp-urlconnection:3.10.0
    cordova.system.library.2=com.android.support:support-v4:24.1.1+
    cordova.system.library.3=com.soundcloud.android:android-crop:1.0.0@aar
    cordova.system.library.4=com.google.firebase:firebase-core:16.0.8
    cordova.system.library.4=com.google.firebase:firebase-iid:17.1.1
    cordova.system.library.5=com.google.firebase:firebase-messaging:17.5.0
    cordova.gradle.include.2=cordova-plugin-fcm-with-dependecy-updated/raihan-FCMPlugin.gradle
    cordova.gradle.include.3=cordova-support-google-services/raihan-build.gradle
    cordova.system.library.6=com.google.firebase:firebase-auth:16.2.0
    cordova.system.library.6=com.google.firebase:firebase-perf:16.2.4
    cordova.system.library.7=com.android.support:support-annotations:27.+
    cordova.system.library.8=com.android.support:appcompat-v7:23+
    cordova.system.library.8=com.google.firebase:firebase-iid:17.1.1
    cordova.system.library.8=com.google.android.gms:play-services-tagmanager:16.0.8
    cordova.system.library.8=com.google.firebase:firebase-config:16.4.0
    cordova.gradle.include.4=cordova-plugin-telerik-imagepicker/raihan-ignorelinterrors.gradle
    cordova.gradle.include.5=cordova-plugin-telerik-imagepicker/raihan-androidtarget.gradle
    cordova.gradle.include.6=cordova-android-support-gradle-release/raihan-cordova-android-support-gradle-release.gradle
    cordova.gradle.include.7=cordova-plugin-firebase/raihan-build.gradle

我已经提供了以上文件,如果我需要上传其他文件,请告诉我。

【问题讨论】:

    标签: android firebase cordova ionic-framework cordova-plugin-fcm


    【解决方案1】:
    1. 转到 gradle.properties(项目属性)

    2. 添加
      android.enableJetifier=true

    3. 而且大部分时间android.useAndroidX=true 都存在。检查您的 gradle.properties(Project Properties),如果它不存在,则添加
      android.useAndroidX=true -> 看起来喜欢这张图片

    【讨论】:

    【解决方案2】:

    您的项目(或其子项目之一)在其末尾使用 +(加号)来引用依赖项,例如 com.google.firebase:firebase-auth:+,这意味着,使用任何更高版本在可能的情况下,新版本不再使用android.support 库,而是使用androidx;要解决此问题,请按照以下步骤操作。

    步骤:

    1. 确保设置了 ANDROID_HOME 环境变量,然后打开一个控制台窗口(如 git-bash,因为它保留整个命令输出),然后将 cd 放入您的 android 目录(对于 Ionic 项目应该是platforms/android)。
    2. 首先,通过以下运行(在 git-bash 中)列出所有依赖项
      ./gradlew :app:dependencies
      
    3. 将结果复制到您喜欢的文本编辑器中,然后搜索androidx
    4. 如果您发现了某些内容,请按照以下步骤操作,否则您就完成了! (您无需重复这些步骤)。
    5. 向上滚动直到在任何行的末尾看到 ->,例如 16.0.8 -&gt; 19.0.0+ -&gt; 19.0.0,其中两者都表示版本是自动解析的(由于+,版本高于您指定的版本)。
    6. 所以,手动设置版本:
      • 如果可能,在您的项目中找到 + 符号并将其替换为特定版本。
      • 或者,强制使用特定版本的依赖项,如下所述。
    7. 最后,重复上述步骤(但不是第一步,而是 clear 控制台)。

    强制特定版本的依赖项添加到您的根目录 build.gradle 如下所示(这对我有用)但编辑并添加您自己的规则(如果这些规则不适合您):

    allprojects {
      // ...
      configurations.all {
        resolutionStrategy {
          force 'com.google.firebase:firebase-common:17.0.0'
          force 'com.google.android.gms:play-services-basement:16.2.0'
          force 'com.google.firebase:firebase-iid:16.0.0'
          force 'com.google.firebase:firebase-auth:17.0.0'
        }
      }
    }
    

    【讨论】:

    • 这是对我有用的解决方案,你拯救了我的一天。
    • 使用cordova 8对我有用的另一种方法是通过添加github.com/dpa99c/cordova-plugin-androidx然后添加github.com/dpa99c/cordova-plugin-androidx-adapter>来启用AndroidX支持,这是更新依赖项的垫片
    【解决方案3】:

    我遇到了同样的问题,我的解决方案如下:

    1. 转到 gradle.properties 文件

    2. 添加这两行:

      android.useAndroidX=true
      android.enableJetifier=true
      
    3. 重建您的项目。

    就是这样。

    注意:如果您的项目已经显示此android.useAndroidX=true,那么只需添加android.enableJetifier=true 并重建您的项目。

    【讨论】:

      【解决方案4】:

      对我来说,只需安装插件“cordova-plugin-androidx”和“cordova-plugin-androidx-adapter”就解决了这个问题:

      $ ionic cordova plugin add cordova-plugin-androidx
      $ ionic cordova plugin add cordova-plugin-androidx-adapter
      

      【讨论】:

        【解决方案5】:

        我在使用 Android Studio 功能迁移到 Androidx 时遇到了这个问题,但第一次迁移没有成功,所以每次我尝试编译时都遇到了这个问题。

        为了解决这个问题,我做了以下事情:

        [1] Comment all androidx dependencies in the app bundle.gradle file
        [2] Try the Migrate to Androidx. You can see this link in Refactor -> Migrate to Androidx. If the migration was successful, then
        [3] Uncomment all androidx dependencies in the app bundle.gradle file
        

        您可以再次清理并构建您的项目,希望这个错误应该消失。

        【讨论】:

          【解决方案6】:

          我认为您在gradle.properties 中多次保留相同的标签,如下所示

              org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
              org.gradle.jvmargs=-Xmx4608m
          

          【讨论】:

            【解决方案7】:

            只需将以下行添加到您的 gradle.properties 文件中:

            android.useAndroidX=true
            android.enableJetifier=true
            

            注意检查,不要重复任何已经存在的行(并确保存在true)。


            详情

            如果您想在新项目中使用androidx-namespaced 库,您需要将编译 SDK 设置为 Android 9.0(API 级别 28)或更高版本,并将上述两个 Android Gradle 插件标志设置为 true .

            android.useAndroidX:当此标志设置为true 时,Android 插件使用适当的 AndroidX 库而不是支持库。如果未指定,则默认为false

            android.enableJetifier:当此标志设置为true 时,Android 插件会自动迁移现有的第三方库以通过重写其二进制文件来使用 AndroidX 依赖项。如果不指定,则默认为false

            【讨论】:

              【解决方案8】:

              就我而言,我在应用级别 build.gradle 文件的依赖项部分下删除了此实现 -

              implementation 'com.google.android.gms:play-services-ads:19.2.0'

              删除或注释掉!!

              【讨论】:

                【解决方案9】:

                在我的 Ionic 项目中,我需要删除该行

                cordova.system.library.19=com.google.android.gms:play-services-analytics:11.0.1
                

                从我的 /platforms/android/project.properties 获取构建

                【讨论】:

                  【解决方案10】:

                  我有同样的问题,但我解决了它如下。 打开安卓工作室> 文件 > 使缓存无效/重新启动...

                  【讨论】:

                  • 您可以解释此解决方案如何/为何解决了 OP 的问题。我是审稿人。由于您是一个相对较新的贡献者,StackOverflow 要求进行审查。您的回答表示赞赏和帮助。此评论旨在帮助您将一个好的答案变成一个优秀的答案。
                  猜你喜欢
                  • 2022-10-04
                  • 1970-01-01
                  • 2021-11-30
                  • 2021-09-27
                  • 2022-10-05
                  • 1970-01-01
                  • 2019-04-14
                  • 2016-04-18
                  • 2019-08-25
                  相关资源
                  最近更新 更多