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

Release build crash using 2.31-alpha #2291

Closed
p-lr opened this issue Jan 18, 2021 · 19 comments
Closed

Release build crash using 2.31-alpha #2291

p-lr opened this issue Jan 18, 2021 · 19 comments

Comments

@p-lr
Copy link

p-lr commented Jan 18, 2021

Hi,

My release version runs just fine with 2.30.1-alpha. However, with the new version, the release version fails (at app startup) with this stacktrace:

java.lang.IllegalAccessError: Interface e.b.b.c.c.a$a implemented by class com.peterlaurence.trekme.TrekMeApp_HiltComponents$ActivityC is inaccessible (declaration of 'com.peterlaurence.trekme.TrekMeApp_HiltComponents$ActivityC' appears in base.apk)
        at com.peterlaurence.trekme.DaggerTrekMeApp_HiltComponents_SingletonC$ActivityRetainedCImpl.activityComponentBuilder(Unknown Source:0)
        at e.b.b.c.d.a.a(Unknown Source:79)
        at e.b.b.c.d.a.generatedComponent(Unknown Source:11)
        at com.peterlaurence.trekme.Hilt_MainActivity.generatedComponent(Unknown Source:4)
        at com.peterlaurence.trekme.Hilt_MainActivity.inject(Unknown Source:7)
        at com.peterlaurence.trekme.Hilt_MainActivity.onCreate(Unknown Source:0)
        at com.peterlaurence.trekme.MainActivity.onCreate(Unknown Source:0)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Activity.performCreate(Activity.java:7984)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3404)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
        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:7660)
        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)

Is there some proguard rule I should add?

@bcorso
Copy link

bcorso commented Jan 19, 2021

Hmm, I'm not really sure what in Hilt could have caused this.

Is there some proguard rule I should add?

Does it only happen in proguarded builds?

Any idea what the underlying cause of this is (e.g. is it that e.b.b.c.c.a$a is completely missing from the dex, or something else)?

@p-lr
Copy link
Author

p-lr commented Jan 19, 2021

I wasn't clear. The release build finishes without error. It is when I start the app (the release version) that I get the crash.
The debug version, which isn't affected by proguard, runs fine.
It looks like this e.b.b.c.c.a$a is missing from the dex. It appears that it's coming from obfuscation.

@yshrsmz
Copy link

yshrsmz commented Jan 19, 2021

@peterLaurence enableExperimentalClasspathAggregation is true in your gradle file? I think I saw the same error when I enabled this flag.
I'm wondering if the root cause is the same as #2288

@hijamoya
Copy link

Same issue here.

@p-lr
Copy link
Author

p-lr commented Jan 20, 2021

@yshrsmz No, I don't have enableExperimentalClasspathAggregation set. It's not the build that fails. The app crashes at startup, while reverting to 2.30.1-alpha fixed the issue. I changed the OP to reflect that.
BTW, I also tested with 2.31.1-alpha. Still the same stacktrace.

@satoshun
Copy link

I got a same issue when release build.

Added proguard rules and output logs.

Process: my.app.dev, PID: 4079
java.lang.IllegalAccessError: Interface dagger.hilt.android.internal.lifecycle.DefaultViewModelFactories$ActivityEntryPoint implemented by class my.app.App_HiltComponents$ActivityC is inaccessible (declaration of 'my.app.App_HiltComponents$ActivityC' appears in /data/app/~~FM-gpW7f2V-7shmQqvIcog==/my.app.dev-I_VxkFwsLMsITVbsHfv9JQ==/base.apk)
    at my.app.DaggerApp_HiltComponents_SingletonC$ActivityRetainedCImpl.a(DaggerApp_HiltComponents_SingletonC.java:3652)
    at dagger.hilt.android.internal.managers.ActivityComponentManager.a(ActivityComponentManager.java:88)
    at dagger.hilt.android.internal.managers.ActivityComponentManager.I(ActivityComponentManager.java:66)
    ...

@bcorso
Copy link

bcorso commented Jan 20, 2021

@satoshun thanks for the deobfuscated error message, that helps a lot! @danysantiago was able to reproduce this locally and confirm the issue. dagger.hilt.android.internal.lifecycle.DefaultViewModelFactories$ActivityEntryPoint, was recently changed from public to pkg-private which is likely what triggered this issue.

However, I think the real issue is in r8. Hilt allows non-public entry points by generating a public wrapper for the entry point, e.g.

// Hilt generates a public wrapper for PkgPrivateEntryPoint.
public interface HiltWrapper_PkgPrivateEntryPoint extends PkgPrivateEntryPoint {}

// The generated Hilt component extends the public wrapper
@Component(...)
interface HiltComponents_SingletonC extends HiltWrapper_PkgPrivateEntryPoint {}

It sounds like this is a bug in r8 where it is incorrectly removing the wrapper during shrinking/optimization. We should file a bug for r8.

In the meantime, you can try adding a keep rule for all HiltWrapper_* classes to unblock yourself. We should probably also consider pushing another release that includes this keep rule automatically until the bug is fixed.

EDIT: Looks like the keep rule may not be enough... we'll update once/if we've found a general solution.
EDIT2: The keep rule does work (just need to force a rebuild in AndroidStudio since it's not triggered automatically).

@p-lr
Copy link
Author

p-lr commented Jan 21, 2021

@satoshun For my own education, how did you generated a deobfuscated stacktrace? :)

@kenshin171
Copy link

For anyone who wants the workaround, here is what i added to my proguard/r8 file.

-keep class  dagger.hilt.android.internal.modules.HiltWrapper_ActivityModule
-keep class dagger.hilt.android.internal.managers.HiltWrapper_ActivityRetainedComponentManager_LifecycleModule
-keep class dagger.hilt.android.internal.managers.HiltWrapper_ActivityRetainedComponentManager_ActivityRetainedLifecycleEntryPoint
-keep class dagger.hilt.android.internal.managers.HiltWrapper_ActivityRetainedComponentManager_ActivityRetainedComponentBuilderEntryPoint

-keep class dagger.hilt.android.internal.lifecycle.HiltWrapper_DefaultViewModelFactories_ActivityEntryPoint
-keep class dagger.hilt.android.internal.lifecycle.HiltWrapper_DefaultViewModelFactories_ActivityModule
-keep class dagger.hilt.android.internal.lifecycle.HiltWrapper_DefaultViewModelFactories_FragmentEntryPoint

-keep class dagger.hilt.android.internal.lifecycle.HiltWrapper_HiltViewModelFactory_ViewModelModule
-keep class dagger.hilt.android.internal.lifecycle.HiltWrapper_HiltViewModelFactory_ViewModelFactoriesEntryPoint

@satoshun
Copy link

@peterLaurence I use a keepnames proguard rule !

 -keepnames class dagger.**

copybara-service bot pushed a commit that referenced this issue Jan 21, 2021
…ation issues.

This CL is a partial rollback of changes made in CL/351213437 when introducing TestInstallIn. Making these classes pkg-private was mostly just a precaution. Making these public again should be fine since AggeregatedDepsProcessor prevents using TestInstallIn from replacing dagger.hilt modules.

See #2291

RELNOTES=N/A
PiperOrigin-RevId: 352903624
copybara-service bot pushed a commit that referenced this issue Jan 21, 2021
…r8 optimization issues.

This CL is a partial rollback of changes made in CL/351213437 when introducing TestInstallIn. Making these classes pkg-private was mostly just a precaution. Making these public again should be fine since AggeregatedDepsProcessor prevents using TestInstallIn from replacing dagger.hilt modules.

See #2291

RELNOTES=Partially Fixes 2291: Reverts Hilt internal entry point and modules back to public to avoid r8 optimization issues. The full fix on our side (until r8 bug is fixed) will be to ship a proguard config that keeps the HiltWrapper_ classes. This will be done in a future release.
PiperOrigin-RevId: 352903624
copybara-service bot pushed a commit that referenced this issue Jan 21, 2021
…r8 optimization issues.

This CL is a partial rollback of changes made in CL/351213437 when introducing TestInstallIn. Making these classes pkg-private was mostly just a precaution. Making these public again should be fine since AggeregatedDepsProcessor prevents using TestInstallIn from replacing dagger.hilt modules.

See #2291

RELNOTES=Partially Fixes 2291: Reverts Hilt internal entry point and modules back to public to avoid r8 optimization issues. The full fix on our side (until r8 bug is fixed) will be to ship a proguard config that keeps the HiltWrapper_ classes. This will be done in a future release.
PiperOrigin-RevId: 353064986
@Chang-Eric
Copy link
Member

The immediate breakage caused by 2.31 has been reverted and pushed in 2.31.2. I will continue to leave this open though since the general issue still remains.

@FunkyMuse
Copy link

FunkyMuse commented Jan 25, 2021

@peterLaurence I use a keepnames proguard rule !

 -keepnames class dagger.**

Thanks for the quick solution.
You can go even with dagger.hilt.** since it obfuscates only the problematic hilt deps

@ColinAygalincSe
Copy link

Hi, get the same issue. Here is the unscramble stack trace :

 at com.schneiderelectric.configelec.application.DaggerScotApplication_HiltComponents_SingletonC$ActivityRetainedCImpl.activityComponentBuilder(DaggerScotApplication_HiltComponents_SingletonC.java:0)
    at dagger.hilt.android.internal.managers.ActivityComponentManager.createComponent(ActivityComponentManager.java:79)
    at dagger.hilt.android.internal.managers.ActivityComponentManager.generatedComponent(ActivityComponentManager.java:11)
    at com.se.module.wiserhome.ui.activity.Hilt_WiserHomeActivity.generatedComponent(Hilt_WiserHomeActivity.java:4)
    at com.se.module.wiserhome.ui.activity.Hilt_WiserHomeActivity.inject(Hilt_WiserHomeActivity.java:7)
    at com.se.module.wiserhome.ui.activity.Hilt_WiserHomeActivity.onCreate(Hilt_WiserHomeActivity.java:0)
    at com.se.module.wiserhome.ui.activity.WiserHomeActivity.onCreate(WiserHomeActivity.java:0)
    at android.app.Activity.performCreate(Activity.java:7893)
    at android.app.Activity.performCreate(Activity.java:7880)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3286)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3460)
    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:2047)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7590)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

@peterLaurence : check this blogpost to unscramble stack trace : https://segunfamisa.com/posts/analyze-stack-trace-in-android-studio

@bcorso
Copy link

bcorso commented Jan 25, 2021

Hi @ColinAygalincSe,

  1. The stack trace you posted is missing the line with the error -- is it the same as Release build crash using 2.31-alpha #2291 (comment) or are you reporting a new error?

  2. Are you still seeing this error after the update to 2.31.2 (see Release build crash using 2.31-alpha #2291 (comment))?

@ColinAygalincSe
Copy link

ColinAygalincSe commented Jan 25, 2021

@bcorso : it just the unscramble stack trace, hope it helps. Triggered with version 2.31-alpha.
Update to 2.31.2 fix the issue.

@Chang-Eric
Copy link
Member

The underlying issue is https://issuetracker.google.com/178045782 which has been fixed in R8. Since that is done, and the immediate issue introduced by Hilt was fixed in 2.31.2, I'm closing this issue.

@danysantiago
Copy link
Member

@eugene-kirzhanov do you have a repro steps? Are you seeing the same issue as OP? Have you tried adding the obfuscation rules mentioned in #2291 (comment) ? We have not been able to repro this locally after updating the visibility in a2798a8.

@eugene-kirzhanov
Copy link

eugene-kirzhanov commented Apr 8, 2021

@eugene-kirzhanov do you have a repro steps? Are you seeing the same issue as OP? Have you tried adding the obfuscation rules mentioned in #2291 (comment) ? We have not been able to repro this locally after updating the visibility in a2798a8.

Sorry, my mistake - commented in another thread #2502 (but possibly related to this)

@badoualy
Copy link

For anyone hitting this with hilt 1.0.0:

-keep class dagger.hilt.android.internal.** {*;}

did the trick for me

(dagger.hilt.android.internal.lifecycle.HiltViewModelFactory$ActivityCreatorEntryPoint might be enough though)

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