//根路徑
def ROOT_PATH = rootProject.rootDir.path
def GROUP = "com.genialsir.mobileads"
def MOB_SDK_VERSION_NAME = "1.1.2"
複製代碼
//自定義aar名稱
android.libraryVariants.all {
variant ->
variant.outputs.all {
def fileName = GROUP + "." + MOB_SDK_VERSION_NAME + ".aar"
outputFileName = fileName
}
}
複製代碼
使用gradle -b **(表明當前Project或Module目錄名)/build.gradle aarRelease
複製代碼
//生成對應目錄
task makeLibDir() {
def outputPath = ROOT_PATH + '/aar_release'
//腳本指定路徑
if(project.hasProperty('OUT_PUT_DIR_PATH')){
outputPath = "${OUT_PUT_DIR_PATH}"
}
//建立aar所輸出的目錄
createDir(outputPath)
}
複製代碼
def createDir = {
path ->
File dir = new File(path)
if (!dir.exists()) {
dir.mkdirs()
}
println "Generate the corresponding directory path is" + dir.toString()
}
複製代碼
task copyAAR(type: Copy) {
println "----------> ARR copy start <-----------"
def buildPath = ROOT_PATH + '/containerad/build/outputs/aar'
//AAR所在的編譯路徑
from buildPath
//AAR所拷貝的目錄
def outputPath = ROOT_PATH + '/aar_release'
println "outputPath = " + outputPath
into outputPath
println "----------> ARR copy succeeded <-----------"
}
複製代碼
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(copyAAR)
}
複製代碼
task aarRelease(type: Copy) {
//任務開始
println "----------> AAR Release Task Start <----------"
//AAR所在的編譯路徑
def buildPath = ROOT_PATH + '/containerad/build/outputs/aar'
//AAR輸出路徑
def aarOutPath = ROOT_PATH + "/aar_release"
//廣告的SDK
def adPath = buildPath + GROUP + "." + MOB_SDK_VERSION_NAME + ".aar"
//封裝數組
def modulePaths = [adPath]
//刪除AAR輸出目錄
println "Delete -> " + aarOutPath
delete aarOutPath
//循環刪除各個AAR編譯目錄
for (path in modulePaths) {
println "Delete -> " + path
delete path
}
//執行編譯AAR腳本(原生腳本)
dependsOn 'assembleRelease'
//循環拷貝AAR到ARR輸出目錄
for (path in modulePaths) {
//顯示開始拷貝
println "-> Start of current copy <-"
//當前目錄
println "From : " + path
from path
//拷貝至 aarOutPath
println "Into : " + aarOutPath
into aarOutPath;
//顯示當前拷貝結束
println "-> End of current copy <-"
}
//任務結束
println "----------> AAR Release Task End <----------"
}
複製代碼
####先來張最近奧迪漏油事件皮一波,免費打打廣告 android
//自定義aar名稱
android.libraryVariants.all {
variant ->
variant.outputs.all {
def fileName
if (!project.hasProperty('OUT_PUT_AAR_VERSION_SUFFIX')) {
fileName = GROUP + "." + MOB_SDK_VERSION_NAME + ".aar"
}else{
fileName = GROUP + "." + "${OUT_PUT_AAR_VERSION_SUFFIX}.aar"
}
outputFileName = fileName
}
}
複製代碼
使用默認路徑命令執行(gradle -b containerad/build.gradle aarRelease)
腳本指定版本號與對應目錄(gradle assemble -P OUT_PUT_AAR_VERSION_SUFFIX=1.1.2 -P OUT_PUT_DIR_PATH=H:\AndroidProject\ADPlugIn\OnlyLadyAD\ad_release_path aarRelease)
複製代碼
經過協定好的OUT_PUT_DIR_PATH與OUT_PUT_AAR_VERSION_SUFFIX來控制版本號與路徑。git
task aarRelease(type: Copy) {
//任務開始
println "----------> AAR Release Task Start <----------"
//執行編譯AAR腳本(原生腳本)
dependsOn 'assembleRelease'
//AAR所在的編譯路徑
def buildPath = ROOT_PATH + '/containerad/build/outputs/aar/'
//AAR輸出默認路徑
def aarOutPath = ROOT_PATH + '/aar_release'
//腳本指定路徑
if(project.hasProperty('OUT_PUT_DIR_PATH')){
aarOutPath = "${OUT_PUT_DIR_PATH}"
}
//廣告的SDK
def adPath
if (!project.hasProperty('OUT_PUT_AAR_VERSION_SUFFIX')) {
//默認版本
adPath = buildPath + GROUP + "." +
MOB_SDK_VERSION_NAME + ".aar"
}else{
//腳本指定版本
adPath = buildPath + GROUP + "." + "${OUT_PUT_AAR_VERSION_SUFFIX}.aar"
}
//封裝數組
def modulePaths = [adPath]
//當前AAR輸出目錄
println "The current aar output directory is " + aarOutPath
delete aarOutPath
//循環刪除已存在的aar
for (path in modulePaths) {
println "Delete ---> " + path
delete path
}
//循環拷貝AAR到ARR輸出目錄
for (path in modulePaths) {
//顯示開始拷貝
println "-> Start of current copy <-"
//當前目錄
println "From : " + path
from path
//拷貝至 aarOutPath
println "Into : " + aarOutPath
into aarOutPath;
//顯示當前拷貝結束
println "-> End of current copy <-"
}
dependsOn 'assembleRelease'
//任務結束
println "----------> AAR Release Task End <----------"
}
複製代碼