The Gradle plugin simplifies the process of preserving necessary declarations from obfuscation when using the R8 tool.
It provides the KeepAPI
and KeepReflection
annotations, along with corresponding R8 rules that are
automatically applied to your project based on the annotations used.
repositories {
mavenCentral()
}
plugins {
id("dev.g000sha256.keep") version "0.0.1"
}
The KeepAPI
and KeepReflection
annotations are used similarly but serve different purposes.
- Use the
KeepReflection
annotation to preserve declarations accessed via reflection. - Use the
KeepAPI
annotation to preserve API declarations in library modules.
Important
Annotating methods and fields does not automatically preserve the class name. Don't forget to add the annotation to the class if necessary.
@KeepAPI
class TestClass
@KeepAPI
class TestParentClass {
@KeepAPI
class TestInnerClass
}
@KeepAPI
class TestClass {
@get:KeepAPI
val testValue: Int = 0
}
@KeepAPI
class TestClass {
@set:KeepAPI
var testValue: Int = 0
}
@KeepAPI
class TestClass {
@get:KeepAPI
@set:KeepAPI
var testValue: Int = 0
}
@KeepAPI
class TestClass @KeepAPI constructor(val testValue: Int)
@KeepAPI
class TestClass @KeepAPI constructor(@get:KeepAPI val testValue: Int)
@KeepAPI
class TestClass {
@KeepAPI
fun testMethod() {
}
}