Skip to content

Instantly share code, notes, and snippets.

@rozPierog
Last active October 4, 2021 13:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rozPierog/9c1f63d39c4e5cece537e5b03d0f43f1 to your computer and use it in GitHub Desktop.
Save rozPierog/9c1f63d39c4e5cece537e5b03d0f43f1 to your computer and use it in GitHub Desktop.
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 = """
configurations.maybeCreate("default")
artifacts.add("default", file('${packageName}.aar'))
"""
}
}
task deJetify(type: Exec) {
workingDir "$projectDir/AAR/"
if (System.getProperty('os.name').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