gpt4 book ai didi

android-studio - 使用gradle时如何定义apk输出目录?

转载 作者:行者123 更新时间:2023-12-03 12:35:53 25 4
gpt4 key购买 nike

使用gradle时如何定义apk输出目录?

我希望在每次构建后都可以将apk上传到共享文件夹。

最佳答案

多数民众赞成在我的工作:

android.applicationVariants.all { variant ->
def outputName = // filename
variant.outputFile = file(path_to_filename)
}

或适用于Gradle 2.2.1+
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(path_to_filename, output.outputFile.name)
}
}
}

但是“清理”任务不会删除该apk,因此您应该按以下方式扩展清理任务:
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)

关于android-studio - 使用gradle时如何定义apk输出目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22833297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com