iOS Project redundant resource scan script

Source: Internet
Author: User
Tags echo name

iOS Project redundant resource scan script

  

As iOS projects continue to iterate, the number of redundant files in the app grows and the app size continues to grow, and it's time to test the app's redundant resources and thin the app.

How to use:

1. Operating environment for Mac, first prepare the project source code;

2. Create a new check.sh, paste the following code into the check.sh and save; (TXT file can be changed to sh suffix)

#!/bin/SH ##### Several cases that the scripts does not work:#####1) there isSpace or SlashinchThe resources file, such as "AAA. PNG"The resource file name contains spaces or/##### 2) Reference Resourcesinchthe commented Code resource reference is commented #####3) You need to manuallycheckedThe resources one by oneinchThe result for the script check results, it is best to manually check the #####4) You can add some miscellaneous types more than PNG, JPG, GIF, WAV, M4A if you need to check other resources, modify the script yourself; #####5The default file suffix is in the format @2x.png, if the suffix format is different, please modify the script yourself; # # # #SetParameters:prjpath is the directory where the project works, contains the. m. xib file, Respath is the directory of resource files scanned, contains. png. wav#### Xcodeprojpath is the project xcodeproj location Prjpath =/users/....... Respath=/users/... .. xcodeprojpath=/users/.../******.xcodeproj If [-F ~/desktop/resource_san_result.txt];then rm-f ~/desktop/resource_san_result.txtfi cd $Pr jpathfiles=$ (Find-name "*.m"-o-name "*.xib"-o-name "*.mm"-o-name "*.plist") CD $ResPathfor PNG in $ (find.-name "*.png"-o-name "*.jpg"-o-name "*.gif"-o-name "*.wav"-o-name "*.m4a") do basename= ' basename/' $png basename=${ basename##*/} # Echo $basenameif["${basename##*.}"=="PNG"];then Echo $basename|grep-Q @2x.pngif[$?-eq0];then name=${basename%%@2x.png}ElseEcho $basename|grep-Q @3x.pngif[$?-eq0];then name=${basename%%@3x.png}Elsename=${basename%. png} fi fi elif ["${basename##*.}"=="jpg"];then Echo $basename|grep-Q @2x.jpgif[$?-eq0];then name=${basename%%@2x.jpg}ElseEcho $basename|grep-Q @3x.jpgif[$?-eq0];then name=${basename%%@3x.jpg}Elsename=${basename%%. jpg} fi fi elif ["${basename##*.}"=="gif"];then Echo $basename|grep-Q @2x.gifif[$?-eq0];then name=${basename%%@2x.gif}ElseEcho $basename|grep-Q @3x.gifif[$?-eq0];then name=${basename%%@3x.gif}Elsename=${basename%%. gif} fi fi elif ["${basename##*.}"=="wav"];then name=${basename%%. wav} elif ["${basename##*.}"=="M4A" ]; Then name=${basename%%. M4A}Elsename="'fiif[${#name}-GT0];then # # Name=${name%%[0-9]*} CD $PrjPathifgrep-q $name $files; then echo"$png"  isusedElseCD $xcodeprojPathifgrep-q $name project.pbxproj;then echo"$png"  isNot used >> ~/desktop/Resource_san_result.txtElseEcho"$png"  isNot packaged fi fiElseEcho Name isempty fi doneif[-F ~/desktop/Resource_san_result.txt]; Then EchoThe end of the scan. Please see result fromResource_san_result.txtElseEchoThe end of scan, everything isOKFI

3. Set the parameters in the script:

Prjpath is the directory where the project works, including the. M. xib file;

Respath is the directory of resource files that are scanned, including. png. wav;

Xcodeprojpath for engineering xcodeproj position;

For example:

prjpath=/users/zhuquan/documents/secret-develop/Projectrespath=/users/zhuquan/documents/ secret-develop/project/phoenix/Resxcodeprojpath=/users/zhuquan/documents/secret-develop/project/ Phoenix.xcodeproj

4. Execute script check.sh;

5. Finally, the test results, the detection of redundant resources is best to manually check it again.

[Zhuquandemacbook-pro:desktop zhuquan$./check.sh./1. png isused./2. png isused./3. png isused./4. png isused./5. png isused./ajax-loader.gif isNot packaged./sports record. png isNot packagedThe end of scan, everything isOk

Usage Summary:

There are a few things to note in the script use process,

1. If the resource file name contains spaces or/, such as "AAA. png", the resource cannot be detected properly;

2. If the resource file is referenced in the code, but the reference code is commented out, it cannot be successfully detected;

3. For the final script output script check results, it is best to manually check, some resources may not be redundant resources;

4. The resource types supported in the current script are. png. jpg. gif. wav. M4A, and if you need to check other resources, modify the script yourself.

iOS Project redundant resource scan script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.