简体   繁体   中英

@Keep annotation and keep rules are not working for interfaces nested inside classes or other interfaces by enabling Android R8 obfuscation



I am using Android R8 obfuscation in my Android library. After including the AAR file in the application module of the library's client project, I am getting compile time errors for interfaces that are declared inside the class or another interface.

eg one of the public interfaces is MyPublicInterface:

interface InterfaceA {
    fun a()
}

interface InterfaceB {
    fun b()
}

class ClassA {
    interface NestedInterfaceOfA {
        fun nia()
    }
}

interface MyPublicInterface : InterfaceA, InterfaceB, ClassA.NestedInterfaceOfA

The interface MyPublicInterface is used by the application module.

I am getting the below errors while compiling the application module:

"Cannot access ClassA$NestedInterfaceOfA which is a supertype of MyPublicInterface. Please make sure you have the required dependencies in the classpath."
"unresolved supertypes ClassA$NestedInterfaceOfA"

I tried all the below rules:

-keepclasseswithmembers public interface * {
*;
}
-keepclasseswithmembernames public interface * {
*;
}
-keep public interface *$* {
*;
}
-keepclasseswithmembers public interface *$* {
*;
}
-keepclasseswithmembernames public interface *$* {
*;
}
-keepattributes InnerClasses, Signature

I tried by explicitly adding @Keep annotation in code and by explicitly adding the keep rule for a particular interface as well. But it didn't work.

Note: The entire code of the library is in Kotlin.

The above specified issue is resolved now. I used below solution for it:

Android studio version: 4.1.x

Android tools version: classpath 'com.android.tools.build:gradle:4.1.1' (Issue was occurring with version 4.0.2 )

Gradle version: 6.5.1 (Issue was occurring with version 6.3 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM