使用gradle时如何定义apk输出目录? [英] How to define apk output directory when using gradle?
本文介绍了使用gradle时如何定义apk输出目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用gradle时如何定义apk输出目录?
How to define apk output directory when using gradle?
我希望有可能在每次构建后将 apk 上传到共享文件夹.
I would like to have possibility to upload apk to shared folder after each build.
推荐答案
这对我有用:
android.applicationVariants.all { variant ->
def outputName = // filename
variant.outputFile = file(path_to_filename)
}
或 Gradle 2.2.1+
or for Gradle 2.2.1+
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(path_to_filename, output.outputFile.name)
}
}
}
但是clean"任务不会丢弃那个apk,所以你应该按如下方式扩展clean任务:
but "clean" task will not drop that apk, so you should extend clean task as below:
task cleanExtra(type: Delete) {
delete outputPathName
}
clean.dependsOn(cleanExtra)
完整样本:
apply plugin: 'android'
def outputPathName = "D:\\some.apk"
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
applicationVariants.all { variant ->
variant.outputFile = file(outputPathName)
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
task cleanExtra(type: Delete) {
delete outputPathName
}
clean.dependsOn(cleanExtra)
这篇关于使用gradle时如何定义apk输出目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文