我正在使用 gradle 构建的应用程序中导入一个 android 库,如下所示:
I'm importing an android library in an application built with gradle, like that:
dependencies {
compile 'com.example:great-lib:0.1-SNAPSHOT'
}
此库仅包含要在 webview 中使用的资产、js、css 和图像,布局如下:
This library contains only assets, js, css and images to be used in a webview, with a layout like that:
assets/
|-> great.css
|-> great.min.js
|-> great.min.js.map
|-> js/
| |-> plop.js
| |-> foo.js
| ...
|-> img/
| ...
js
文件夹包含源文件(用于源映射).我想在调试版本中包含它和 .map
文件,并且在发布版本中只有缩小的 js,但我找不到这样做的方法.
The js
folder contains source files (to be used with source maps). I would like to include it and the .map
file for the debug builds, and have only the minified js in release builds, but I can't find a way to do that.
到目前为止,我已经尝试过:
So far I've tried :
android {
// this doesn't exclude anything
packageOptions {
exclude 'assets/js'
}
buildTypes {
release {
// this does exclude the js folder, but in both release and debug
aaptOptions {
ignoreAssetsPattern "!js"
}
}
}
}
知道我想要的是否可以实现,如果可以,如何实现?
Any idea if what I want is possible to achieve, and if so how?
(我也想过发布两个版本的库(great-lib
和great-lib-debug
),并且在中有依赖debugCompile
和 releaseCompile
,但我宁愿避免这种情况并发布单个版本)
(I've also thought of publishing two versions of the library (great-lib
and great-lib-debug
), and have the dependency in debugCompile
and releaseCompile
, but I'd prefer avoiding that and publishing a single version)
我最终做了以下事情:
android.applicationVariants.all { variant ->
if (variant.name.contains('Release')) {
// exclude source and sourcemap from release builds
def noJsSourceTask = task("delete${variant.name}JsSource", type: Delete) {
delete "${buildDir}/intermediates/assets/${variant.dirName}/js"
delete "${buildDir}/intermediates/assets/${variant.dirName}/great.min.js.map"
}
variant.mergeAssets.finalizedBy noCeJsSourceTask
}
}
它工作正常,但有几件事我不太喜欢:
It works ok, but there are a few things I don't really like:
finalizedBy
),因此它不适用于最新"检查.但这仅适用于发布版本,我更频繁地进行调试finalizedBy
), so it doesn't work well with "up-to-date" checking. But it's only for release builds, I'm doing debug ones more often这篇关于排除发布构建类型的资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!