android-gradle-aspectj icon indicating copy to clipboard operation
android-gradle-aspectj copied to clipboard

When using com.archinamon.aspectj-ext and includeJar, the type xxx is defined multiple times

Open averyzhong opened this issue 5 years ago • 7 comments

com.archinamon.aspectj-ext

aspectj { includeJar 'retrofit2' }

Task :app:mergeProjectDexDebug FAILED AGPBI: {"kind":"error","text":"Type retrofit2.CompletableFutureCallAdapterFactory$ResponseCallAdapter is defined multiple times: /Users/avery/AndroidStudioProjects/NewsPlus/app/build/intermediates/mixed_scope_dex_archive/debug/out/cbf7c823e7225e02a34d087be63f58c4e3f372e4b663235e195d08fd9398358c_2.jar:classes.dex, /Users/avery/AndroidStudioProjects/NewsPlus/app/build/intermediates/mixed_scope_dex_archive/debug/out/b6d20cdf8a2862d83190fc0b72c48af7169626e3e784971edbcc1c3ffa23e7c8_2.jar:classes.dex","sources":[{"file":"/Users/avery/AndroidStudioProjects/NewsPlus/app/build/intermediates/mixed_scope_dex_archive/debug/out/cbf7c823e7225e02a34d087be63f58c4e3f372e4b663235e195d08fd9398358c_2.jar"}],"tool":"D8"} com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: Type retrofit2.CompletableFutureCallAdapterFactory$ResponseCallAdapter is defined multiple times: /Users/avery/AndroidStudioProjects/NewsPlus/app/build/intermediates/mixed_scope_dex_archive/debug/out/cbf7c823e7225e02a34d087be63f58c4e3f372e4b663235e195d08fd9398358c_2.jar:classes.dex, /Users/avery/AndroidStudioProjects/NewsPlus/app/build/intermediates/mixed_scope_dex_archive/debug/out/b6d20cdf8a2862d83190fc0b72c48af7169626e3e784971edbcc1c3ffa23e7c8_2.jar:classes.dex Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:132) at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:119) at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:102) at com.android.build.gradle.internal.tasks.DexMergingTaskRunnable.run(DexMergingTask.kt:441) at com.android.build.gradle.internal.tasks.Workers$ActionFacade.run(Workers.kt:242) at org.gradle.workers.internal.AdapterWorkAction.execute(AdapterWorkAction.java:50) at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:50) at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:63) at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:59) at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:98) at org.gradle.workers.internal.NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:59) at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44) at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41) at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416) at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406) at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165) at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250) at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158) at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102) at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36) at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41) at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:53) at org.gradle.workers.internal.DefaultWorkerExecutor.lambda$submitWork$2(DefaultWorkerExecutor.java:200) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215) at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164) at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64) at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56) at java.lang.Thread.run(Thread.java:748) Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete at com.android.tools.r8.utils.W.a(:87) at com.android.tools.r8.D8.run(:11) at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:117) ... 33 more Caused by: com.android.tools.r8.utils.b: Error: /Users/avery/AndroidStudioProjects/NewsPlus/app/build/intermediates/mixed_scope_dex_archive/debug/out/cbf7c823e7225e02a34d087be63f58c4e3f372e4b663235e195d08fd9398358c_2.jar:classes.dex, Type retrofit2.CompletableFutureCallAdapterFactory$ResponseCallAdapter is defined multiple times: /Users/avery/AndroidStudioProjects/NewsPlus/app/build/intermediates/mixed_scope_dex_archive/debug/out/cbf7c823e7225e02a34d087be63f58c4e3f372e4b663235e195d08fd9398358c_2.jar:classes.dex, /Users/avery/AndroidStudioProjects/NewsPlus/app/build/intermediates/mixed_scope_dex_archive/debug/out/b6d20cdf8a2862d83190fc0b72c48af7169626e3e784971edbcc1c3ffa23e7c8_2.jar:classes.dex at Version.fakeStackEntry(Version_2.0.74.java:0) at com.android.tools.r8.utils.M0.a(:21) at com.android.tools.r8.utils.L0.b(:7) at com.android.tools.r8.utils.L0.a(:27) at com.android.tools.r8.utils.L0.a(:10) at java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:1990) at com.android.tools.r8.utils.L0.a(:6) at com.android.tools.r8.graph.D0$c.f(:3) at com.android.tools.r8.dex.a.a(:83) at com.android.tools.r8.dex.a.a(:10) at com.android.tools.r8.D8.d(:6) at com.android.tools.r8.D8.b(:1) at com.android.tools.r8.utils.W.a(:30) ... 35 more

:app:mergeProjectDexDebug spend 560ms Task spend time: 147ms :app:processDebugManifest 64ms :app:mergeDebugResources 1097ms :app:processDebugResources 1952ms :app:kaptGenerateStubsDebugKotlin 121ms :app:javaPreCompileDebug 645ms :app:mergeDebugNativeLibs 977ms :app:kaptDebugKotlin 4456ms :app:compileDebugKotlin 148ms :app:compileDebugJavaWithJavac 1140ms :app:transformClassesWithAspectjForDebug 8485ms :app:dexBuilderDebug 103ms :app:mergeDebugJavaResource 560ms :app:mergeProjectDexDebug

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:mergeProjectDexDebug'.

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: Type retrofit2.CompletableFutureCallAdapterFactory$ResponseCallAdapter is defined multiple times: /Users/avery/AndroidStudioProjects/NewsPlus/app/build/intermediates/mixed_scope_dex_archive/debug/out/cbf7c823e7225e02a34d087be63f58c4e3f372e4b663235e195d08fd9398358c_2.jar:classes.dex, /Users/avery/AndroidStudioProjects/NewsPlus/app/build/intermediates/mixed_scope_dex_archive/debug/out/b6d20cdf8a2862d83190fc0b72c48af7169626e3e784971edbcc1c3ffa23e7c8_2.jar:classes.dex Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.

  • 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 20s 24 actionable tasks: 24 executed

averyzhong avatar Jul 03 '20 12:07 averyzhong

Hi!

Could you provide please more info:

  • what version of android gradle plugin do you use?
  • what version of aspectj plugin do you use?
  • maybe a minimal reproduceable project you can share?

Archinamon avatar Jul 14 '20 17:07 Archinamon

Hi!

gradle plugin & aspectJ plugin version:

classpath "com.android.tools.build:gradle:4.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.archinamon:android-gradle-aspectj:4.2.1'

android version:

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.foo.aop"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

averyzhong avatar Jul 30 '20 03:07 averyzhong

This is also happening for me. It seems to be linked to having multiple variants and using includeJars - possibly the jars are being included for each variant?

superafroman avatar Aug 12 '20 06:08 superafroman

Note, after a little more investigation the additional variants aren't the issue. I've opened a PR that includes a failing test showing the issue ☝️

I'm happy to fix this, but any pointers would be helpful - from what I can tell the processed classes are being included along with the original dependency when the multi dexing is being done?

superafroman avatar Aug 14 '20 13:08 superafroman

I have pinpointed the problem as the addition of copying the include jars that resolves #108 and updated my PR to revert this change and add a test for both this issue and 108.

(@Archinamon please review when you can)

superafroman avatar Sep 05 '20 11:09 superafroman

@superafroman Hi! Sorry for being offline for so long. I've took a look at your code. It seems have to work, but I'll test in my production project first before commiting public packages.

Thank's for your contribution!

Archinamon avatar Oct 18 '20 13:10 Archinamon

@superafroman This change, which was released in the 4.3.0 version of the plugin today, seems to have re-introduced issue #108

AGP v4.1.0 and android-gradle-aspectj v3.4.0

This branch on my sample project is exhibiting the issue for reference: https://github.com/jdvp/AndroidAspectExample/tree/feature/agp-4.1.0

Stacktrace if interested:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: me.jdvp.androidaspectexample.debug, PID: 5225
    java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/appcompat/R$drawable;
        at androidx.appcompat.widget.AppCompatDrawableManager$1.<init>(AppCompatDrawableManager.java:63)
        at androidx.appcompat.widget.AppCompatDrawableManager.preload(AppCompatDrawableManager.java:57)
        at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:336)
        at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:286)
        at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:230)
        at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:554)
        at androidx.appcompat.app.AppCompatActivity.attachBaseContext(AppCompatActivity.java:107)
        at android.app.Activity.attach(Activity.java:7899)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3401)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.R$drawable" on path: DexPathList[[zip file "/data/app/~~oR4sHx3yVPaRSB1KduWpUQ==/me.jdvp.androidaspectexample.debug-I1VyhpPc3vfvewIIUTYhow==/base.apk"],nativeLibraryDirectories=[/data/app/~~oR4sHx3yVPaRSB1KduWpUQ==/me.jdvp.androidaspectexample.debug-I1VyhpPc3vfvewIIUTYhow==/lib/x86, /system/lib, /system_ext/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)

jdvp avatar Dec 03 '20 22:12 jdvp