当前位置:网站首页>Apktool tool usage document

Apktool tool usage document

2022-06-26 05:09:00 Light ink CGZ

apktool Tools using documentation

Installation instructions

apktool yes java Language development , What is provided is a jar package , Need to be in java The operating environment is 1.8 above
Input... At the terminal   java -version  Viewing this computer java edition
Mac OS X:

  1. download Mac  Packaging scripts ( Right click , Save Link as apktool ), Note that the file does not have a suffix
  2. download apktool-2(  Find the latest... Here  )
  3. Will download jar Rename it to  apktool.jar
  4. Combine two files ( apktool.jar&apktool ) Move to /usr/local/bin( need root )
  5. Make sure both files are executable (chmod +x)
  6. Try to pass through CLI ( Command line ) function apktool

Introduce

First let's learn apk file , It is a system that contains resources and java Assembly code zip file . Since it is zip file , So we unzip apk What will the file see . Try it and you'll see
classes.dex And other resource files

$ unzip testapp.apk
Archive:  testapp.apk
 inflating: AndroidManifest.xml
 inflating: classes.dex
 extracting: res/drawable-hdpi/ic_launcher.png
 inflating: res/xml/literals.xml
 inflating: res/xml/references.xml
 extracting: resources.arsc

You can try to see  AndroidManifest.xml  file , The display is a pile of , Encrypted gibberish .

P4F0\fnversionCodeversionNameandroid*http://schemas.android.com/apk/res/androidpackageplatformBuildVersionCodeplatformBuildVersionNamemanifestbrut.apktool.testapp1.021APKTOOL

obviously , We can't edit or view the compiled file . So how do we change the content ?

That this is apktool Where it works .

$ apktool d testapp.apk
I: Using Apktool 2.0.0 on testapp.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: 1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
$

AndroidManifest.xml  Look again , Is that familiar . This is not in AS It's the same as the one shown inside !

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android" package="brut.apktool.testapp" platformBuildVersionCode="21" platformBuildVersionName="APKTOOL" />

except XML outside , Such as 9.PNG, Layout file , Strings and other resources , They are also correctly decoded into readable format .

decode ( Decompile )

apktool Besides being able to decode apk Outside , It can also decode jar file , Using parameter d or decode Of , The specific usage is as follows .

//  take foo.jar  Decode to  foo.jar.out  Folder 
$ apktool d foo.jar
//  The execution result is the same as the previous command 
$ apktool decode foo.jar

//  Decompile  apk  file , The generated file is in the... Of the current folder  bar  Catalog 
$ apktool d bar.apk

// -o  Parameter can specify the generated folder directory name 
$ apktool d bar.apk -o baz

Examples of operation :

image.png

build( compile )

It can be seen from the b or build As shown below   Call build options

//  take  foo.jar.out  Folder build to  foo.jar.out/dist/foo.jar  In file 
//  Note the generated  jar  File path 
$ apktool b foo.jar.out
$ apktool build foo.jar.out

//  take bar Folder build apk To  bar/dist/bar.apk  In file 
$ apktool b bar

//  Build the current directory to  ./dist  in 
$ apktool b .

//  take  bar  Folder build to  new_bar.apk  in  ,-o  Options 
$ apktool b bar -o new_bar.apk


//  If you use the wrong file , The following error message appears .
$ apktool b bar.apk
// WRONG: brut.androlib.AndrolibException: brut.directory.PathNotExist: apktool.yml
// Must use folder, not apk/jar file

image.png

Recoiled apk, Cannot directly install and run . Need to sign again , Specific reference  Android Developing documents
We execute the validation command , Check the... In the above example apk, Show app unsigned .

image.png

Manually sign the application from the command line

Here is already ready-made apk file , For in AndroidStudio Use the command line to build apk, Reference resources Build your application from the command line .
There are two options for signing applications from the command line   jarsigner  and apksigner.
Here are google Ways to recommend .
Signature APK , Refer to the following steps to use  zipalign  and  apksigner.

  1. Open the command line ( stay Android Studio in , choice  View > Tool Windows > Terminal ), Then navigate to unsigned APK directory .
  2. Use  zipalign  Align unsigned APK

zipalign -v -p 4 my-app-unsigned.apk my-app-unsigned-aligned.apk

zipalign  You can ensure that all uncompressed data is first aligned with a specific byte relative to the beginning of the file , Designated here 4 Byte alignment . This can reduce the amount of memory used by applications .

image.png

  1. Use  apksigner  Sign your with your private key APK:
apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk
  1. In this case , Use a single keystore file  my-release-key.jks  Private key and certificate signing stored in APK after , With  my-app-release.apk Form output signed APK .
    apksigner  The tool supports other signing options , This includes signing with a separate private key and certificate file APK file , And signed by more than one signatory APK. For more information , see also  apksigner  Reference resources .
    notes : To use  apksigner  Tools , Must install Android SDK Build a revised version of the tool 24.0.3 Or later . You can use  SDK Manager Update this package .

image.png
After executing the command, enter the password corresponding to the signature file , Check again whether the signature is successful .
image.png

  1. verification APK Whether it has been successfully signed , Execute the following command :
apksigner verify my-app-release.apk

Reference resources :
apktool  Official documents

原网站

版权声明
本文为[Light ink CGZ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260505080469.html