We have an application(with moderate amount of strings) which we translate to 27+ languages. We make 2 builds of the application. These 2 builds only differ in the name of the package. So basically we first do a build of our application with package name lets say com.android.sad.app
and then another one with package name com.android.even.sadder.app
.
We had the chance to test our application on a great variety of Android devices and we have found out that on some devices like Samsung ACE, Samsung Galaxy S or LG Optimus 2x our application can't load/read the resources so even the application icon isn't shown and when the application is started it crashes with android.content.res.Resources.NotFoundException
. On other devices everything is working just fine.
We have found out that if we reduce the overall amount of strings in the resources of the application, our application can successfully run on the above mentioned devices. However we do not think this is the real solution to our problem because the debug build with full strings in resources can be ran on the devices in question.
So my question would be does someone knows what can potentially cause this very strange behavior ?
After some trial and error experimenting we have found out that the problem was with the apk package itself. In our build process we add some files to our application apk right after the build has finished but before signing and aligning the apk file. Originally we were extracting and repackaging the apk with our own tool (which is written in Java and thus using the Java implementation of Zip).
We have noticed that after repackaging the apk with our tool we were able to reduce the size of the apk to half size of the original apk created by the Android build. As we have found out this repackaging was the cause of our problem!
As our experiments have shown if the repacked apk was smaller then ~1.6 Mb, all devices were able to read and work with the newly repacked apk. However if the size of the apk have exceeded ~1.6 Mb the devices (and the emulator) mentioned in this post were not able to correctly read or work with the application apk .
I have been looking around for some specification on the apk file format(which is essentially jar), but I have found nothing that would explain this very odd behavior. So could somebody please clarify why is this strange behavior happening and what are the exact reasons?
Note: from now on we are using the Android aapt tool to insert our files to the package, instead of the tool we have been using and the final apk can be read by all devices
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With