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

Hilt: java.lang.VerifyError: Verifier rejected class on views that use @AndroidEntryPoint #2662

Closed
lukas1 opened this issue Jun 1, 2021 · 0 comments · Fixed by #2680
Closed

Comments

@lukas1
Copy link

lukas1 commented Jun 1, 2021

Version: 2.36

Custom views, that use @AndroidEntryPoint annotation crash in runtime with cryptic error message.

Code of the custom view:

@AndroidEntryPoint
class CustomView2 @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    @AttrRes defStyleAttr: Int = 0,
    @StyleRes defStyleRes: Int = 0
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes) {
    private fun methodCausesProblems(): FrameLayout {
        return FrameLayout(context)
    }
}

Error message:

Process: com.example.hiltviewbug, PID: 25682
    java.lang.VerifyError: Verifier rejected class com.example.hiltviewbug.CustomView2: android.widget.FrameLayout com.example.hiltviewbug.CustomView2.methodCausesProblems() failed to verify: android.widget.FrameLayout com.example.hiltviewbug.CustomView2.methodCausesProblems(): [0x6] 'this' argument 'Uninitialized Reference: android.widget.FrameLayout Allocation PC: 0' not instance of 'Reference: com.example.hiltviewbug.Hilt_CustomView2' (declaration of 'com.example.hiltviewbug.CustomView2' appears in /data/app/com.example.hiltviewbug-Qw27sqf3TVAyEoy9KcNjDQ==/base.apk!classes4.dex)

Also this view crashes with very similar error:

@AndroidEntryPoint
class CustomView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    @AttrRes defStyleAttr: Int = 0,
    @StyleRes defStyleRes: Int = 0
) : LinearLayout(context, attrs, defStyleAttr, defStyleRes) {
    private fun methodCausesProblems(): LinearLayout {
        return LinearLayout(context)
    }
}

The problem seems to be creating LinearLayout within a view that extends LinearLayout, or FrameLayout within a class that extends FrameLayout etc.

I have prepared an example project for you to test it on:
https://github.com/lukas1/HiltViewBug

copybara-service bot pushed a commit that referenced this issue Jun 9, 2021
…ntiations.

The instruction invokespecial is also used to invoke constructors and perform object instantiation. This CL fixes Hilt's transform to not change the owner of such instructions even if the owner is the older superclass since they are instantiating an object that happens to be the of the same type as the 'old' superclass.

Fixes #2662

RELNOTES=Fix an issue in Hilt's bytecode transform that would cause classes to fail validation if they contained an instantiation of an object whose type is the same as the superclass of the @androidentrypoint annotated class.
PiperOrigin-RevId: 378309129
copybara-service bot pushed a commit that referenced this issue Jun 9, 2021
…ntiations.

The instruction invokespecial is also used to invoke constructors and perform object instantiation. This CL fixes Hilt's transform to not change the owner of such instructions even if the owner is the older superclass since they are instantiating an object that happens to be the of the same type as the 'old' superclass.

Fixes #2662

RELNOTES=Fix an issue in Hilt's bytecode transform that would cause classes to fail validation if they contained an instantiation of an object whose type is the same as the superclass of the @androidentrypoint annotated class.
PiperOrigin-RevId: 378309129
copybara-service bot pushed a commit that referenced this issue Jun 9, 2021
…ntiations.

The instruction invokespecial is also used to invoke constructors and perform object instantiation. This CL fixes Hilt's transform to not change the owner of such instructions even if the owner is the older superclass since they are instantiating an object that happens to be the of the same type as the 'old' superclass.

Fixes #2662

RELNOTES=Fix an issue in Hilt's bytecode transform that would cause classes to fail validation if they contained an instantiation of an object whose type is the same as the superclass of the @androidentrypoint annotated class.
PiperOrigin-RevId: 378309129
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants