IOS IPA Pack Slimming---Delete useless picture resources

Source: Internet
Author: User

with the increase in client services and business updates, the size of the app package is getting bigger, the optimization of the package size is imminent, the client needs to optimize the place there are many, this issue is mainly about how to find useless pictures and delete useless pictures method. Scenario 1: (Brute force method) It's very simple to write a script to find the name of the picture under the whole project, which means that the picture is useless. (This is possible for small projects, but too slow for project-wide projects). Scenario 2: All the assignment statements are extracted into a file, and then the project below the name of the image to be found in this file, if not found that the picture is a useless resource. As the pictures in the project are all placed under the Images.xcassets folder. The following script is looking for useless images under the Images.xcassets directory. If the picture file is not placed in the Images.xcassets folder, a slight modification of the script can be used, the following script to delete useless pictures of the same idea applies to Android engineering.
#!/bin/shProgramfilepath=$ (CD"$ (dirname"$")"; pwd) Unusedcount=0maybeUnusedCount=0if[[ -Z $programFilePath]]; Thenread-P"Please enter the path of the project"Programfilepathficheck_files= ' Find $programFilePath-name'*.xib'-o-name'*.storyboard'-o-name'*. [MH]'-o-name'*.pch'-o-name'*.java'-o-name'*.xml'-o-name'*.js'-o-name'*.html'` forFileinch' Echo $check _files | Sed's/\n//g'' do#iOS picture reference rule: Get the @ sign statementGrep-i"@\""-A 0"$file"| Grep-v-E"--">>maybeImageSentence.txt Doneimagetextpath="$programFilePath/maybeimagesentence.txt"Maybeunusedimagefilepath="$programFilePath/maybeunusedimage.txt"if[-F"$maybeUnusedImageFilePath" ]; Then RM-F"$maybeUnusedImageFilePath"Fiunusedimagefilepath="$programFilePath/unusedimage.txt"if[-F"$unusedImageFilePath" ]; Then RM-F"$unusedImageFilePath"fi forPnginch' Find $programFilePath-name'*.png'' do#Picture nameMatch_name=' basename $png ' suffix1="@2x.png"suffix2=". 9.png"suffix3=". PNG"suffix4="@3x.png"    if[[${match_name/${suffix1}//}! =$match _name]]; Then Match_name=${match_name%$suffix 1}elif[[${match_name/${suffix4}//}! =$match _name]]; Then Match_name=${match_name%$suffix 4}elif[[${match_name/${suffix2}//}! =$match _name]]; Then Match_name=${match_name%$suffix 2}ElseMatch_name=${match_name%$suffix 3} fi dir_name=' dirname $png 'if[[$dir _name =~ bundle$] | | [[$dir _name =~ appiconset$] | | [[$dir _name =~. launchimage$]]; ThenContinuefi#look inside the ImageSet .result=$ (echo $dir _name | grep"ImageSet")    if[["$result"=="" ]]; ThenContinueFi referenced=falseifGrep-q"$match _name" "$imageTextPath"; then referenced=true fi contat=$ (echo $match _name | grep"[0-9]")    if[["$contaT"!="" ]]; Then Maybeunusedcount= ' Expr $maybeUnusedCount + 1' echo"$png">>MaybeUnusedImage.txtContinuefiif! $referenced; then Unusedcount= ' Expr $unusedCount + 1' echo"$png">>UnusedImage.txt#Open the following statement to delete the picture directory directly such as Icon_arrow_bluesmall.imageset#rm-rf $dir _namefidonerm Maybeimagesentence.txtecho"Total $unusedCount unusedimage files->imagepath store UnusedImage.txt"Echo"Total $maybeUnusedCount maybeunusedimage files->imagepath store MaybeUnusedImage.txt"

How to use: first copy the above code to a file named unused-image.sh, put this file under the target project to execute the SH unused-image.sh command. Generates two files unusedImage.txt and MaybeUnusedImage.txt.

The disadvantage of scenario 2 is that you cannot determine whether a picture name with a number cannot be determined if it is a useless resource slice name called [email protected], such a named picture output to maybeUnusedImage.txt this file, need to manually remove.

Original articles, welcome reprint, Reproduced please mark, thank you all!!!!!!!

Original articles, welcome reprint, Reproduced please mark, thank you all!!!!!!!

Original articles, welcome reprint, Reproduced please mark, thank you all!!!!!!!

================================================================

If you have any questions, please add my qq:610774281:stephenli225. Together to explore progress together ....

IOS IPA Pack Slimming---Delete useless picture resources

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.