Apktool icon indicating copy to clipboard operation
Apktool copied to clipboard

[BUG] Decode and build apk but crashed when launch it

Open wangnianwu opened this issue 1 year ago • 5 comments
trafficstars

Information

  1. Apktool Version (apktool -version) - latest
  2. Operating System (Mac, Linux, Windows) - Mac
  3. APK From? (Playstore, ROM, Other) - Other
  4. Java Version (java --version) - java 11.0.16

Stacktrace/Logcat

20241008-174553

Steps to Reproduce

  1. apktool d and apktool b
  2. install it by command line ('adb install')
  3. launch it and crashed

Frameworks

If this APK is from an OEM ROM (Samsung, HTC, LG). Please attach framework files (.apks that live in /system/framework or /system/priv-app)

APK

If this APK can be freely shared, please upload/attach a link to it. app-debug.apk.zip please remove the suffix '.zip' from this file name, it's a demo apk.

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything? yes
  2. If you are trying to install a modified apk, did you resign it? yes, install it successfuly, but crashed when launch
  3. Are you using the latest apktool version? yes, clone the latest source code and build it.

wangnianwu avatar Oct 08 '24 09:10 wangnianwu

Well thats odd. If you use it with -s (without sources) does it work? It would suggest smali/baksmali is corrupting the file.

iBotPeaches avatar Oct 08 '24 13:10 iBotPeaches

yes, if I use it with -s and it work.

wangnianwu avatar Oct 09 '24 01:10 wangnianwu

Well thats odd. If you use it with -s (without sources) does it work? It would suggest smali/baksmali is corrupting the file.

@iBotPeaches has any new discoveries

wangnianwu avatar Oct 21 '24 07:10 wangnianwu

@iBotPeaches I have found that cause, here:

// In case we have no resources. We should store the minSdk we pulled from the source opcode api level
if (!mApkInfo.hasResources() && mMinSdkVersion > 0) {
    mApkInfo.setSdkInfoField("minSdkVersion", Integer.toString(mMinSdkVersion));
}

Add a condition likes:

// In case we have no resources. We should store the minSdk we pulled from the source opcode api level
if (!(mApkInfo.hasResources() && mConfig.forceDecodeManifest == Config.FORCE_DECODE_MANIFEST_FULL)
        && mMinSdkVersion > 0) {
    mApkInfo.setSdkInfoField("minSdkVersion", Integer.toString(mMinSdkVersion));
}

If not decode manifest, we can not get minSdkVersion. So build the dex with incorrect minSdkVersion(dex version).

wangnianwu avatar Oct 24 '24 08:10 wangnianwu

@wangnianwu - You are welcome to open a PR with some reasoning. Its tough to follow samples in issues as it might not reflect the present state / context of code around it.

iBotPeaches avatar Oct 26 '24 18:10 iBotPeaches