Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
realyukii authored Feb 16, 2024
1 parent 38845f0 commit 6ca8dbf
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ this repo created in order to understand how Android build system actually works

## Manual Build simple hello world APK

```powershell
PS C:\Users\Kyouma\HelloJava> aapt2.exe link --manifest .\AndroidManifest.xml -I "C:\Android\platforms\android-31\android.jar" -o samplebuild.apk
PS C:\Users\Kyouma\HelloJava> javac -bootclasspath "C:\Android\platforms\android-31\android.jar" -source 1.8 -target 1.8 .\src\dom\domain\*.java
PS C:\Users\Kyouma\HelloJava> d8.bat .\src\dom\domain\SayingHello.class --lib "C:\Android\platforms\android-31\android.jar"
PS C:\Users\Kyouma\HelloJava> zip -uj samplebuild.apk classes.dex
PS C:\Users\Kyouma\HelloJava> zipalign.exe -p -f -v 4 .\samplebuild.apk aligned.apk
PS C:\Users\Kyouma\HelloJava> keytool.exe -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000
PS C:\Users\Kyouma\HelloJava> apksigner.bat sign --ks .\debug.keystore --ks-pass pass:android --out signed.apk .\aligned.apk
- since d8 dexer [not support javac 21](https://code2care.org/java-jdk-21/fix-unsupported-major-minor-version-65-0-java-jdk-21/) yet, we need to lower the target and source
- [stackoverflow](https://stackoverflow.com/questions/59895743/replacement-for-bootclasspath-option-in-java), use classpath instead of bootclasspath

```shell
aapt2 link --manifest AndroidManifest.xml -I "C:\Android\platforms\android-31\android.jar" -o samplebuild.apk
javac -classpath "C:\Android\platforms\android-31\android.jar" -source 17 -target 17 src\dom\domain\*.java
d8 src/dom/domain/SayingHello.class --lib "C:\Android\platforms\android-31\android.jar"
zip -uj samplebuild.apk classes.dex
zipalign -p -f -v 4 samplebuild.apk aligned.apk
keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000
apksigner sign --ks debug.keystore --ks-pass pass:android --out signed.apk aligned.apk
```

These command will generate the following output:
Expand All @@ -27,21 +30,21 @@ These command will generate the following output:
`baksmali dis classes.dex`, edit the string on generated `.smali`
add modified dex to repatch the apk:

```
PS C:\Users\Kyouma\HelloJava> smali as ./out/dom/domain/SayingHello.smali -o classes.dex
PS C:\Users\Kyouma\HelloJava> zip -uj samplebuild.apk classes.dex
PS C:\Users\Kyouma\HelloJava> zipalign.exe -p -f -v 4 .\samplebuild.apk aligned.apk
PS C:\Users\Kyouma\HelloJava> apksigner.bat sign --ks .\debug.keystore --ks-pass pass:android --out signed.apk .\aligned.apk
```shell
smali as out/dom/domain/SayingHello.smali -o classes.dex
zip -uj samplebuild.apk classes.dex
zipalign -p -f -v 4 samplebuild.apk aligned.apk
apksigner sign --ks debug.keystore --ks-pass pass:android --out signed.apk aligned.apk
```

## Repatch other apk (telkomsel roli)

```sh
apktool.bat d telkomsel_roli.apk # modify smali stage
apktool.bat b .\telkomsel_roli -o patched_roli.apk
zipalign.exe -p -f -v 4 .\patched_roli.apk aligned_roli.apk
apksigner.bat sign --ks .\debug.keystore --ks-pass pass:android --out final_roli.apk .\aligned_roli.apk # Make sure you've generated the keystore.
adb install .\final_roli.apk # final signed patched aligned apk
```shell
apktool d telkomsel_roli.apk # modify smali stage
apktool b telkomsel_roli -o patched_roli.apk
zipalign -p -f -v 4 patched_roli.apk aligned_roli.apk
apksigner sign --ks debug.keystore --ks-pass pass:android --out final_roli.apk aligned_roli.apk # Make sure you've generated the keystore.
adb install final_roli.apk # final signed patched aligned apk
```

### [Other Link](https://www.facebook.com/permalink.php?story_fbid=pfbid06v2GZ6ctwsWStEkVt9KhYLzc3Gg8sQTpks9jqnFcEpJRKaiWepB45NxH4FbBDSMSl&id=100090321692618)
Expand Down

0 comments on commit 6ca8dbf

Please sign in to comment.