Coder Social home page Coder Social logo

hcq0618 / android-cleanresources Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 2.0 57 KB

批量删除无用资源 Batch remove unused resources

License: MIT License

Python 100.00%
android java lint clean-code clean-resources resources python matrix gradle gradlew

android-cleanresources's Introduction

Android-CleanResources

当项目越来越大时,无用资源可能会越来越多 如果每个都是手动删除,不但可能删错,查找和删除文件也很麻烦, 所以需要一个脚本工具来批量删除用工具(Lint、Matrix等)分析出的无用资源

As the project gets bigger, there may be more and more unused resources, If each is manually deleted, not only might it be wrong to delete, but also to find and delete files is very troublesome, Therefore, a script tool is needed to batch remove some tools(Lint or Matrix,etc.) analysis of unused resources


环境: python2.7


clean_res.py

  • 使用前先clean工程,确保工程bin下重新生成dex,以便lint进行分析。

  • 修改配置文件clean_lint_config.json中的路径即可使用,其中:

    projectPath:项目路径

    lintPath:Android SDK目录中lint命令行的路径,一般为Android SDK目录下tools目录中

    keepFilePathKeys:需要保留不删除的文件目录集合,默认保留Android项目中values目录下的资源,支持自定义添加

  • At first clean your project

  • Modify the content of 'clean_lint_config.json' file,including:

    projectPath:your project directory path

    lintPath:the lint comand file path in Android SDK directory,and generally, it is in the tools directory under the Android SDK directory

    keepFilePathKeys: You want to keep an undeleted collection of file directories. By default, the resources under values directory in the Android project are keeped.Support custom add


clean_res_for_gradle.py

修改配置文件clean_lint_config.json中的路径即可使用,其他同上,另外还包括:

Modify the content of 'clean_lint_config.json' file,other same as above, also include additionally:

moduleName:主模块名称,默认为app

moduleName:Main module name, default is 'app'


clean_res_for_matrix.py

针对Matrix分析结果进行无用资源的批量清理

For Matrix analysis results are unused resources batch cleaning

修改配置文件clean_lint_config.json中的路径即可使用,其他同上,另外还包括:

Modify the content of 'clean_lint_config.json' file,other same as above, also include additionally:

matrixJsonResultPath:matrix分析结果,json为后缀的文件

matrixJsonResultPath:Matrix analysis results, json for the suffix of the file

libPaths:依赖库的路径

libPaths:the paths of dependency library


说明:

  • 可利用cxFreeze、py2exe、pyInstaller等工具将py文件打包转成exe执行文件

    You can use cxFreeze, py2exe, pyInstaller and other tools to package py files and turn them into exe executables

  • 如果清除资源后,工程缺少文件而报错(极少情况),尝试通过svn/git恢复该文件即可

    If the project reports an error (in rare cases) due to a lack of files after clearing resources, try to restore the file through SVN /Git

  • 也可以选择在Android Studio中使用 Menu > Refactor > Remove Unused Resources

    Alternatively, you can also use Menu > Refactor > Remove Unused Resources in Android Studio

  • 也可以选择在gradle中配置

    You can also add the configuration in gradle

     android {
             ...
    
             buildTypes {
                 release {
                     minifyEnabled true
                     shrinkResources true
                 }
        }

License

MIT License

Copyright (c) 2017 Hcq

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

android-cleanresources's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

vikingden

android-cleanresources's Issues

能否扩展以下功能

目前这个版本的功能,只能能够查找和删除文件。能否扩展以下功能:
1.删除无用的layout文件。
2.删除无用的标签,例如strings.xml里面的string标签,或者其他例如color之类的标签。
3.过滤范围扩大。例如strings.xml文件里面,以开始,以结尾,即使是多余的,也不进行删除。
4.以正则表达式(regular expression)为过滤规则。

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.