Search code examples
androidproguardobfuscationandroid-r8

Android R8(Proguard) parameter name changed (i don't want change my parameter name)


i use agp(android gradle plugin) 7.0.4 after run proguard -> interface parameter name changed (com.android.tools.build:gradle:4.2.2 version not changed interface parameter names)

in Gradle 4.2.2

public interface ITicketBoxCount {
    public abstract fun callback(condition: kotlin.Int): kotlin.Unit
}

in Gradle 7.0.4

public interface ITicketBoxCount {
    void callback(int var1);
}

use same "proguard_rules.txt"

-keep interface myinterfaceclass.** { *; }

i already try to "-keepparameternames" -> class parameter names not changed but interface parameter names changed

i don't want to change my interface parameter names please help me


additional

I make a ".aar"(sdk) file

define interface "ITicketBoxCount" -> make aar -> build time run r8 -> decompile aar -> ITicketBoxCount Interface parameter names all obfuscation


Solution

  • I found a reason in R8 issue tracker

    It seems like you are using kotlin version 1.6. The R8 version that is bundled with AGP 7.0 was released prior to 1.6 being released and cannot read the metadata. As a result it will simply discard it since it cannot do anything with it. You should also get these info messages if compiling through the command line:

    Info: Unexpected error while reading com.noimply.mymodule.ITicketCount's kotlin.Metadata: null
    Info: Unexpected error while reading com.noimply.mymodule.IUpdateNotification's kotlin.Metadata: null
    Info: Unexpected error while reading com.noimply.mymodule.MyModuleSDK's kotlin.Metadata: null
    Info: Unexpected error while reading com.noimply.mymodule.view.MainActivity's kotlin.Metadata: null
    Info: Unexpected error while reading com.noimply.mymodule.ILoginCallback's kotlin.Metadata: null
    Info: Unexpected error while reading com.noimply.mymodule.ITicketBoxCount's kotlin.Metadata: null
    

    You will have to use version 3.0.77 or upgrade or R8 version 3.1.X which are currenty in release candidate. You can set a specific version by adding the following to your top-level build.gradle:

    pluginManagement {
        buildscript {
            repositories {
                mavenCentral()
                maven {
                    url = uri("https://storage.googleapis.com/r8-releases/raw")
                }
            }
            dependencies {
                classpath("com.android.tools:r8:3.0.77")
                classpath('com.google.guava:guava:30.1.1-jre')  // <-- THIS IS REQUIRED UNTIL R8 3.2.4-dev
            }
        }
    }
    

    If you are wondering why it would work in AGP 4.2 it is because that version of R8 has no modeling of kotlin metadata and just pass it through.