Kotlin
PreEmptive Protection™ DashO™ for Android & Java supports protecting compiled Kotlin code for the JVM or Android. In many cases, processing Kotlin code with DashO will simply work without additional DashO configuration, but some build processes or Kotlin features may require additional configuration.
Kotlin Runtime Libraries
DashO needs the Kotlin runtime library to be supplied either as inputs or as supports. For many types of DashO configurations, this will happen automatically:
- APK Post Processing: All Kotlin runtime classes are treated as inputs.
- DashO Gradle Plugin for Android: All Kotlin runtime classes are treated as inputs.
- DashO Gradle Plugin for Java (including legacy Android projects): Kotlin runtime classes are treated as supports, unless specific libraries are targeted with
includeAsInputs
in which case they will be treated as inputs.
In these cases, you do not need to explicitly add any Kotlin libraries as inputs or supports for DashO, and doing so could cause issues with duplicated classes.
In other cases, you may need to add Kotlin runtime jars (e.g., kotlin-stdlib.jar
, kotlin-stdlib-jdk8.jar
, and kotlin-stdlib-jdk7.jar
; or kotlin-runtime.jar
, depending on the version of Kotlin) to your DashO configuration as inputs or supports.
If you plan to run the protected app with the Kotlin wrapper script, you should configure the runtime jars as support libraries.
Otherwise, you can configure them as either support libraries or as inputs.
If added to the inputs, DashO can remove unused classes and methods from the Kotlin runtime libraries.
Using Reflection
If you use Kotlin's reflection capabilities, or libraries that internally use reflection, you may need to exclude the referenced classes, methods, and fields from renaming.
Note: If you are using reflection we recommend configuring the Kotlin runtime jars as support libraries when possible.
Coroutines
The Kotlin coroutines library extensively uses reflection to access fields defined within the library. If the coroutine library classes are treated as inputs by DashO, you will need to exclude fields they contain from renaming:
<renaming>
<excludelist>
<classes name="kotlinx.coroutines.**">
<field name="*"/>
</classes>
</excludelist>
</renaming>
In an Android Mode project, R8 is responsible for Renaming and Removal. The following rule will prevent R8 from removing fields defined in the Kotlin coroutines library:
-keepclassmembers class kotlinx.coroutines.** {
volatile <fields>;
}