A sample Android™ app that demonstrates using PreEmptive Protection™ DashO™ with the DashO Gradle Plugin for Android 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 app is coded in Java™. The library is coded in Kotlin™.
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
andrelease
builds. This sample will be protectingrelease
builds.Debug
builds can be protected by configuringenabledBuildVariants
.
- Java™ 8
- PreEmptive Protection DashO v12.0.0 (or later)
- Android Build Environment
- Platform v30
Note: The Android-specific settings can be changed by editing the
build.gradle
files.
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 theGameOfLifeView
.app/src/paid
- Code which allows user interaction with theGameOfLifeView
.app/src/menu
- TheAndroidManifest.xml
for allmenu
flavors.app/src/single
- TheAndroidManifest.xml
for allsingle
flavors.app/src/menuFree
- Resources for themenuFree
flavor.app/src/menuPaid
- Resources for themenuPaid
flavor.app/src/singleFree
- Resources for thesingleFree
flavor.app/src/singlePaid
- Resources for thesinglePaid
flavor.
Setting up protection involves the following steps:
- Run the DashO New Project Wizard.
- Configure DashO Home (if needed).
- Customize the configuration.
Note: You can preview the final configuration by switching to the
obfuscated
branch.
The wizard will guide you through the process of integrating the DashO Gradle Plugin for Android into your build.
- Launch the DashO GUI.
- Launch the New Project Wizard by going to
File > Project Wizard...
, if it is not started automatically. - Select
Next
, selectAndroid (Most projects)
, and selectNext
again. - To enter the project directory, select
DashO-GameOfLife/app
(orDashO-GameOfLife/app/build.gradle
), and selectNext
. - After reading the Summary, select
Finish
to have the wizard do the integration.
At this point the initial integration is complete.
The DashO Gradle Plugin for Android will automatically find DashO if it is installed in the default location. Otherwise, the plugin needs to know where DashO Home is so it can run DashO to protect the code. There are multiple ways to configure DashO Home.
The wizard will have already added a dasho { }
closure in build.gradle
with a home
line commented out.
Uncommenting this line will set DashO Home to the location of the current DashO installation.
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.
The paid
variants will use app/project.dox
.
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.
- Copy
app/project.dox
toapp/free.dox
. This file will be used by thefree
variants. - Launch the DashO GUI (if not already opened).
- Open
app/free.dox
. - If it prompts you to run a build:
- Click
OK
. - Run
gradlew clean assembleSingleFreeRelease
from the command line. - Click the refresh button once it is highlighted.
- Click
- Go to the
Checks->Emulator
page in the GUI. - Click
Add
and chooseEmulator Check...
- Under
Locations
, checkcheckTheLock()
underAbstractGameOfLifeActivity
. (You will need to scroll down past theandroidx
packages and expandAbstractGameOfLifeActivity
undercom.preemptive.dasho.example.gameoflife
.) - Set the
Action
tosetLocked()
and clickOK
. - Save the file.
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 MF Game Of Life.gradlew installMenuPaidRelease
- Installs MP Game Of Life.gradlew installSingleFreeRelease
- Installs SF Game Of Life.gradlew installSinglePaidRelease
- Installs SP Game Of Life.
You can uninstall all the variants by running gradlew uninstallAll
.
Run a custom task to just do all of it: gradlew doAllTheThings
.
You can validate the build is using the appropriate configurations and that it is protecting the application.
The output from the Gradle build will show when DashO is run.
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.
If you want to see more information on what DashO is doing, you can configure verbose true
inside the dasho
closure in app/build.gradle
.
This will provide you with the verbose output from the protection process.
To further investigate you can use the following tools to look at the final protected APK:
PreEmptive Protection DashO is an obfuscation and application protection solution from PreEmptive. 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.
This sample is based on GameOfLifeView by Thiago Rocha.
Copyright 2021 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
<http://www.apache.org/licenses/LICENSE-2.0>
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Android is a trademark of Google LLC. GitHub is a registered trademark of GitHub, Inc. Gradle is a registered trademark of Gradle, Inc. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.