批量去除项目中无用的资源文件
来源:互联网 发布:学校网络解决方案 编辑:程序博客网 时间:2024/06/05 05:23
如果项目有添加混淆的时候,打包生成release包的时候,会在项目的app包下app\build\outputs\mapping 中生成如下几个文件
其中resources的文件中是将无用的资源文件压缩之后再打包的,所以虽然添加混淆可以使安装包变小,但是呢,其他无用的资源并没有完全被剔除掉,它还会增大安装包的大小。
我们可以写一个java文件将resource中删除的无用资源的语句复制过来,然后通过io操作删除项目中的文件。
public static void main(String[] args) {
String string = "Skipped unused resource res/drawable-hdpi-v4/discovery_coupon.png: 579 bytes (replaced with small dummy file of size 67 bytes)\n" + "Skipped unused resource res/drawable-hdpi-v4/discovery_daily.png: 769 bytes (replaced with small dummy file of size 67 bytes)\n" + "Skipped unused resource res/drawable-hdpi-v4/discovery_forum.png: 570 bytes (replaced with small dummy file of size 67 bytes)\n" + "Skipped unused resource res/drawable-hdpi-v4/discovery_into.png: 1440 bytes (replaced with small dummy file of size 67 bytes)\n" + "Skipped unused resource res/drawable-hdpi-v4/discovery_quiz.png: 1051 bytes (replaced with small dummy file of size 67 bytes)\n" + "Skipped unused resource res/drawable-hdpi-v4/discovery_registerdomain.png: 1479 bytes (replaced with small dummy file of size 67 bytes)\n" + "Skipped unused resource res/drawable-hdpi-v4/dottedline.png: 114 bytes (replaced with small dummy file of size 67 bytes)\n" + "Skipped unused resource res/drawable-hdpi-v4/my_pushdomain.png: 1340 bytes (replaced with small dummy file of size 67 bytes)\n" + "Skipped unused resource res/drawable-hdpi-v4/mytrade.png: 1219 bytes (replaced with small dummy file of size 67 bytes)\n" + "Skipped unused resource res/drawable-hdpi-v4/publci_type_bg_notchecked.png: 377 bytes (replaced with small dummy file of size 67 bytes)\n" + "Skipped unused resource res/drawable-hdpi-v4/radiogroup_bg.png: 85 bytes (replaced with small dummy file of size 67 bytes)\n" + "Skipped unused resource res/drawable-hdpi-v4/remind_icon.png: 451 bytes (replaced with small dummy file of size 67 bytes)\n" + "Skipped unused resource res/drawable/btn_gray_selector.xml: 580 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/drawable/btn_orange_selector.xml: 580 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/drawable/btn_picture_selector.xml: 580 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/drawable/btn_red_selector.xml: 580 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/drawable/btn_white_selector.xml: 580 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/drawable/radio_vp_position_selector.xml: 580 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/abc_action_bar_up_container.xml: 448 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/abc_action_bar_view_list_nav_layout.xml: 396 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/amoydomain_search.xml: 1132 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/draw_search_activity.xml: 3608 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/layout_couponlist.xml: 1816 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/layout_dianzan.xml: 680 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/layout_editsearch.xml: 1432 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/layout_guidefirst.xml: 488 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/layout_guidefourth.xml: 716 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/layout_guidesecond.xml: 488 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/layout_guidethird.xml: 488 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/layout_messagelist.xml: 3100 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/layout_regdomain1.xml: 644 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/layout/layout_schedulexieyi.xml: 1480 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/abort_ename.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/aprise.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/attention_domain.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/base.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/edit_mobile_bid.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/my_trade.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/nick_name.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/on_sale.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/personal_data.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/recharge.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/treasure_more.xml: 464 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/treasure_search.xml: 464 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/turn_in.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/turn_in_re_add.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/turn_out_detail.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/use_protection.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n" + "Skipped unused resource res/menu/wxentity.xml: 420 bytes (replaced with small dummy file of size 104 bytes)\n"; String[] strings = string.split("\n"); Pattern pattern=Pattern.compile(".*(drawable-hdpi-v4/|drawable/|menu/)(.*):.*"); for (int i=0;i<strings.length;i++){ matcher=pattern.matcher(strings[i]); if (matcher.find()){ list.add(matcher.group(2)); } } tran("项目路径\app\\src\\main\\res",list);
} public static void tran(String path,ArrayList<String> list){ ArrayList<String> strings=list; File file=new File(path); if (file.exists()){ File[] files=file.listFiles(); if (files.length==0){ System.out.println("文件夹为空"); return; }else { for (File file1:files){ if (file1.isDirectory()){ tran(file1.getAbsolutePath(),strings); }else{ for (int i=0; i<strings.size();i++){ if (strings.get(i).equals(file1.getName())){ file1.delete(); strings.remove(i); break; } } } } } } }}
0 0
- 批量去除项目中无用的资源文件
- AndroidStudio去除项目无用的资源
- 利用Android studio 删除项目中无用资源文件
- android lint 去除无用的资源
- 使用AS的lint去除无用资源
- Android项目中如何清理无用的资源文件或代码
- 清除IOS项目中无用的图片资源
- Android 如何找出项目中无用多余的资源
- 清除IOS项目中无用的图片资源
- Android studio清除项目中无用的资源
- 删除iOS工程中无用的资源文件
- Android清除工程中无用的资源文件
- 自动化清理Android中无用的资源文件。
- Android Studio 检查并去除无用资源文件
- 快速清除Andorid项目中无用资源
- 查找android项目中无用资源
- 多方法批量删除Android中无用的资源(更新Android Studio2.1工具)
- 多方法批量删除Android中无用的资源(更新Android Studio2.1工具)
- libgomp.so.1: version `GOMP_4.0' not found 解决办法
- 5-9 集合相似度 (set的运用)
- 网页制作中遇到的一些问题及解决方案
- Qt 的QString类的使用
- 原码、反码、补码和为什么char类型的范围是 -128~+127
- 批量去除项目中无用的资源文件
- 远程控制
- Snmp乱码问题
- picasso和Glide加载图片
- 枚举之熄灯问题
- 目前c语言程序员普遍月收入是多少
- CSS3选择器
- Python设计模式——装饰模式(Decorator)
- 搭建electron开发环境