Gradle Plugin for Android Configuration
To use the DashOâ„¢ Gradle Plugin for Android, first add it to your Gradle build and then configure it further in your buildscript.
Adding the Plugin
To apply the DashO Gradle Plugin for Android, you need to include it as a buildscript dependency on your build, which in turn requires you to add the PreEmptive Maven Repository as a buildscript repository:
buildscript {
repositories {
maven { url 'https://maven.preemptive.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.preemptive.dasho:dasho-android:1.0.+'
}
}
You will also need to apply the plugin after the appropriate Android plugin (i.e., com.android.application or com.android.library):
apply plugin: 'com.android.application'
apply plugin: 'com.preemptive.dasho.android'
Configuring the Plugin
The plugin can be configured via the dasho closure in your buildscript at any point after the com.preemptive.dasho.android plugin has been applied.
dasho {
debug false
doxFilename "project.dox"
enabledBuildVariants "release"
excludeFromProtection null
home "/Applications/PreEmptive Protection DashO x.y/Contents/Java"
javaOptions "-Xmx128m", "-Xms96m"
searchVersion "10"
verbose false
}
The following properties are available for the dasho closure:
| Name | Functionality | Default |
|---|---|---|
debug |
If enabled, the plugin will run DashO with the --debug and --printStackTraces options, and will print the command used to invoke DashO. |
false |
doxFilename |
Defines the name of the DashO configuration file that DashO should use when protecting your Android project. This should refer to a file in your project directory. Note that backslashes (\) in this path must be escaped (\\) or replaced with forward slashes (/). |
See Default DashO Configuration File |
enabledBuildVariants |
Defines the build variants that the plugin should protect. Accepts a regular expression; the plugin will protect a build variant if the variant's name contains a match for the expression, case insensitively. A blank value ("") will match all variants. |
release (Matches all release variants) |
excludeFromProtection |
Defines inputs that should be excluded from protection. Accepts a regular expression; any inputs whose name contains a match by the expression, case insensitively, will be passed to DashO as a dependency instead of an input. | null (See documentation) |
home |
DashO Home; where to find DashOPro.jar. Don't set if specifying searchVersion or otherwise allowing the plugin to locate DashO automatically. |
No default |
javaOptions |
Additional JVM options to use when invoking Java to run DashO. Accepts one or more Strings. | No additional options |
searchVersion |
Configures the plugin to search for DashO Home given a string in the format {major}[.{minor}] (e.g. 10 or 10.2). Don't set if specifying home. |
No default |
verbose |
If enabled, the plugin will run DashO with the --verbose and --printStackTraces options, and will print the command used to invoke DashO. |
false |
The dasho closure is not required if you don't need to set any of its properties, all of which are optional.
Notes:
The DashO Gradle Plugin for Android will use the same version of Java as configured for Gradle when running DashO. This can be configured with theorg.gradle.java.homesetting.
The DashO Gradle Plugin for Android is not compatible with Instant Run functionality in Android Studio. If you enable DashO to run on debug build variants, you will need to disable Instant Run.
Default DashO Configuration File
If you do not specify a DashO Configuration File with the doxFilename property of the dasho closure, the DashO Gradle Plugin for Android will search for a project file matching the current variant.
As an example, suppose you have the following build flavors and types configured:
android {
buildTypes {
debug { }
release { }
}
flavorDimensions 'monetization', 'deviceType'
productFlavors {
free { dimension 'monetization' }
paid { dimension 'monetization' }
phone { dimension 'deviceType' }
tablet { dimension 'deviceType' }
}
}
For the build variant freePhoneDebug, the DashO Gradle Plugin for Android would look for project files in the same directory as the application-level build.gradle, using the first project file found in the following list:
freePhoneDebug.doxfreePhone.doxfree.doxphone.doxdebug.doxproject.dox
Excluding from Protection
The dasho closure contains an excludeFromProtection property which allows inputs to be excluded from protection by DashO.
The setting accepts a regular expression.
All inputs whose name contains a match for the expression will be passed to DashO as a dependency.
By default nothing is excluded.
For example, if your project has dependencies like:
dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation project(':library')
}
...setting excludeFromProtection "androidx" will pass the androidx jars as dependencies to DashO.
This setting can be helpful if you are running a single build from which you distribute both a library (AAR) and an application (APK).
You can configure DashO to protect both the library and the application and then set excludeFromProtection ":library" in your application's build.gradle file.
If you are only distributing the application, do not protect the library independently; it will be protected with the application so long as you do not exclude it.
Notes:
The regular expression only needs to case-insensitively match part of the name. Soviewwould match'androidx.recyclerview:recyclerview:1.0.0and:codeViewerLibrary.
The build will fail if you configureexcludeFromProtectionto match everything (e.g.excludeFromProtection ".*"orexcludeFromProtection "").
Some plugins may corrupt the names making it impossible to match the original names. For example, the Firebase Performance plugin will change the nameandroidx.annotation:annotation:1.0.0to something like0a1124bfce06f9f05e9f92edcabdc725-classes. If you encounter corrupted names, please applycom.preemptive.dasho.androidbefore those plugins (e.g.com.google.firebase.firebase-perf).
Running with the plugin
Once you have applied the plugin it should automatically integrate with the Android plugin.
You can run gradlew dashOPluginVersion to display the full version of the plugin.
Supported Properties
The plugin supports the following properties which can be set as a Gradle project property, a Java system property or an environment variable:
DASHO_HOME- Specifies DashO Home.DISABLE_DASHO- DashO will not process the classes if this property exists. No value is needed. All values other thanfalseare interpreted astrue.GENERATE_DASHO_CONFIG- Tells DashO to generate a default Android Mode configuration file. No value is needed. All values other thanfalseare interpreted astrue.SHOW_DASHO_CMD- The command line arguments used when launching DashO will be shown if this property exists. No value is needed. All values other thanfalseare interpreted astrue.
These properties can be passed on the gradlew command line via -P{name}[={value}] or -D{name}[={value}]
Note: An error will occur when using the
GENERATE_DASHO_CONFIGproperty if the configuration file already exists.