Skip to content

Instantly share code, notes, and snippets.

@obfusk
Last active January 18, 2023 13:58
Show Gist options
  • Select an option

  • Save obfusk/a5463fe404e22d6691f180279266b94a to your computer and use it in GitHub Desktop.

Select an option

Save obfusk/a5463fe404e22d6691f180279266b94a to your computer and use it in GitHub Desktop.
-> https://github.com/obfusk/reproducible-apk-tools#gradle-integration | reproducible-apk-tools gradle integration
// NB: assumes reproducible-apk-tools is a submodule in the app repo's
// root dir; adjust the path accordingly if it is found elsewhere
project.afterEvaluate {
tasks.compileReleaseArtProfile.doLast {
outputs.files.each { file ->
if (file.toString().endsWith(".profm")) {
exec {
commandLine(
"../reproducible-apk-tools/inplace-fix.py",
"sort-baseline", file
)
}
}
}
}
}
// NB: assumes reproducible-apk-tools is a submodule in the app repo's
// root dir; adjust the path accordingly if it is found elsewhere
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
variant.packageApplicationProvider.get().doLast {
def tools = "${android.sdkDirectory}/build-tools/${android.buildToolsVersion}"
exec {
// set PATH for zipalign
environment "PATH", "${tools}:$System.env.PATH"
commandLine(
"../reproducible-apk-tools/inplace-fix.py",
"--zipalign", "fix-newlines", output.outputFile,
"META-INF/services/*"
)
}
// re-sign w/ apksigner if needed
if (variant.signingConfig != null) {
def sc = variant.signingConfig
exec {
environment "KS_PASS", sc.storePassword
environment "KEY_PASS", sc.keyPassword
commandLine(
"${tools}/apksigner", "sign", "-v",
"--ks", sc.storeFile,
"--ks-pass", "env:KS_PASS",
"--ks-key-alias", sc.keyAlias,
"--key-pass", "env:KEY_PASS",
output.outputFile
)
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment