Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a comprehensive Android sample project (
UsedByNativeSample) that demonstrates the use of theandroidx.annotation.keepGradle plugin and best practices for keeping code reachable when using reflection, JNI, and serialization with R8/Proguard. It includes a fully configured app module, native C++ integration, multiple Kotlin and Java examples illustrating reflection and code retention scenarios, and detailed documentation for setup and testing.The most important changes are:
Project Setup and Documentation
UsedByNativeSample) with a detailedREADME.mdexplaining how to use theandroidx.annotation.keepplugin, including instructions for both Android and Java/Kotlin modules..gitignorefiles for both the project root and app module to exclude build artifacts and IDE files. [1] [2]App Module Configuration
build.gradle.ktsfor the app, enabling Compose, native builds, Kotlin Parcelize, and integrating the annotation-keep plugin.AndroidManifest.xmland instrumented test (ExampleInstrumentedTest.kt). [1] [2]JNI and Native Code Integration
native-lib.cppandCMakeLists.txt) demonstrating both downcalls (Kotlin→C++) and upcalls (C++→Kotlin), with comments on required keep rules. [1] [2]JniBridge,NativeLib, etc.) to interact with the native library and show JNI usage in the app UI.Reflection and Code Retention Examples
UsedByNative) to mark members used by native code for retention by R8/Proguard.Serialization and Parcelable
SerializableExample.kt) and Kotlin Parcelable (ParcelableExample.kt), demonstrating the need for keep rules to preserve serialization methods. [1] [2]These changes together provide a robust reference for handling code shrinking and reflection in modern Android development.
References: [1] [2] [3] [4] [5]