Jef*_*eff 3 android android-gradle-plugin
我以为我的google-fu会让我失望,但我不知道如何将版本号添加到我的图书馆项目的输出中。
我正在使用Android Studio(gradle)构建库,并将其包含在其他项目中。我希望能够向文件中添加一个版本,以跟踪给定项目使用的库的版本,因此我希望版本号在生成的.aar中。
我不知道这一点。有指针吗?
重命名com.android.library模块的输出文件与com.android.application模块的输出仅稍有不同。
在com.android.application gradle插件中,您可以放置
android.applicationVariants.all { variant ->
def file = variant.outputFile
variant.outputFile =
new File(file.parent,
file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
}
Run Code Online (Sandbox Code Playgroud)
但是在com.android.library gradle插件中,您可以使用:
android.libraryVariants.all { variant ->
def file = variant.outputFile
variant.outputFile =
new File(file.parent,
file.name.replace(".aar", "-" + defaultConfig.versionName + ".aar"))
}
Run Code Online (Sandbox Code Playgroud)
如果您只想对特定的变体执行此操作,则可以这样:
if(variant.name == android.buildTypes.release.name) {
}
Run Code Online (Sandbox Code Playgroud)
较新 (2.+) Android Gradle 插件版本没有属性variant.outputFile。这对我有用:
android.libraryVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace((".aar"), "-${version}.aar"))
}
}
Run Code Online (Sandbox Code Playgroud)
版本 3 插件不再支持outputFile。这是因为在配置阶段不再创建特定于变体的任务。这导致插件无法预先知道其所有输出,但这也意味着更快的配置时间。请注意,您需要使用all而不是each因为该对象在新模型的配置时不存在。
android.libraryVariants.all { variant ->
variant.outputs.all {
outputFileName = "${variant.name}-${variant.versionName}.aar"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4017 次 |
| 最近记录: |