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.
-
I don't know if there's any tool but you can extract your exported .ipa and check its content in finder – Kubba Apr 26 '17 at 11:56
-
see this https://github.com/onevcat/FengNiao?utm_campaign=iOS%2BDev%2BWeekly&utm_medium=web&utm_source=iOS_Dev_Weekly_Issue_295 – Prashant Tukadiya Apr 26 '17 at 12:43
3 Answers
So far the best tool I found is https://github.com/tinymind/LSUnusedResources
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.
Export unused resource list
Use this tool and export unused/unreferenced resource list into unused.txt
Remove references from Xcode .pbxproj file
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

- 8,350
- 16
- 53
- 95

- 37,929
- 33
- 189
- 256
-
Why not simply hit the handy "Delete" button in the app itself (skipping the python script)? – Roger Oba Aug 20 '20 at 06:01
-
Nevermind, I got it. When I posted, I had compiled the app just fine but probably because it was using cached build info. On CI the build failed because Xcode was referencing a single file that was being accessed from bundle instead of as an xcasset. Turns out I gave a try to the script above (probably posted 3 years ago), but it didn't work for me. So I ended up writing my own bash script for this. I'll suggest an edit to the the answer to include the bash script alternative :) – Roger Oba Aug 20 '20 at 06:54
First of all, are you using the latest Xcode version? Xcode 8.3 produces binaries 2-3 times larger than Xcode 8.2, and Apple fixed this bug in 8.3.1.
Also, you can check out On Demand Resources, which will let you upload your heavy assets to App Store, but not bundled within the app - and when the user will download your app, iOS will automatically download necessary assets for properly running the app.
You can change the .ipa
file to have the .zip
extension and unpack it. You later on can use simple inspection (Disk Inventory X for instance) of the unarchived .zip
file and
see what's going on there.
Also, it is probable that you're looking at a App Store Submission .ipa
, which will contain necessary dSYM
files and other miscellaneous data.
You can check what App Store .ipa
sizes for different devices the app will have by following steps in this answer.
And last but not least, check out this Q&A by Apple on reducing the size of your app.
-
Thanks for your answer. I am using Xcode 8.3.1. I have already went through the app size reducing guide. My main purpose is to remove unused and non references resource and codes from IPA. Wondering if there is any way. – Sazzad Hissain Khan Apr 27 '17 at 03:24
-
The link for "_On Demand Resources_" says: "_This document is no longer being updated._" – Cœur Aug 03 '18 at 04:23
Recommend an effective tool to analysis App Size:
Advantages:
- Directly measure the size of .a or .framework after linking, no need to compile again and again.
- Clearly show the differences between two versions,helping you to control the increasing size.
- Effectively detect unused Code (ObjC & Swift)
- Widely used in apps of Wuba inc.

- 3,208
- 9
- 22
- 33

- 11
- 1