Where did the code appear in the apk file after installing from Market?

This is a very interesting thing. I have an APK file, com.company.app.apk. When installed to emulator using Eclipse using the following code to get the apk file name:

String fileName = activity.getPackageManager().getApplicationInfo(
    activity.getPackageName(), PackageManager.GET_META_DATA).publicSourceDir;


I get a path 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 on Market and install it on a real device (Android 2.3), the same code returns the path as follows: com.company.app-2.zip

. Please note that the file extension has been changed to .zip and, most importantly, the file size is significantly smaller than the original.

Now, if I transfer these two files to my computer and use WinZip to open them, I found one interesting thing:

The one installed on the Eclipse emulator has the same stuff as me. Namely: code ("com" folder), resource ("res" folder), signature ("META-INF" folder), assets ("assets" folder) and manifest file (AndroidManifest.xml). However, the one installed on the real Market device only has two parts: the resource and the manifest file.

Question: I think that when installing from Market, the .apk file is split into two (or more) files. One file is specified ApplicationInfo.publicSourceDir

which contains only the resource. How can I get the path to another file?

ADDED: I have two versions of the same app, one paid for using the Google Vendor Licensing Service and the other free. The above phenomenon only happens with the paid version. Why?

Bugfix: When I said the "com" folder exists in the installed apk file in the first case, I should be clearer. The code as such, * .java files are not in the "com" folder. Basically, the "com" folder contains only a few junk files that were accidentally left there during the build process. If not for these junk files, I don't think the "com" folder will be there in the first place.


source to share

2 answers

Ok, here is what I found out if it helps someone:

When the Market installs the free version of my application, the apk file is installed on /data/app/com.company.app.apk

, the content of the file is exactly the same as I created it, the same file size, the same.

For the paid version using market vendor licensing, the apk file itself is installed on /data/app-private/com.company.app.apk

. This is the same file as me. However, the resources are fetched and installed in a different file /data/app/com.company.app.zip

, note the file extension. This zip file contains only resources, so it is significantly smaller. But the .apk file /data/app-private

has everything, so the file size is the same as I created it.


always points to a file in / data / app, so it is /data/app/com.company.app.zip

in the case of the paid version and /data/app/com.company.app.apk

for the free version. For the paid version, I got the path from publicSourceDir

, then replaced .app with app-private and replaced .zip with .apk to get the original file.

If I install apk directly to emulator then there is only one file and always installed under / data / app.



I think you are wrong. The market works like this: you select an application and press a button to install it. The market then sends an intent to use the gtalk service to install the application. This service downloads the apk file that you have uploaded to the market and when the installation of that apk is complete. Some changes may occur during installation. It seems to me that the classes.dex file is extracted from the application during installation, and an optimized dex (.odex) is generated from this file and placed in a separate directory. This is why you see the difference in the files.



All Articles