https://github.com/g000sha256/keep
The plugin for preserving necessary declarations from obfuscation
https://github.com/g000sha256/keep
android kotlin obfuscation obfuscator proguard r8
Last synced: about 2 months ago
JSON representation
The plugin for preserving necessary declarations from obfuscation
- Host: GitHub
- URL: https://github.com/g000sha256/keep
- Owner: g000sha256
- License: apache-2.0
- Created: 2024-09-17T16:11:16.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2025-03-11T16:59:59.000Z (2 months ago)
- Last Synced: 2025-03-11T17:50:45.638Z (2 months ago)
- Topics: android, kotlin, obfuscation, obfuscator, proguard, r8
- Language: Kotlin
- Homepage:
- Size: 42 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Keep
[](https://central.sonatype.com/artifact/dev.g000sha256/keep-plugin)
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.## Initialization
### Add plugin repository
```kotlin
repositories {
mavenCentral()
}
```### Apply plugin
```kotlin
plugins {
id("dev.g000sha256.keep") version "1.0.0"
}
```### Plugin customization
#### Library module
```kotlin
keep {
outputDirectory =
type = // All / ApiOnly / ReflectionOnly
}
```#### Application module
Annotation and rules for API don't apply to the application module.
```kotlin
keep {
outputDirectory =
}
```### Generate rules
Apply annotations and generate rules with the command:
```
./gradlew keepGenerate
```## Annotations usage
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.> [!TIP]
> You may add annotations only for the necessary declarations. Parent declarations will be added automatically.### Classes
```kotlin
@KeepApi
class TestClass
``````kotlin
class TestParentClass {@KeepApi
class TestInnerClass}
```### Objects
```kotlin
@KeepApi
object TestObject
```### Companion objects
```kotlin
class TestClass {@KeepApi
companion object}
``````kotlin
class TestClass {@KeepApi
companion object TestCompanionObject}
```### Getters
```kotlin
class TestClass {@get:KeepApi
val testValue: Int = 0}
```### Setters
```kotlin
class TestClass {@set:KeepApi
var testValue: Int = 0}
```### Constructors
```kotlin
class TestClass @KeepApi constructor(val testParameter: Int)
```### Constructor parameters
```kotlin
class TestClass(@get:KeepApi val testParameter: Int)
```### Methods
```kotlin
class TestClass {@KeepApi
fun testMethod() {
}}
```## Roadmap
- Constructor parameter types
- Field types
- Method parameter types
- `@JvmStatic` and `@JvmField` support