我正在尝试将自定义任务添加到我的Android项目中,build.gradle以将最终的APK和Proguard复制mapping.txt到另一个目录中.我的任务取决于assembleDevDebug任务:
task publish(dependsOn: 'assembleDevDebug') << {
description 'Copies the final APK to the release directory.'
...
}
Run Code Online (Sandbox Code Playgroud)
Copy根据文档,我可以看到如何使用标准任务类型执行文件复制:
task(copy, type: Copy) {
from(file('srcDir'))
into(buildDir)
}
Run Code Online (Sandbox Code Playgroud)
但这假设您知道要复制的文件的名称和位置.
如何找到作为assembleDevDebug任务一部分构建的APK文件的确切名称和位置?这可以作为财产吗?感觉好像我应该能够将文件声明为我的任务的输入,并将它们声明为assemble任务的输出,但我的Gradle-fu不够强大.
我有一些自定义逻辑将版本号注入APK文件名,所以我的publish任务不能只假设默认名称和位置.
我在Android应用程序项目中使用以下简化配置.
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 20
versionCode 1
versionName "1.0.0"
applicationVariants.all { variant ->
def file = variant.outputFile
def fileName = file.name.replace(".apk", "-" + versionName + ".apk")
variant.outputFile = new File(file.parent, fileName)
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我将Gradle插件更新到v.0.13.0并将Gradle更新到v.2.1.出现以下警告:
WARNING [Project: :MyApp] variant.getOutputFile() is deprecated.
Call it on one of variant.getOutputs() instead.
WARNING [Project: :MyApp] variant.setOutputFile() is deprecated.
Call it on one of variant.getOutputs() instead.
WARNING [Project: :MyApp] variant.getOutputFile() is deprecated.
Call it on one of …Run Code Online (Sandbox Code Playgroud)