Skip to content

Instantly share code, notes, and snippets.

@hkkcngz
Last active September 12, 2022 13:33
Show Gist options
  • Save hkkcngz/9860a537e32ee50c5c5f5e25d54ebdff to your computer and use it in GitHub Desktop.
Save hkkcngz/9860a537e32ee50c5c5f5e25d54ebdff to your computer and use it in GitHub Desktop.
Allatori, build.gradle
android {
...
// for applications
applicationVariants.all { variant ->
variant.javaCompileProvider.get().doLast {
runAllatori(variant)
}
}
// for libraries
// libraryVariants.all { variant ->
// variant.javaCompileProvider.get().doLast {
// runAllatori(variant)
// }
// }
}
def runAllatori(variant) {
copy {
from "$projectDir/allatori.xml"
into "$buildDir/intermediates/classes/"
expand(classesRoot: variant.javaCompileProvider.get().destinationDir,
kotlinRoot: "${buildDir}/tmp/kotlin-classes/${variant.name}",
androidJar: "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar",
classpathJars: variant.javaCompileProvider.get().classpath.getAsPath(),
logFile: "allatori-log-${variant.name}.xml")
rename('allatori.xml', "allatori-${variant.name}.xml")
}
new File("${variant.javaCompileProvider.get().destinationDir}-obfuscated").deleteDir()
javaexec {
main = 'com.allatori.Obfuscate'
classpath = files("$rootDir/allatori/allatori.jar")
args "$buildDir/intermediates/classes/allatori-${variant.name}.xml"
}
new File("${variant.javaCompileProvider.get().destinationDir}").deleteDir()
new File("${variant.javaCompileProvider.get().destinationDir}-obfuscated").renameTo(new File("${variant.javaCompileProvider.get().destinationDir}"))
// Kotlin support
// new File("${buildDir}/tmp/kotlin-classes/${variant.name}").deleteDir()
// new File("${buildDir}/tmp/kotlin-classes/${variant.name}-obfuscated").renameTo(new File("${buildDir}/tmp/kotlin-classes/${variant.name}"))
}
task runAllatoriOnRelease() {
Gradle gradle = getGradle()
String tskReqStr = gradle.getStartParameter().getTaskRequests().toString()
boolean isDebuggable = android.buildTypes.release.debuggable
if (tskReqStr.contains("Release") && isDebuggable) {
// Allatori Codes
android.libraryVariants.all { variant ->
variant.javaCompileProvider.get().doLast {
runAllatori(variant)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment