Archinamon / android-gradle-aspectj

gradle plug-in adding supports of AspectJ into Android project
Apache License 2.0
363 stars 58 forks source link

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/appcompat/R$drawable; #108

Closed rahuljain88 closed 4 years ago

rahuljain88 commented 4 years ago

App getting crash with below logs , Our app using Android Gradle version 3.6+ , archinamon version 4.1.0 and distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-all.zip.

2020-04-06 10:09:27.677 20473-20473/com.example.smapireferenceapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.smapireferenceapp, PID: 20473 java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/appcompat/R$drawable; at androidx.appcompat.widget.AppCompatDrawableManager$1.(AppCompatDrawableManager.java:63) at androidx.appcompat.widget.AppCompatDrawableManager.preload(AppCompatDrawableManager.java:57) at androidx.appcompat.app.AppCompatDelegateImpl.(AppCompatDelegateImpl.java:328) at androidx.appcompat.app.AppCompatDelegateImpl.(AppCompatDelegateImpl.java:278) at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:221) at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:543) at androidx.appcompat.app.AppCompatActivity.attachBaseContext(AppCompatActivity.java:98) at android.app.Activity.attach(Activity.java:7051) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2873) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.R$drawable" on path: DexPathList[[zip file "/data/app/com.example.smapireferenceapp-7ftx-1zg3Oz8UpM7sw_eww==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.smapireferenceapp-7ftx-1zg3Oz8UpM7sw_eww==/lib/x86, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at androidx.appcompat.widget.AppCompatDrawableManager$1.(AppCompatDrawableManager.java:63)  at androidx.appcompat.widget.AppCompatDrawableManager.preload(AppCompatDrawableManager.java:57)  at androidx.appcompat.app.AppCompatDelegateImpl.(AppCompatDelegateImpl.java:328)  at androidx.appcompat.app.AppCompatDelegateImpl.(AppCompatDelegateImpl.java:278)  at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:221)  at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:543)  at androidx.appcompat.app.AppCompatActivity.attachBaseContext(AppCompatActivity.java:98)  at android.app.Activity.attach(Activity.java:7051)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2873)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:193)  at android.app.ActivityThread.main(ActivityThread.java:6669)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)  2020-04-06 10:09:27.719 20473-20473/com.example.smapireferenceapp I/Process: Sending signal. PID: 20473 SIG: 9

topvas7450 commented 4 years ago

I got the same problem.

Looks like same issue use Transform implementation https://github.com/objectbox/objectbox-java/issues/817

jdvp commented 4 years ago

Anybody manage to get around this issue? I am also having this problem with a basically empty project. Gradle 6.0.1, Android Gradle 3.6.2, android-gradle-aspectj 4.1.0

kvolkers commented 4 years ago

I'm experiencing something similar on Gradle plugin 3.6.3 icw AspectJ 4.1.0.

fine:

"com.android.tools.build:gradle:3.6.3"
"com.squareup.leakcanary:leakcanary-android:2.2"

fine:

"com.android.tools.build:gradle:3.5.3"
"com.archinamon:android-gradle-aspectj:4.0.1"
"com.squareup.leakcanary:leakcanary-android:2.2"

crash:

"com.android.tools.build:gradle:3.6.3"
"com.archinamon:android-gradle-aspectj:4.1.0"
"com.squareup.leakcanary:leakcanary-android:2.2"

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/leakcanary/core/R$bool;

jdvp commented 4 years ago

@topvas7450 I looked at the sample fix given in the linked issue and tried it on a local build of this repo by updating the following method:

private fun includeCompiledAspects(transformInvocation: TransformInvocation, outputDir: File) {
        val compiledAj = project.file("${project.buildDir}/$LANG_AJ/${transformInvocation.context.variantName}")
        if (compiledAj.exists()) {
            aspectJWeaver.aspectPath shl compiledAj

            //copy compiled .class files to output directory
            FileUtil.copyDir(compiledAj, outputDir)
        }

        transformInvocation.inputs.forEach { transformInput ->
            // Ensure JARs are copied as well:
            transformInput.jarInputs.forEach {
                it.file.copyTo(
                        transformInvocation.outputProvider.getContentLocation(it.name, inputTypes, scopes, Format.JAR),
                        overwrite = true
                )
            }
        }
    }

basically just copying the sample fix into the bottom of the includeCompiledAspects function. The plugin seems to work with that fix applied but I don't know enough about how the plugin works overall to be comfortable making a PR with this kind of change as IDK what kind of side effect it would have.

Hopefully the above snippet can give maintainers an idea of where to look though?

eyedol commented 4 years ago

I'm affirming @jdvp fix worked.

dansaka commented 4 years ago

When do you merge this

Archinamon commented 4 years ago

Releases here: 4.2.1 But make first upgrade to AGP 4.0.0 starting this release.

Thanks for your contribution a lot!

rahuljain88 commented 4 years ago

@Archinamon , any update if gradle version is 3.6+ and com.archinamon:android-gradle-aspectj:4.1.0" .

Still app is crashing with above error.

jdvp commented 4 years ago

@rahuljain88 since this fix is only provided in library version 4.2.1, which is only compatible with AGP 4.0.0, you would need to update your gradle to 4.0.0 and the library to 4.2.1 I believe

cyangibm commented 3 years ago

@topvas7450 I looked at the sample fix given in the linked issue and tried it on a local build of this repo by updating the following method:

private fun includeCompiledAspects(transformInvocation: TransformInvocation, outputDir: File) {
        val compiledAj = project.file("${project.buildDir}/$LANG_AJ/${transformInvocation.context.variantName}")
        if (compiledAj.exists()) {
            aspectJWeaver.aspectPath shl compiledAj

            //copy compiled .class files to output directory
            FileUtil.copyDir(compiledAj, outputDir)
        }

        transformInvocation.inputs.forEach { transformInput ->
            // Ensure JARs are copied as well:
            transformInput.jarInputs.forEach {
                it.file.copyTo(
                        transformInvocation.outputProvider.getContentLocation(it.name, inputTypes, scopes, Format.JAR),
                        overwrite = true
                )
            }
        }
    }

basically just copying the sample fix into the bottom of the includeCompiledAspects function. The plugin seems to work with that fix applied but I don't know enough about how the plugin works overall to be comfortable making a PR with this kind of change as IDK what kind of side effect it would have.

Hopefully the above snippet can give maintainers an idea of where to look though?

Hi,

Could you please elaborate how to apply the workaround? I'm a little confused on where to put your code snippet, thanks!!

jdvp commented 3 years ago

@cyangibm As shown in this PR: https://github.com/Archinamon/android-gradle-aspectj/pull/113/files

You'd need to apply the change inside this library itself in the AspectJTransform.kt file. However, doing so apparently leads to issue 122

cyangibm commented 3 years ago

I'm affirming @jdvp fix worked.

Thank you for your reply! The ticket is closed, but looks like the issue is still not fixed as part of the plugin. Should I open a new issue instead? This is a blocker, the app crashes after running with the error.

jdvp commented 3 years ago

@cyangibm Yeah it was in the 4.2.1 release and then removed in the 4.3.0 release since this fix had broken something else. I'd recommend raising another issue since I'm not sure how we can re-open this one