Skip to content

Instantly share code, notes, and snippets.

@weiancheng
Created June 17, 2020 07:25
Show Gist options
  • Save weiancheng/8e4a42021ed430b2bc57deec1a8774f6 to your computer and use it in GitHub Desktop.
Save weiancheng/8e4a42021ed430b2bc57deec1a8774f6 to your computer and use it in GitHub Desktop.
[Android makes AAR file] #android #gradle #aar
// ...
android {
// ...
libraryVariants.all { variant ->
variant.outputs.all { output ->
variant.assemble.doLast {
exec {
def localProperties = new File(rootDir, "local.properties")
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}
def sdkDir = properties.getProperty('sdk.dir')
def dxCommandPath=sdkDir+'/build-tools/27.0.3/dx.bat'
if(Os.isFamily(Os.FAMILY_MAC)){
dxCommandPath = sdkDir+'/build-tools/27.0.3/dx'
}
File dxFile = new File(dxCommandPath)
if(!dxFile.exists()) {
def buildToolsDir = new File(sdkDir, "build-tools")
def buildToolsAvailable = buildToolsDir.list().sort { a, b -> b <=> a }
println "Using latest found build tools," + buildToolsAvailable[0]
if(Os.isFamily(Os.FAMILY_WINDOWS)){
dxCommandPath = sdkDir + '/build-tools/' + buildToolsAvailable[0] + '/dx.bat'
}else if(Os.isFamily(Os.FAMILY_MAC)){
dxCommandPath = sdkDir + '/build-tools/' + buildToolsAvailable[0] + '/dx'
}
}
println "dx command path="+dxCommandPath
commandLine dxCommandPath, '--dex', '--output=build/libs/svrApi.jar', 'build/libs/classes.jar'
} // end of exec
// copy aar to somewhere
copy {
from outputFile
into 'path_to_folder'
} // endo of copy
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment