Skip to content
An Android app that demonstrates using DashO with libraries and product flavors
Branch: master-vNext
Clone or download
Pull request Compare This branch is 57 commits ahead of thiagokimo:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


A sample Android app that demonstrates using PreEmptive Protection - DashO with the DashO Android Gradle Plugin on an application with libraries and product flavors.

This sample is a Game of Life simulation application. This project consists of the app itself and a library that it uses.

The application has two flavor dimensions: view and monetization. The view dimension determines if the application launches a menu with a list of two views or just launches a single view. The monetization dimension determines whether the application is interactive (paid) or non-interactive (free). This interaction allows the user to give life to a cell by tapping.

These dimensions are ultimately combined to create four applications:

paid free
menu menuPaid - Shows a menu of two interactive views. menuFree - Shows a menu of two non-interactive views.
single singlePaid - Shows a single interactive view. singleFree - Shows a single non-interactive view.

The library is used by all four applications. The menu flavors use the library's code directly and reference the library's GameOfLifeView class via XML. The single flavors only use the library's code directly.

These instructions will demonstrate protecting the application with variant-specific configurations.

Note: DashO can protect both debug and release builds. This sample will be protecting release builds. Debug builds can be protected by configuring enabledBuildVariants.


Note: The Android-specific settings can be changed by editing the build.gradle files.

Code Layout

This sample uses a standard layout for an Android project.

  • library - The library project.
  • app - The application project.
  • app/src/main - The majority of the application source.
  • app/src/free - Code which does not allow user interaction with the GameOfLifeView.
  • app/src/paid - Code which allows user interaction with the GameOfLifeView.
  • app/src/menu - The AndroidManifest.xml for all menu flavors.
  • app/src/single - The AndroidManifest.xml for all single flavors.
  • app/src/menuFree - Resources for the menuFree flavor.
  • app/src/menuPaid - Resources for the menuPaid flavor.
  • app/src/singleFree - Resources for the singleFree flavor.
  • app/src/singlePaid - Resources for the singlePaid flavor.

Setting up Protection

Setting up protection involves the following steps:

  1. Enable and configure R8.
  2. Configure the DashO Android Gradle Plugin's location.
  3. Apply the plugin.
  4. Configure DashO Home (if needed).
  5. Generate a configuration file.
  6. Customize the configuration.

Note: You can preview the final configuration by switching to the obfuscated-vNext branch.

Enable and Configure R8

The DashO Android Gradle Plugin relies on R8 to perform renaming and removal, so it is important that you enable it.

In app/build.gradle, add the following inside the android { buildTypes { release { } } } block:

minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')

This will enable R8 with default settings, including optimization.

Configure the DashO Android Gradle Plugin's Location

The Gradle build script needs to be able to find the DashO Android Gradle Plugin.

In build.gradle add the following to the repositories section which is inside buildscript:

maven { url '' }

In build.gradle add the following to the dependencies section which is inside buildscript:

classpath 'com.preemptive.dasho:dasho-android:0.10.+'

Apply the Plugin

Applying the plugin will incorporate DashO into the build process.

In app/build.gradle add the following after apply plugin: '':

apply plugin: ''

Configure DashO Home (If Needed)

The plugin needs to know where DashO is installed so it can protect the code.

The plugin should find it automatically if DashO is installed in the default location. If not, there are multiple ways to configure DashO Home.

Generate a Configuration File

The basic configuration can be generated during the build.

Run the following command:

gradlew clean assembleRelease -DGENERATE_DASHO_CONFIG

That will generate an Android Mode project.dox file in the app directory.

Customize the Configuration

Since this sample demonstrates product flavor support, we need two different configuration files. One to handle the free variants and one for the paid variants.

These two configurations will start with the same information. We are excluding Android's classes as they are not relevant to this sample.

  1. Launch the DashO GUI (if not already opened).
  2. Open app/project.dox.
  3. If it prompts you to run a build:
    1. Click OK.
    2. Run gradlew clean assembleSinglePaidRelease from the command line.
    3. Click the refresh button once it is highlighted.
  4. Go to Global Exclude in the GUI.
  5. Click New Class
  6. Type android*.** for the name and click OK.
  7. Save the file.

Configuring the 'free' Variants

To further encourage users to "buy" the paid version, an Emulator Check will be added to the free variants. If the application is run on an emulator, the entire view will be covered by oscillating blinkers.

  1. Copy app/project.dox to app/free.dox. This file will be used by the free variants.
  2. Launch the DashO GUI (if not already opened).
  3. Open app/free.dox.
  4. If it prompts you to run a build:
    1. Click OK.
    2. Run gradlew clean assembleSingleFreeRelease from the command line.
    3. Click the refresh button once it is highlighted.
  5. Go to Checks->Emulator in the GUI.
  6. Click Add and choose Emulator Check
  7. Under Locations, check checkTheLock() under AbstractGameOfLifeActivity.
  8. Set the Action to setLocked() and click OK.
  9. Save the file.

Running the Application

Because of the Emulator Check, the application will respond differently based on where it is run.

Paid Variants Free Variants
Device Interactive views. Tapping a cell brings it to life. Non-interactive views. Tapping tells user to "upgrade".
Emulator Interactive views. Tapping a cell brings it to life. Non-interactive views with blinker patterns. Tapping tells user to "upgrade".


The first two screens are the starting pages for the menu and single variants. The last screen shows what to expect when running a free variant on an emulator.


Run gradlew clean assembleRelease to compile and protect all the release variants.


The four different variants can be simultaneously installed:

  • gradlew installMenuFreeRelease - Installs DashO MF Game Of Life.
  • gradlew installMenuPaidRelease - Installs DashO MP Game Of Life.
  • gradlew installSingleFreeRelease - Installs DashO SF Game Of Life.
  • gradlew installSinglePaidRelease - Installs DashO SP Game Of Life.


You can uninstall all the variants by running gradlew uninstallAll.

Everything at Once

Run a custom task to just do all of it: gradlew doAllTheThings.

Verifying Protection

You can validate the build is using the appropriate configurations and that it is protecting the application.

Reviewing DashO's Protection

The output from the Gradle build will show when DashO is run.

Verify the Flavor-specific Configuration

If you add -DSHOW_DASHO_CMD when building (e.g. gradlew doAllTheThings -DSHOW_DASHO_CMD), the information being passed to DashO will be printed to the console as the transformClassesAndResourcesWithDashOFor... tasks are run. This will include a Running: line where you can see the full arguments used to run DashO including which .dox configuration file is passed.

Verbose Output

If you want to see more information on what DashO is doing, you can add a dasho closure to app/build.gradle and configure verbose true. This will provide you with the verbose output from the protection process.

Decompiling the APK

To further investigate you can use the following tools to look at the final protected APK:

About DashO

PreEmptive Protection - DashO is a Java and Android obfuscator and application hardening solution from PreEmptive Solutions. DashO's obfuscation, hardening, and runtime check features make your application much harder to reverse engineer, pirate, or steal data from. World-class technical support for DashO is available through our website and/or our support request form.

Original Source

This sample is based on GameOfLifeView by Thiago Rocha.


Copyright 2019 PreEmptive Solutions, LLC.

Copyright 2011, 2012 Thiago Rocha

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at


Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
You can’t perform that action at this time.