Go Android App install package apk file decompile and recompile, re-sign

Source: Internet
Author: User

Background Introduction:Recently in the Robotium Automation test, use the Solo.takescreenshot () function to the test process, but this function needs to be tested by the app with <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>Permissions. In the case of only the apk file of the app being tested, modify the apk file suffix named Zip, unzip, modify the Androidmanifest.xml file, delete the Meta-inf folder, re-compress the apk file, then sign it again. But! This article Shejinqiuyuan, the opportunityDecompile, recompile, and re-sign the APK file to modify the Androidmanifest.xml file in the source code. The purpose of this article is to familiarize yourself with the process of decompile, recompile, and re-signing . 1. Download the Apktool, recompile tool, and the jar and Apktool script files that Apktool need to rely on https://code.google.com/p/android-apktool/downloads/list download. Take the Windows user as an example to download the top two files:2. After extracting the downloaded two compressed package, get three files and put it into a folder. For example:
3. Locate cmd in the folder where Apktool.bat is located, and the input apktool.bat will show all parameter explanations.  4. Let's start the process of anti-compilation apk:on the command line, enter apktool.bat d-f <apk file path/apk file > < destination folder > parameter Interpretation D:decompile, anti-compilation-F: Force empty content that already exists in the destination folderFor example: 5. Enter the generated folder, both the assets and RES folders have generated the XML and footage used by the appThe Lib folder contains a cross-compilation libraryThe Smali folder contains the anti-compiled Smali file.and Androidmanifest.xml is exactly what we need to modify (why modify it?). See Background introduction) here, by the way, explain the Odex file and the Dex file. dex File:Dex is the full name of Dalvik VM executes, the Android Dalvik execution program, not Java bytecode but Dalvik bytecode, 16 binary machine instructions. Odex File:The Dex file is optimized for specific models, resulting in optimized Dex files that increase software speed and reduce RAM usage when running software. Smali File:Convert the Dex file into a readable code form and decompile the general format of the file. 6. Add to Androidmanifest.xml<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> 7. Start the re-compilation. Enter Apktool.bat B < decompile folder on the command line >parameter interpretation: B:build, recompileFor example: 8. Go to the target folder, the new build folder and the Dist folder build folder contains the transition files generated by recompiling the build apk file, including Dex files, resource files, etc. dist folder contains the recompile generated APK file 9. The generated APK file cannot be installed directly on the phone. Otherwise, a install_parse_failed_no_certificates error occurs: This error occurs because each installed apk must contain a signature. One of the functions of signing is to verify that the APK installation package is a legitimate installation package. After the anti-compile-modify-recompile process, the generated apk does not contain a signature. During the installation of the APK, the phone does not detect the signature in the APK, so it promptsinstall_parse_failed_no_certificates error. For Android signatures, refer to: http://www.blogjava.net/zh-weir/archive/2011/07/19/354663.html. In a word, the Android signature mechanism does not prevent the APK package from being modified, but the modified re-signature cannot be consistent with the original signature. (except where the private key is owned). 10. Next, we'll have to recompile the APK file to signyou can use Re-sign.jar. Re-sign-jar:https://dl.dropboxusercontent.com/u/5055823/re-sign.jar Double-click to drag the unsigned apk into the UI, and you will be prompted to save the signed apk after a while. (First use requires setting android_home and java_home environment variables)

Go Android App install package apk file decompile and recompile, re-sign

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.