PreEmptive Protection™ DashO™ protects compiled Kotlin code for the JVM and Android. DashO often processes Kotlin code without any extra configuration. Some build processes and Kotlin features, such as reflection and coroutines, need additional settings.
How DashO Handles Kotlin Runtime Libraries
DashO needs the Kotlin runtime library as either an input or a support. The following configurations supply it automatically:
| Configuration | How DashO treats Kotlin runtime classes |
| APK Post Processing | Inputs |
| DashO Gradle Plugin for Android | Inputs |
| DashO Gradle Plugin for Java (including legacy Android projects) | Supports. If you target specific libraries with includeAsInputs, DashO treats those libraries as inputs. |
Add Kotlin Runtime Libraries Manually
For all other configurations, add the Kotlin runtime JAR files to your DashO configuration yourself.
- Identify the runtime JAR files for your Kotlin version:
-
kotlin-stdlib.jar,kotlin-stdlib-jdk8.jar, andkotlin-stdlib-jdk7.jar kotlin-runtime.jar
-
- Choose how to add the JAR files:
| If you… | Add the JAR files as |
| Run the protected app with the Kotlin wrapper script | Support libraries |
| Use Kotlin reflection, or libraries that use reflection internally | Support libraries, when possible |
| Neither of the above | Support libraries or inputs. Choose inputs to let DashO remove unused classes and methods from the Kotlin runtime libraries. |
- Add the JAR files to your DashO configuration.
- Save your project and build it to apply the changes.
Configure DashO for Reflection
Kotlin reflection, and libraries that use reflection internally, refer to classes, methods, and fields by name. Renaming breaks these references.
- Identify the classes, methods, and fields your code accesses through reflection.
- Exclude them from renaming.
- Save your project and build it to apply the changes.
Configure Kotlin Coroutines
The Kotlin coroutines library relies heavily on reflection to access fields defined inside the library. If DashO treats the coroutines library classes as inputs, protect those fields with one of the following options:
| Option | Use it when |
| Exclude the fields from renaming | DashO handles renaming for your project. |
| Add an R8 keep rule | Your project uses Android Mode, where R8 handles renaming and removal. |
| Exclude the coroutines libraries from protection | You configure DashO through a dasho closure and don't need to protect the coroutines libraries. |
Exclude Coroutines Fields from Renaming
Add the following exclusion to the renaming section of your DashO configuration.
<renaming>
<excludelist>
<classes name="kotlinx.coroutines.**">
<field name="*"/>
</classes>
</excludelist>
</renaming>Add an R8 Keep Rule in Android Mode
Add the following rule to your R8 configuration. It stops R8 from removing fields defined in the Kotlin coroutines library.
-keepclassmembers class kotlinx.coroutines.** {
volatile <fields>;
}For more information, see Enable R8 Optimization.
Exclude Coroutines Libraries from Protection
Add an excludeFromProtection entry to your dasho closure:
dasho {
excludeFromProtection "kotlinx-coroutines"
}If your dasho closure already contains an excludeFromProtection entry, update its pattern so it also matches kotlinx-coroutines.
Limitations and Troubleshooting
| Issue | Resolution |
| Duplicated classes | Remove any Kotlin libraries you added manually if you use APK Post Processing or a DashO Gradle plugin. These configurations supply the Kotlin runtime automatically. [Include the error message users see.] |
| Reflection fails after protection | Exclude the classes, methods, and fields accessed through reflection from renaming. |
| Coroutines fail after protection | Apply one of the options in Configure Kotlin Coroutines. |