This is a very interesting thing. I have an APK file, com.company.app.apk. When installed to an emulator by using Eclipse, by using the following code to get the apk’s file name:
String fileName = activity.getPackageManager().getApplicationInfo(
activity.getPackageName(), PackageManager.GET_META_DATA).publicSourceDir;
I get a pathname like this com.company.app-1.apk. The file size is the same as the apk file I built.
Now when I publish this app to Market, and install it to a real device (Android 2.3), the same code returned a pathname like this: com.company.app-2.zip. Note that the file extension has changed to .zip and, most importantly, the file size is significantly smaller than the original size.
Now if I transfer these two files to my PC and use WinZip to open them, I found one really interesting thing:
The one installed on emulator by Eclipse has exactly the same stuff as I expected. Namely: the code (‘com’ folder), the resource (‘res’ folder), the signature (‘META-INF’ folder), the assets (‘assets’ folder), and the manifest file (AndroidManifest.xml). However, the one installed on a real device by Market has only two parts: the resource, and the manifest file.
Question: I think when installed from Market, the .apk file is split into two (or more) files. One file is pointed to by ApplicationInfo.publicSourceDir, which contains only the resource. How can I get the pathname to the other file(s)?
ADDED: I have two versions of the same app, one is paid using Google’s Vendor Licensing Service, the other is free. The above mentioned phenomenon happens only to the paid version. Why?
Correction: When I said the ‘com’ folder exists in the installed apk file in the first case, I should be more clear. The code per se, the *.java files, are not in the ‘com’ folder. As a matter of fact, the ‘com’ folder contains only a few garbage files that were inadvertently left there during the build process. If not for those garbage files, I don’t think the ‘com’ folder would be there in the first place.
Ok, here is what I’ve found out, in case this helps someone out there:
When Market installs the free version of my app, the apk file is installed to
/data/app/com.company.app.apk, the file content is exactly the same as I built it, same file size, same everything.For the paid version that uses Market Vendor Licensing, the apk file itself is installed to
/data/app-private/com.company.app.apk. This is the same file as I released. However, the resources are extracted and installed to another file/data/app/com.company.app.zip, note the file extension. This zip file contains only resources, so it’s significantly smaller. But the .apk file in/data/app-privatehas everything, so the file size is the same as I built it.ApplicationInfo.publicSourceDiralways points to the file in /data/app, so it’s/data/app/com.company.app.zipin the paid version’s case, and/data/app/com.company.app.apkfor the free version. For the paid version, I obtained the pathname frompublicSourceDir, then replace.app with app-private, and replace .zip with .apk to get the original file.If I install the apk directly to an emulator, then there is only one file and is always installed under /data/app.