Skip to content

java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation #406

Closed
@Andoctorey

Description

@Andoctorey

Receive crashes on production users:

Fatal Exception: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
       at java.lang.reflect.Method.getAnnotation(Method.java)
       at java.lang.reflect.Method.getAnnotation(Method.java:266)
       at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingReflectionInSingleClass(Unknown Source:165)
       at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingInfo(Unknown Source:88)
       at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(Unknown Source:64)
       at org.greenrobot.eventbus.EventBus.register(Unknown Source:136)
       at com.*****.BaseActivity.onResume(Unknown Source:73)
       at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
       at android.app.Activity.performResume(Activity.java:5364)
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2924)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3042)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2337)
       at android.app.ActivityThread.access$800(ActivityThread.java:184)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5281)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
       at dalvik.system.NativeStart.main(NativeStart.java)

Code:

 @Override
    protected void onResume() {
        super.onResume();
            if (!EventBus.getDefault().isRegistered(this)) {
                EventBus.getDefault().register(this); //crash is here
            }
    }

Dexguard:

-keepattributes JavascriptInterface
-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

Eventbus version - 3.0.0
For now have only 5 crashes, 3 users. Android: 4.1.2, 4.4.2. Devices: Sony Xperia GX, Kyocera TORQUE G01, Fujitsu F-01F

Activity

greenrobot-team

greenrobot-team commented on Mar 14, 2017

@greenrobot-team
Collaborator

java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation indicates that the class (one of your classes that contains a @Subscribed annotation) in question seems to be different in your final APK (specifically the dex file).

This may be related to multi-dex or if you somehow included these classes twice as a dependency.
-ut

Andoctorey

Andoctorey commented on Mar 22, 2017

@Andoctorey
Author

Thanks. Probably found problem. We rewrote EventBusBuilder and EventBus classes, added some logs. EventBusBuilder constructor is not public, se we put custom classes in org.greenrobot.eventbus package. Maybe it caused problem.

greenrobot-team

greenrobot-team commented on Mar 27, 2017

@greenrobot-team
Collaborator

Alright, closing this then. -ut

removed their assignment
on Apr 11, 2017
BornLotus

BornLotus commented on Jun 8, 2018

@BornLotus

Now, I faced the same problem as above,can you tell me why and what I should do with it? thanks a lot

DeanKersting

DeanKersting commented on Apr 4, 2019

@DeanKersting

Now, I faced the same problem as above,can you tell me why and what I should do with it? thanks a lot

This is usually happened when call Eventbus.register(subscribe),subscribe Class is belonged to a different dex which is not THE dex Eventbus class belonged to!So you can add Eventbus ref(such as Eventbus.class.getName()) in your subscribe class to prevent it being marked as 'class_preverified' by Dalvik VM,ART VM don't have this problem),it will solve ur problem!

liuyan82

liuyan82 commented on Oct 21, 2019

@liuyan82

Now, I faced the same problem as above,can you tell me why and what I should do with it? thanks a lot

This is usually happened when call Eventbus.register(subscribe),subscribe Class is belonged to a different dex which is not THE dex Eventbus class belonged to!So you can add Eventbus ref(such as Eventbus.class.getName()) in your subscribe class to prevent it being marked as 'class_preverified' by Dalvik VM,ART VM don't have this problem),it will solve ur problem!

Thanks. Saved my day.

juanlabrador

juanlabrador commented on Jan 28, 2020

@juanlabrador

@liuyan82 please you can show me how fix that, please!

juanlabrador

juanlabrador commented on Feb 6, 2020

@juanlabrador

It happens when Dexguard is active, How I can add Eventbus ref in subscribe class?

soochun-deali

soochun-deali commented on Mar 14, 2020

@soochun-deali

same here with after applying dexguard

soochun-deali

soochun-deali commented on Mar 19, 2020

@soochun-deali

fix with below rule added

dexguard version : 8.6.06
eventbus version : 3.2.0

-keepnames class org.greenrobot.eventbus.**
-keep class org.greenrobot.eventbus.** { *; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @DeanKersting@liuyan82@juanlabrador@Andoctorey@greenrobot-team

        Issue actions

          java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation · Issue #406 · greenrobot/EventBus