1



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.

e.g. 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.

Ryan M
  • 18,333
  • 31
  • 67
  • 74
gsv
  • 11
  • 3
  • Proguard obfuscation is working fine with above rules. If the interfaces are moved out of classes/interfaces into separate files, it is working fine with R8 as well. As the codebase is having many more inner/nested interfaces, it is difficult to move them out of parent classes. We want to just do the migration from Proguard to R8. – gsv Dec 28 '20 at 14:29
  • This looks like a bug in R8. Could you open an issue on https://issuetracker.google.com/issues/new?component=326788? Please include as much information as possible including the version of Android Studio you are using. – sgjesse Jan 05 '21 at 07:40

1 Answers1

0

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)

gsv
  • 11
  • 3