Android Configuration
Overview
If using DashO's com.android.application
or com.android.library
plugin, your output in DashO must be configured to be a jar. In addition to configuring ${gradleInput}
and ${gradleOutput}
, a non-class file must be configured for the AndroidManifest.xml. Use ${AndroidManifestFile}
as the source file and ${AndroidManifestOutput}
as the relative destination. You will also need to add the correct android.jar
file to the supporting classpath section of your .dox
file and use your package name as the renaming prefix. If you are protecting a library, you should also configure DashO to remove the compiled {package name}.R* classes and make sure the classes which will be referenced by applications are configured as entry points.
DashO has a project wizard that will configure most of these settings for you, if you use it for initial DashO project setup.
Notes:
The DashO Gradle Plugin is not compatible with R8 and will not run with R8 enabled.
See the Enabling Protection section for how to configure DashO to run in your Android project.
If you have a multi-project configuration, see the Library section.
The following User Properties can also be used if needed:
${buildVariant}
- The build variant being run, expressed as a directory (e.g.debug
,release
,free/debug
). Available starting in version 3.0.2.${buildType}
- Equivalent to${buildVariant}
. Deprecated.${sdk.dir}
- The directory where the Android SDK is located.${build.dir}
- The directory containing Gradle build output.${sdk.target}
- The SDK version against which the project is compiled, prefixed withandroid-
(i.e.,compileSdkVersion
).${target.sdk.api}
- The SDK version that the project is targeting,-1
if not configured (i.e.,targetSdkVersion
). Available starting in version 3.2.0.${min.sdk.api}
- The minimum SDK version on which the project is built to run (i.e.,minSdkVersion
). Available starting in version 3.2.0.${compile.sdk.api}
- The SDK version against which the project is compiled (i.e.,compileSdkVersion
). Available starting in version 3.2.0.${manifest.package}
- The package name from the manifest.${applicationID}
- The application's ID. Available starting in version 3.1.0.${gradleSupport}
- The list of support jars.${KEYSTORE}
- The location of the key store.${KEYSTORE_PASSWORD}
- The password to access the key store.${KEY_ALIAS}
- The key alias.${KEY_ALIAS_PASSWORD}
- The password to access the key.
Note: The signing information is only passed when it is configured in the Android build.
Including Dependencies
When specifying the includeAsInputs
and dexExcluded
on an Android project, in addition to specifying dependencies as .aar
or .jar
files, you can specify them in a more direct fashion:
:myProject
- This represents theclasses.jar
inside anaar
file compiled as a separate sub-project.myProject
in this example.com.google.code.gson:gson:2.8.2
- Thegroup(groupid):name(artifactid):version
of a dependency.gson
in this example.
Note: This is only supported in version 3.0.1 and above.
Product Flavors
If you are working with different product flavors in your Android configuration and need different DashO configurations for the different flavors, you will need to create multiple DashO configuration files, name them based on the flavor, and remove any doxFilename
setting from the dashOConfig
closure. For Example: If you have two flavors: personal
and pro
, you would create a personal.dox
and pro.dox
configuration. When the DashO task runs, and does not find any configured doxFilename
, it will search for a file based on the flavor/build type (e.g. proDebug.dox
, pro.dox
, or debug.dox
). If it can't find one, then it will assume project.dox
.
Note: If you use flavor dimensions, the final name for each combined flavor should be used to name the
.dox
file.
Library (AAR) Projects
DashO can protect library (AAR) projects independently of the applications that use them.
The final .aar
file will contain the protected classes.
The Android Gradle Plugin behavior changed in v3.0.0. It no longer protects libraries that are compiled as part of a multi-project build. To ensure such libraries are protected by DashO, include library (AAR) projects for protection with your final application (APK).
Samples
The DashO-GameOfLife sample demonstrates how to configure DashO for a complex Android app.
Advanced Functionality
APK Splitting
The DashO Gradle plugin supports the APK Splitting functionality provided by the base Android Gradle plugin.
Multidex
The DashO Gradle plugin supports, on Lollipop (and later) devices, the multidex functionality provided by the base Android Gradle plugin. For older devices you will need to make the following changes to your .dox
file.
- Add the multidex library to your inputs. It will probably be located in
build/intermediates/exploded-aar/com.android.support/multidex/1.0.1/jars/classes.jar
. - Add the
android.support.multidex.MultiDexApplication
class with its<init>()
method as an Entry Point.
Resource Shrinking
The DashO Gradle plugin supports the resource shrinking functionality provided by the base Android Gradle plugin. It is recommended DashO be configured to remove all non-used classes and methods as resource shrinking relies on checking the compiled code for references to the resources.
Instant Run
Instant Run is not supported by DashO. If Instant Run is enabled, the DashO Transform will automatically be turned off. This should not affect your release builds. If you want to disable Instant Run, view the instructions at http://developer.android.com/studio/run/index.html#disable-ir