删除android工程不再使用的资源文件
来源:互联网 发布:电脑网络维修上门 编辑:程序博客网 时间:2024/04/30 07:42
删除android工程不再使用的资源文件
1.
先cmd调用 lint --check "UnusedResources" /Users/alvin/Documents/workspacenewjuno/Alvin_Android7bug > ~/Downloads/result.txt
2.
printusedLineFrom 方法是打印出来复制到文件里面
removeUnUsedResources() 是删除多余文件
import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.Reader;import java.util.ArrayList;import java.util.HashSet;import java.util.List;import java.util.Set;public class ClearUnUsedResource {public static String RESULT_PATH = "/Users/alvin/Downloads/result.txt";public static String projectDirPath = "/Users/alvin/Documents/workspacenewjuno/Alvin_Android7bug";public static String STRING_PATH = projectDirPath+ "/res/values/strings.xml";public static String colors_PATH = projectDirPath+ "/res/values/colors.xml";public static String layoutDirPath = projectDirPath + "/res/layout";public static String layout_arDirPath = projectDirPath + "/res/layout-ar";public static String drawableDirPath = projectDirPath + "/res/drawable";public static String resDirPath = projectDirPath + "/res";public static void main(String[] args) {/** * 先cmd调用 lint --check "UnusedResources" * /Users/alvin/Documents/workspacenewjuno/CocoVoice_Android7bug > * ~/Downloads/result.txt *///// printusedLineFrom("res/values/strings.xml:", STRING_PATH);// removeUnUsedResources();printusedLineFrom("res/values/colors.xml:", colors_PATH);}private static void printusedLineFrom(String key, String filePath) {Set<Integer> unUsedNums = getUnUsedLineNumFormCheckResult(key,RESULT_PATH);List<String> lines = new ArrayList<String>();try {File file = new File(filePath);Reader reader = new FileReader(file);BufferedReader bf = new BufferedReader(reader);String line = "";lines.add("");while ((line = bf.readLine()) != null) { //lines.add(line);}} catch (Exception e) {e.printStackTrace();}int size = lines.size();String expen = "android.1428972613902";for (int i = 1; i < size; i++) {if (!unUsedNums.contains(i) || lines.get(i).contains(expen)) {System.out.println(lines.get(i));}}}private static Set<Integer> getUnUsedLineNumFormCheckResult(String key,String filePath) {Set<Integer> unUsedNums = new HashSet<Integer>();try {BufferedReader bf = new BufferedReader(new FileReader(filePath));int count = 0;String line = "";while ((line = bf.readLine()) != null) { //if (line.contains(key)) {String[] ss = line.split(":");if (ss != null && ss.length == 4) {int numberline = -1;try {numberline = Integer.parseInt(ss[1]);} catch (Exception e) {}if (numberline > 0) {unUsedNums.add(numberline);}}}}System.out.println("count : " + count);} catch (Exception e) {e.printStackTrace();}return unUsedNums;}public static void removeUnUsedResources() {String resultFilePath = RESULT_PATH;Set<String> drawablepaths = new HashSet<String>();try {BufferedReader bf = new BufferedReader(new FileReader(resultFilePath));String line = "";while ((line = bf.readLine()) != null) { //if (line.contains("UnusedResources")&& !line.contains("res/value")&& !line.contains("appcompat")) {int end = line.indexOf(":");if (end != -1) {String file = projectDirPath + "/"+ line.substring(0, end);new File(file).delete();System.out.println(file);drawablepaths.add(file);}}}} catch (Exception e) {}for (String layoutpath : drawablepaths) {System.out.println(layoutpath);}}}
0 0
- 删除android工程不再使用的资源文件
- android删除未使用的资源文件
- Lint工具去除Android工程里不再需要的资源
- 如何删除xcode项目中不再使用的图片资源
- 如何删除xcode项目中不再使用的图片资源
- 如何删除xcode项目中不再使用的图片资源
- 如何删除xcode项目中不再使用的图片资源
- 如何删除xcode项目中不再使用的图片资源
- 如何删除xcode项目中不再使用的图片资源
- 如何删除xcode项目中不再使用的图片资源
- 使用Lint+python删除Android工程中的冗余资源
- 使用C#工程里的资源文件
- 删除iOS工程中无用的资源文件
- Android删除工程里面无用的代码和资源
- Android Studio删除工程里面无用的代码和资源
- Android Studio删除无用的资源文件
- Android Studio删除无用的资源文件
- Android资源文件的使用
- K-means学习笔记
- MySQL Study之--MySQL工具mysqlshow
- hdoj-2090-算菜价(水题)
- 用CocoaPods做iOS程序的依赖管理
- XCode无法打开
- 删除android工程不再使用的资源文件
- Javascript 多浏览器兼容性问题及解决方案
- 基础总结篇之一:Activity生命周期
- Matlab函数bwmorph
- 关于UIBarButtonItem的一点札记
- 学习ios的网站
- 锦标赛排序
- Difference between HashMap and Hashtable in Java
- hdu3722Card Game 概率dp水题