Monday, November 21, 2011

How to Make configuration changes in apk file 




Decompile apk, make changes, compile and create apk.

Android puts all the resources in binary format under the apk file, and cannot be read by unpacking the apk file. It needs tool to unzip/decompile so that we can read it and if required, we can make some configuration changes and again create the apk with those changes.

In my example, I am updating the VersionName in AndroidManifest.xml file.

Need to follow the below steps - 

  • Setup the apkTool -
    • Download apktool-install-windows-* and apktool* file from http://code.google.com/p/android-apktool/ link.
    • Unpack both these downloaded files into some directory into your local machine (we will refer this location as root directory in our below examples).
    • If you want to use this frequently, set this path into your environment variable, this is not mandatory step.
  • Open command prompt and go to your root path.
  • To decompile your apk, use below command - 
    • apktool d ApkToolTest.apk
Note: Here I have ApkToolTest.apk file which I have created to demo this and copied that apk file into root directory.
Once you run the above command you will see the output like this -

I: Baksmaling...
I: Loading resource table...
I: Loaded.
I: Loading resource table from file: C:\Users\raghvendra\apktool\framework\1.apk
I: Loaded.
I: Decoding file-resources...
I: Decoding values*/* XMLs...
I: Done.
I: Copying assets and libs...

Once this is done, you will see ApkToolTest folder in root directory, with all the resources. 
  • Make the changes into any of the configuration file, In my case, I made the changes in AndroidManifest.xml file and updated the VersionName field.
  • Once you done with all your changes, run the below command to again compile the project and create the apk file again - 
    • apktool b ApkToolTest
The above command will output like below -

I: Checking whether sources has changed...
I: Smaling...
I: Checking whether resources has changed...
I: Building resources...
I: Building apk file...

  • Once that's done you will find the ApkToolTest.apk file having updated resources information You can find the updated apk under dist folder, In my case it is \ApkToolTest\dist\ApkToolTest.apk. You can deploy this updated apk file to any devices, or Market, or any app store.
  • Once you try to install this app onto emulator or any device before releasing to any of the public use, and if you see "INSTALL_PARSE_FAILED_NO_CERTIFICATES" error, then you have to sign your apk. To sign apk follow the below steps - 

No comments:

Post a Comment