【发布时间】:2018-02-20 10:57:43
【问题描述】:
我有一个使用 NDK 和 CMake 以及 externalNativeBuild 的 Android Studio 项目。为了减少数据包大小,我有几种不同纹理压缩格式的风格。没有代码更改,即所有生成的 APK 都使用完全相同的代码。
productFlavors {
ETC2 {
manifestPlaceholders = [supportedTexture: "GL_OES_compressed_ETC2_RGB8_texture"]
}
DXT {
manifestPlaceholders = [supportedTexture: "GL_EXT_texture_compression_dxt1"]
}
ATC {
manifestPlaceholders = [supportedTexture: "GL_AMD_compressed_ATC_texture"]
}
//...and list goes on...
}
这在实践中意味着我有一个 Copy 任务,它检查当前的风味并将正确的纹理包复制到 APK 中。 getCurrentFlavor()函数是从How to get current flavor in gradle复制而来的:
task copyTexSD(type: Copy) {
def currentFlavor = getCurrentFlavor()
if(currentFlavor == "etc2") {
from 'bin/tex/ETC2.bin'
}
else if(currentFlavor == "dxt") {
from 'bin/tex/DXT.bin'
}
else if(currentFlavor == "atc") {
from 'bin/tex/ATC.bin'
}
//...
into 'src/main/assets/tex'
}
要构建任何东西,我使用以下批处理命令:
call gradlew clean
call gradlew assembleETC2Release
call gradlew assembleDXTRelease
call gradlew assembleATCRelease
这很好用,但由于某种原因,复制到先前 APK 的纹理包也包含在后续 APK 中,如下所示:
- app-ETC2-release.apk 仅包含 ETC2.bin 文件
- app-DXT-release.apk 包含 DXT.bin 和 ETC2.bin
- app-ATC-release.apk 包含 ATC.bin、DXT.bin 和 ETC2.bin
为什么构建过程包含来自之前 Gradle 任务的资产?如何使构建过程中每个 APK 只有一个纹理文件?
【问题讨论】:
标签: android gradle android-gradle-plugin