Android Integration

Integration with your AndroidStudio/gradle project is easy:

  • Download ClassGuard for Android
  • Add the downloaded jar to gradle.properties:
    aguard.jar=/path/to/aguard/jar/aguard-1.x.y.jar
    Please don't add aguard-1.x.y.jar to your app library folder!
  • Add additional tasks and dependencies to the root build.gradle file:
    allprojects {
        repositories {
            google()
            jcenter()
            ...
        }
        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')
        }
        tasks.whenTaskAdded { task ->
            if (task.name == 'packageRelease') {
                task.dependsOn androidGuardDex
            }
            else if (task.name == 'transformDexArchiveWithDexMergerForRelease') {
                tasks.androidGuardDex.dependsOn transformDexArchiveWithDexMergerForRelease
            }
            else if (task.name == 'mergeReleaseAssets') {
                tasks.androidGuardDex.dependsOn mergeReleaseAssets
            }
            else if (task.name == 'mergeReleaseJniLibFolders') {
                tasks.androidGuardDex.dependsOn mergeReleaseJniLibFolders
            }
            else if (task.name == 'processReleaseManifest') {
                tasks.androidGuardManifest.dependsOn processReleaseManifest
            }
            else if (task.name == 'processReleaseResources') {
                task.dependsOn androidGuardManifest
            }
        }
    }
    

Your're done!

  • gradlew assembleRelease or gradlew installRelease now generates an encrypted apk!
  • "Generate Signed APK..." within Android Studio also generates an encrypted apk!