ClassGuard for Android

Integration with your AndroidStudio/gradle project is easy:

aguard.jar=/path/to/aguard/jar/aguard-2.0.x.jar

Please don’t add aguard-2.0.x.jar to your app library folder!

  • Add additional tasks and dependencies to the root build.gradle file:
    allprojects {
        repositories {
            google()
        mavenCentral()
    }
    task androidGuardDex(type: JavaExec) {
        main = 'com.zenofx.aguard.tasks.GradleTask'
        classpath = files(project.property('aguard.jar'))
        args('dex')
    }
    task androidGuardManifest(type: JavaExec) {
        main = 'com.zenofx.aguard.tasks.GradleTask'
        classpath = files(project.property('aguard.jar'))
        args('manifest')
    }
    task androidGuardClean(type: JavaExec) {
        main = 'com.zenofx.aguard.tasks.GradleTask'
        classpath = files(project.property('aguard.jar'))
        args('clean')
    }
    tasks.whenTaskAdded { task ->
        if (task.name == 'packageRelease') {
            task.dependsOn androidGuardDex
            task.finalizedBy androidGuardClean
        }
        else if (task.name == 'mergeReleaseNativeLibs') {
            task.dependsOn androidGuardDex
        }
        else if (task.name == 'mergeReleaseAssets') {
            task.dependsOn androidGuardDex
        }
        else if (task.name == 'mergeDexRelease') {
            tasks.androidGuardDex.dependsOn mergeDexRelease
        }
        else if (task.name == 'processReleaseManifest') {
            tasks.androidGuardManifest.dependsOn processReleaseManifest
        }
        else if (task.name == 'processReleaseResources') {
            task.dependsOn androidGuardManifest
        }
    }

Your’re done!

  • gradlew packageRelease or gradlew installRelease now generates an encrypted apk!
  • “Generate Signed APK…” within Android Studio also generates an encrypted apk!