Using apkanalyzer
it is possible to find out a multitude of properties from a generated APK / AAB, such as file size, compare with another APK to get the file size delta, etc.
Using this tool I have created several Gradle tasks to:
- get specific dependencies sizes, and sum them to gain insight how big a SDK is;
- get download size of APK, using
apkanalyzer
; - get comparative file size of APK, using
apkanalyzer
, comparatively to an empty app to gain insight of SDK size;
Now, what I really need is to find out is actual install size of an APK. Meaning the storage amount the APK takes once installed on a device. I have found that apkanalyzer
does not provide a solution for this, and don't have the knowledge how to approach this. I don't want to do this manually, but rather has to be automated. Preferably via a Gradle task.
So: how to automate calculating the INSTALL size of an APK preferably using Gradle?
CodePudding user response:
I have developed my own answer.
- Create an AVD using e.g.:
echo no | avdmanager create avd -n <name> -k "system-images;android-30;google_apis;x86" -f
- Run AVD:
emulator -avd <name>
- Be sure to run adbd in root:
adb root
. This is important to retrieve package information. - Install APK on AVD:
adb push <absolute_path_to_apk>
- Get code path of installed APK:
echo $(cut -d "=" -f2- <<< $(adb shell dumpsys package $packageName | grep codePath))
- Use code path value from step 5 to get install size from APK:
adb shell du ${codePath} -h | awk 'FNR == 3' | head -n1 | awk '{print $1;}'
This returns a string value representing the install size of APK on reference device in Mb.