I am working with an iOS app which uses both objective-c and swift code. Currently app IPA size became large. Some resources are included but may not be used in Release IPA. I want to find out which resource should be removed and which resource are making my app size increased unnecessarily. I wonder if there is any such tool or xcode profiler to analyze.
So far the best tool I found is https://github.com/tinymind/LSUnusedResources
A Mac App to find unused images and resources in an XCode project. It is heavily influenced by jeffhodnett‘s Unused, but Unused is very slow, and the results are not entirely correct. So It made some performance optimization, the search speed is more faster than Unused.
Use this tool and export unused/unreferenced resource list into unused.txt
Use the below python script to delete references from project.pbxproj file:
file = open("unused.txt","r")
data = [line.rstrip('\n') for line in open("project.pbxproj", 'r')]
newFile = open("project2.pbxproj","w")
def removeLine(imageName):
temp = data
for line_s in temp:
if line_s.find(imageName) != -1:
data.remove(line_s)
else:
continue
for line in file:
if (len(line) > 5):
tokens = line.split("/")
len_a = len(tokens)
imageName = tokens[len_a-1]
removeLine(imageName.rstrip('\n'))
for line in data:
newFile.write(line)
newFile.write('\n')
And an alternative script, in bash:
#!/bin/bash
UNUSED_ASSETS_FILENAME="unused-images.txt"
XCODEPROJ_PATH="zilly.xcodeproj/project.pbxproj"
while read LINE; do
FILENAME="$(basename "$LINE")"
if [[ $FILENAME =~ (png|jpeg|jpg|gif)$ ]]; then
echo "Removing '$FILENAME' references from $XCODEPROJ_PATH"
sed -i '' "/$FILENAME/d" $XCODEPROJ_PATH
fi
done < $UNUSED_ASSETS_FILENAME