Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failing with NoSuchMethodError: ...VariantManager.getVariantScopes()Ljava/util/List when using Android Gradle Plugin 4.1.0 #131

Open
oakkitten opened this issue Nov 4, 2020 · 10 comments

Comments

@oakkitten
Copy link

Upon applying plugin, I'm getting the following error when building:

> gradlew --stacktrace

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
   > com.android.build.gradle.internal.VariantManager.getVariantScopes()Ljava/util/List;
   > com.android.build.gradle.internal.VariantManager.getVariantScopes()Ljava/util/List;

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app'.
        at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:75)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:68)
        ...
Caused by: org.gradle.internal.event.ListenerNotificationException: Failed to notify project evaluation listener.
        at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:86)
        at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:346)
        ...
Cause 1: java.lang.NoSuchMethodError: com.android.build.gradle.internal.VariantManager.getVariantScopes()Ljava/util/List;
        at com.archinamon.utils.VariantUtilsKt.getVariantScopes(VariantUtils.kt:105)
        at com.archinamon.utils.VariantUtilsKt.getVariantDataList(VariantUtils.kt:101)
        at com.archinamon.plugin.PluginSetupKt.prepareVariant(PluginSetup.kt:53)
        at com.archinamon.plugin.PluginSetupKt.access$prepareVariant(PluginSetup.kt:1)
        ...
Cause 2: java.lang.NoSuchMethodError: com.android.build.gradle.internal.VariantManager.getVariantScopes()Ljava/util/List;
        at com.archinamon.utils.VariantUtilsKt.getVariantScopes(VariantUtils.kt:105)
        at com.archinamon.utils.VariantUtilsKt.getVariantDataList(VariantUtils.kt:101)
        at com.archinamon.api.transform.AspectJTransform$prepareProject$1.execute(AspectJTransform.kt:37)
        at com.archinamon.api.transform.AspectJTransform$prepareProject$1.execute(AspectJTransform.kt:23)
        ...

Windows 10; Gradle 6.3..6.7; Android Gradle Plugin 4.1.0. AGP 4.0.+ works.

@jiechic
Copy link

jiechic commented Nov 6, 2020

@Archinamon when will publish Android-Gradle-Aspectj:4.3.0 for fix AGP 4.1.0 bug?you merge PR #128 but isn't published

@akaita
Copy link

akaita commented Nov 25, 2020

I couldn't wait more for a version compatible with AGP4.1 so I ended up compiling the latest code and sending it to JCenter.
In case it's helpful to others: implementation 'com.akaita.android:android-gradle-aspectj:4.3.0'

@akaita
Copy link

akaita commented Dec 3, 2020

The official 4.3.0 was just released. Please hit that one https://bintray.com/archinamon/maven/android-gradle-aspectj/4.3.0

@cyangibm
Copy link

cyangibm commented Jan 8, 2021

@Archinamon when will publish Android-Gradle-Aspectj:4.3.0 for fix AGP 4.1.0 bug?you merge PR #128 but isn't published

Got stuck using AGP 4.0.0 due to this issue, please help!

@cyangibm
Copy link

@Archinamon when will publish Android-Gradle-Aspectj:4.3.0 for fix AGP 4.1.0 bug?you merge PR #128 but isn't published

Any idea when it could get merged? It's been a blocker and my project couldn't use 4.3.0 at all. Thanks!

@jdvp
Copy link

jdvp commented Jan 19, 2021

@cyangibm For reference, that PR is merged in 4.3.0

@cyangibm
Copy link

Hmm..When I try to run my app using 4.3.0, the app would crash with class resolution error, please see below:

AspectJ Plugin 4.3.0
Gradle 6.5.1/6.1.1
AGP 4.1.1

2021-01-19 15:17:06.608 10519-10519/com.cxa E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.cxa, PID: 10519
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:336)
at androidx.appcompat.app.AppCompatDelegateImpl.(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:7893)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3295)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3485)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2045)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7478)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.R$drawable" on path: DexPathList[[zip file "/data/app/~~GyLFl18w-_vYxzan_N4p7Q==/com.cxa-YdwwJY1W7Bugh6V0o9WuuA==/base.apk"],nativeLibraryDirectories=[/data/app/~~GyLFl18w-_vYxzan_N4p7Q==/com.cxa-YdwwJY1W7Bugh6V0o9WuuA==/lib/x86, /system/lib, /system_ext/lib, /product/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
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:336) 
at androidx.appcompat.app.AppCompatDelegateImpl.(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:7893) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3295) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3485) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
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:2045) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:223) 
at android.app.ActivityThread.main(ActivityThread.java:7478) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941) 

@jdvp
Copy link

jdvp commented Jan 19, 2021

@cyangibm ah yes, I actually had the exact same problem. That's actually a separate issue (#108) caused by a fix for #122 . I had commented on #122 mentioning that it had broken it but never heard back from the contributor that had made the change.

Personally, I decided to switch aspect plugins for my own projects as the resolution of issues 108 and 122 seem to be incompatible and IDK if someone will be able to figure it all out. However, if you are using more advanced features from this plugin, I don't know if switching plugins would work for you.

@cyangibm
Copy link

I couldn't wait more for a version compatible with AGP4.1 so I ended up compiling the latest code and sending it to JCenter.
In case it's helpful to others: implementation 'com.akaita.android:android-gradle-aspectj:4.3.0'

Hello,

I tried your plugin link, however, also getting below crash when using AGP 4.1.1:

2021-01-20 10:50:37.686 5635-5635/com.cxa E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.cxa, PID: 5635
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:336)
at androidx.appcompat.app.AppCompatDelegateImpl.(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:7893)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3295)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3485)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2045)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7478)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.R$drawable" on path: DexPathList[[zip file "/data/app/~~xCH6ru24VPAVPhLSrJwxtA==/com.cxa-mmJx_VjiFSMoSKJ3Zd0Lgg==/base.apk"],nativeLibraryDirectories=[/data/app/~~xCH6ru24VPAVPhLSrJwxtA==/com.cxa-mmJx_VjiFSMoSKJ3Zd0Lgg==/lib/x86, /system/lib, /system_ext/lib, /product/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
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:336) 
at androidx.appcompat.app.AppCompatDelegateImpl.(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:7893) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3295) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3485) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
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:2045) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:223) 
at android.app.ActivityThread.main(ActivityThread.java:7478) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941) 

@oakkitten
Copy link
Author

in case someone needs this, here's a manual way of weaving aspectj on android. you will have to tweak the Transform a bit to suite your needs but it's gradle kotlin dsl, only depends on aspectjtools & aspectjrt, and even deals with some nasty windows issue of gradle not releasing some file locks

https://stackoverflow.com/a/64673644/1449683

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants