我想在Android Studio中创建gradle任务,该任务将对另一个项目的build任务的输出进行某些操作
task foo {
dependsOn ':someApp:build'
...
copy results of :someApp:build to another location
...
}
我不能仅仅对路径进行硬编码,因为我不知道someApp
是作为debug
还是release
构建的,并且输出路径会根据构建的类型而变化。
答案 0 :(得分:0)
不使用硬编码路径的动态复制任务。
applicationVariants.all {
variant->
variant.outputs.each { output ->
println("..a")
task "copy${variant.buildType.name}"(type:Copy){
println("${variant.buildType.name}")
dependsOn app:assembleDebug
copy {
from "$buildDir\\outputs\\apk\\${variant.buildType.name}\\app-${variant.buildType.name}.apk"
into "C:\\Users\\rkumar8\\AndroidStudioProjects\\MyApplication\\app\\build\\outputs\\apk\\"
}
// you can add multiple copy if required, i am doing it here release build was named app-release-unsigned.apk
copy {
from "$buildDir\\outputs\\apk\\${variant.buildType.name}\\app-${variant.buildType.name}-unsigned.apk"
into "C:\\Users\\rkumar8\\AndroidStudioProjects\\MyApplication\\app\\build\\outputs\\apk\\"
}
}
}
}
答案 1 :(得分:-1)
我在应用模块的build.gradle的android块中添加了一个任务。
applicationVariants.all {
variant->
variant.outputs.each { output ->
println("..a")
task "copy${variant.buildType.name}"(type:Copy){
println("${variant.buildType.name}")
dependsOn app:assembleDebug
copy {
from "$buildDir\\outputs\\apk\\${variant.buildType.name}\\app-${variant.buildType.name}.apk"
into "C:\\Users\\rkumar8\\AndroidStudioProjects\\MyApplication\\app\\build\\outputs\\apk\\"
}
// you can add multiple copy if required, i am doing it here release build was named app-release-unsigned.apk
copy {
from "$buildDir\\outputs\\apk\\${variant.buildType.name}\\app-${variant.buildType.name}-unsigned.apk"
into "C:\\Users\\rkumar8\\AndroidStudioProjects\\MyApplication\\app\\build\\outputs\\apk\\"
}
}
}
}