Progress will discontinue Telerik Platform on May 10th, 2018. Learn more
  • How to Obfuscate Java Code With ProGuard

How to Obfuscate Java Code With ProGuard

Environment

Service Code (AppBuilder), Third-party product
Feature Security
Mobile development type Hybrid (Cordova app)
Mobile OS Android

Description

Application packages cannot be completely secured from reverse-engineering. Instead, it is recommended to use tools for code obfuscation and secure any proprietary code on a server. This article shows how to create a small custom plugin that enables ProGuard and obfuscates all Java code that is present in your AppBuilder Apache Cordova application.

Solution

  1. Create an empty folder.
  2. Inside the folder, create three files - package.json, plugin.xml, enable-proguard.gradle.
  3. The package.json file contains only the most basic information required by a Apache Cordova plugin. For example:

    {
      "name": "proguardplugin",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "keywords": [],
      "author": "",
      "license": "ISC"
    }
    
  4. The plugin.xml file is used to reference the enable-proguard.gradle file and include it in your app. For example:

    <?xml version="1.0" encoding="UTF-8"?>
    <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
            xmlns:android="http://schemas.android.com/apk/res/android"
            id="proplugin"
            version="0.0.1">
    
        <name>proplugin</name>
    
        <framework src="enable-proguard.gradle" custom="true" type="gradleReference"/>
    </plugin>
    
  5. The enable-proguard.gradle file contains the logic required to enable ProGuard and obfuscate your code.

    android {
        buildTypes {
            release {
                minifyEnabled true
                proguardFile getDefaultProguardFile('proguard-android.txt')
            }
        }
    }
    
  6. The last step is to archive the folder containing those files and import it to your app as a custom plugin.

Notes

Obfuscation with ProGuard in AppBuilder can also be achieved by modifying an already existing custom plugin. This can be accomplished by adding the enable-proguard.gradle file to the plugin folder and referencing it in plugin.xml.

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.