androidandroid-studioproguardandroid-r8linkageerror

LinkageError: Method onCreate overrides final method


Generate Signed App APK used to work flawlessly for an app of mine until... I upgraded Android Studio to 2024.1.1.

It still builds and runs perfectly when generating debug APK. However, when I attempt to generate a release APK, it builds successfully, but when the app is launched on the smartphone, it crashes immediately with this FATAL EXCEPTION:

 java.lang.LinkageError:
 Method void com.me.koalawoes.MyAppActivity.onCreate(android.os.Bundle)
 overrides final method in class Lcom/me/mylib/core/MyActivity;
 (declaration of 'com.me.koalawoes.MyAppActivity'
  appears in /data/app/~~sHPI9ai93DWU6FOp_edr9A==/com.me.koalawoes-8LbG6dXPeAvMUDEvK-x8jQ==/base.apk)

But...MyActivity's onCreate is not declared final at all:

    @Override
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);

What could I be missing?


Solution

  • Here is how I solved the issue:

    In the proguard.cfg of my library (where com/me/mylib/core/MyActivity is), I added the following:

    -keepnames class com.me.mylib.core.MyActivity {
        public void onCreate(android.os.Bundle);
    }
    

    I still wonder what in my upgrade process (without changing a single line of code) made Generate Signed App APK rely on this -keepnames requirement for onCreate(...). It used to work without this.

    At this point, I can only suspect the update from AGP version 8.4 to AGP version 8.5 which was prompted by the upgrade to AS 2024.1.1. R8 is known to change with AGP, as in the android.enableR8.fullMode=false case when migrating from AGP version 7.0.

    Also, I couldn't find anything related in Android Gradle plugin 8.5 release notes.