Gradle: Exclude file from Android assets folder

≯℡__Kan透↙ 提交于 2019-11-30 03:08:12

It's not possible at the moment.

The packagingOptions feature does not apply to Android resources or assets.

I run into the same problem and it seems adding a "!" works to indicate the file should be excluded:

aaptOptions {
    ignoreAssetsPattern "!myfile.txt" 
}

"assets.exclude" might work also by adding a "!" but I haven't tested it...

I think this should do what you want:

android {
    aaptOptions {
        ignoreAssetsPattern "myfile.txt"
    }
}

Source: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-aapt-options

you can delete a file after build has finished its internal task of merging all assets using groovy task.dolast

so in this case mergeAssets.doLast where mergeAssets is provided inside #android.applicationVariants.all { variant ->

loop give access to few other task too

here i used code to delete a zip file and images folder

tested on Android 3.1.4

hope it helps

android.applicationVariants.all { variant ->

if (variant.buildType.name == 'release') {

    variant.mergeAssets.doLast {
        println("deleting item.zip', 'images/**' from variant")
        delete(fileTree(dir: variant.mergeAssets.outputDir, includes: ['item.zip', 'images/**']))
    }
 }
}

Try this:

export ANDROID_AAPT_IGNORE="ignoreAssetsPatternThatActuallyWorks"
./gradlew assembleDebug

It's the only way to influence the mergeDebugAssets step (code found here).

Filed a bug about this.

lotosbin

just use bash

zip -d xx.jar xxx.txt

to remove duplicated file from jar file

To protect assets folder information If the html file is either css or js, the easiest way is to: Write your code in the html editor first, and then enter it in a Java class as follows :

 public class Content{
    public static final String  myContent ="<!DOCTYPE html> ... </html> "

And then call through the loadDataWithBaseURL method

 webView.loadDataWithBaseURL(null,Content.myContent, "text/html" , "UTF-8" ,null);

And you can call js and css in html code :

 ...
 <head>
 <link rel="stylesheet" type="text/css" 
  href="file:///android_asset/css/custom.css" /> 
 <script src="file:///android_asset/js/code.jquery.js"></script>                                                                                   
</head>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!