Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Automated AAR build, move to folder and deJetify. Just add this to to end of your build.gradle file and run `prepareAAR` task
def manifest = new XmlSlurper().parse(file("./src/main/AndroidManifest.xml"))
def packageName = manifest.@package.text()
task copyAAR(type: Copy) {
from "$projectDir/build/outputs/aar/"
include 'android.aar'
into "$projectDir/AAR/"
rename 'android.aar', "${packageName}.aar"
doLast {
new File("$projectDir/AAR/build.gradle").text = """
artifacts.add("default", file('${packageName}.aar'))
task deJetify(type: Exec) {
workingDir "$projectDir/AAR/"
if (System.getProperty('').toLowerCase(Locale.ROOT).contains('windows')) {
commandLine 'cmd', '/c', 'npx', 'jetifier-standalone', '-r', '-i', "${packageName}.aar", '-o', "${packageName}-support.aar"
} else {
commandLine 'npx', 'jetifier-standalone', '-r', '-i', "${packageName}.aar", '-o', "${packageName}-support.aar"
ignoreExitValue true
doLast {
if(execResult.exitValue != 0) {
logger.error("It seems that you don't have jetifier installed. Try installing it by `npm install jetifier` and try again")
task prepareAAR(type: GradleBuild) {
tasks = ['assemble', 'copyAAR', 'deJetify']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.