iBotPeaches / Apktool

A tool for reverse engineering Android apk files
https://apktool.org/
Apache License 2.0
20.16k stars 3.58k forks source link

Android Lollipop support #763

Closed iBotPeaches closed 9 years ago

iBotPeaches commented 9 years ago

Original issue 653 created by derp.indonesia on 2014-07-07T04:59:17.000Z:

What steps will reproduce the problem?

  1. Decompile any apk from Android L system dump or installing the framework of Android L itself

What is the expected output? What do you see instead?

I see the same error like HTC resources (I hope this won't be pain in the ass to fix). Log :

Exception in thread "main" brut.androlib.AndrolibException: Multiple resources: spec=0x01030128 style/Theme.DeviceDefault, config=[DEFAULT] at brut.androlib.res.data.ResConfig.addResource(ResConfig.java:63) at brut.androlib.res.data.ResConfig.addResource(ResConfig.java:56) at brut.androlib.res.decoder.ARSCDecoder.readEntry(ARSCDecoder.java:193) at brut.androlib.res.decoder.ARSCDecoder.readConfig(ARSCDecoder.java:162) at brut.androlib.res.decoder.ARSCDecoder.readType(ARSCDecoder.java:128) at brut.androlib.res.decoder.ARSCDecoder.readPackage(ARSCDecoder.java:103) at brut.androlib.res.decoder.ARSCDecoder.readTable(ARSCDecoder.java:81) at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:49) at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:40) at brut.androlib.res.AndrolibResources.installFramework(AndrolibResources.java:675) at brut.androlib.Androlib.installFramework(Androlib.java:641) at brut.apktool.Main.cmdInstallFramework(Main.java:252) at brut.apktool.Main.main(Main.java:91)

What version of the product are you using? On what operating system?

2.0.0 b9 and 1.5.3, running Ubuntu 13.04 and Windows (none of them works)

Please provide any additional information below.

iBotPeaches commented 9 years ago

Comment #1 originally posted by connor.tumbleson on 2014-07-07T13:59:38.000Z:

Yep confirmed. First bug report here about that

http://forum.xda-developers.com/google-nexus-5/help/apktool-android-l-preview-t2796555

My response: http://forum.xda-developers.com/showpost.php?p=53824583&postcount=2375

iBotPeaches commented 9 years ago

Comment #2 originally posted by connor.tumbleson on 2014-07-24T18:40:43.000Z:

Issue 659 has been merged into this issue.

iBotPeaches commented 9 years ago

Comment #3 originally posted by connor.tumbleson on 2014-08-03T03:46:48.000Z:

Changes to 9patch: https://github.com/android/platform_frameworks_base/commit/6381dd4ff212a95be30d2b445d40ff419ab076b4

Open source L Google apk: https://github.com/google/iosched/tree/master/android/src/lpreview

iBotPeaches commented 9 years ago

Comment #4 originally posted by connor.tumbleson on 2014-08-12T12:15:22.000Z:

Issue 668 has been merged into this issue.

iBotPeaches commented 9 years ago

Comment #5 originally posted by connor.tumbleson on 2014-09-01T23:30:01.000Z:

Issue 676 has been merged into this issue.

iBotPeaches commented 9 years ago

Comment #6 originally posted by connor.tumbleson on 2014-10-02T19:14:14.000Z:

<empty>

iBotPeaches commented 9 years ago

Comment #7 originally posted by sonia@malhotraz.com on 2014-10-07T11:36:52.000Z:

Just as an experimental hack, I commented the exception in ResConfig.java(line number 63) and ResResSpec.java (Line number 112) and now it works for me.

Built the apktool.jar file.

Command used: java -jar apktool.jar d -f framework-res.apk Output: I: Using Apktool 2.0.0-dirty on framework-res.apk I: Loading resource table... I: Loading resource table... I: Decoding AndroidManifest.xml with resources... I: Regular manifest package... I: Decoding file-resources... I: Decoding values XMLs... I: Copying assets and libs... I: Copying unknown files... I: Copying original files...

I used framework-res.apk from Android L project. Also tried few other APKs from L, they all seem to work fine now.

Obviously this is not the right fix, but just wanted to share this update.

iBotPeaches commented 9 years ago

Comment #8 originally posted by shouvik.dey3993 on 2014-10-07T11:39:59.000Z:

Could you please email me the hacked version? Thank You. shouvik.dey3993@gmail.com

iBotPeaches commented 9 years ago

Comment #9 originally posted by connor.tumbleson on 2014-10-10T02:43:27.000Z:

<empty>

iBotPeaches commented 9 years ago

Comment #10 originally posted by connor.tumbleson on 2014-10-16T13:21:35.000Z:

The duplicate wrongly identified resource is as follows

  config uiModeType=0-v8:
    resource 0x01030128 android:style/Theme.DeviceDefault: <bag> (PUBLIC)

uiModeType=0 is an actual qualifier, which I've never seen before. However aapt d configurations confirms it.

ibotpeaches@raganok:~/Downloads/Apktool/Bug653$ aapt d configurations android-l.jar
large-v4
television-v8
uiModeType=0-v8
... etc

There is also another strange qualifier "450mccko". You can pull 450mcc out which is a known qualifier, but this random "ko" at end makes no sense. These qualifiers are then ignored and fall into the [DEFAULT] config, which obviously already has that ResSpec thus duplicate error occurs.

I'm hoping the release of Android Lollipop source tomorrow explains this. We can get a patch out quickly then. I will be pulling down the source as soon as possible and building new aapt binaries for all platforms.

Basically, hold tight. I think we can solve this easy tomorrow.

iBotPeaches commented 9 years ago

Comment #11 originally posted by connor.tumbleson on 2014-10-17T19:07:04.000Z:

Okay the source dropped help. This has been fixed.

I need to make new aapt binaries to enable recompiling of these apks. However, I'm not yet seeing a tag or branch for Lollipop.

The instant this comes out, I will bundle those platform aapts (mac, linux, win) into Apktool and release a build.

I will close this bug and others when this is completed.

iBotPeaches commented 9 years ago

Comment #12 originally posted by flex360 on 2014-10-17T20:35:29.000Z:

can you put up the apktool.jar file for those of us who are waiting for that file only?

iBotPeaches commented 9 years ago

Comment #13 originally posted by dankoman30 on 2014-10-17T21:04:46.000Z:

Can't you compile it yourself? It's so easy. If you know how to use apktool, then you should have no problem compiling it.

iBotPeaches commented 9 years ago

Comment #14 originally posted by dankoman30 on 2014-10-17T21:09:42.000Z:

Aapt binaries are part of apktool.jar

iBotPeaches commented 9 years ago

Comment #15 originally posted by ryanreycorpin18 on 2014-10-19T04:52:56.000Z:

I've tried decompiling Settings.apk, SystemUI.apk and Calculator.apk from the Android L project and apktool did it. But when I tried the GoogleDialer.apk, GoolgeContacts.apk and framework-res.apk, the same issue appears. What to do?

iBotPeaches commented 9 years ago

Comment #16 originally posted by raziel23x on 2014-10-19T13:28:10.000Z:

well did you do the needed setups

apktool if framework-res.apk apktool if SystemUI.apk HTC FILES apktool if com.htc.resources.apk apktool if com.htc.resources.apk

and depending on the system you might need to install others

iBotPeaches commented 9 years ago

Comment #17 originally posted by raziel23x on 2014-10-19T13:30:23.000Z:

instructions from following here

https://code.google.com/p/android-apktool/wiki/FrameworkFiles

iBotPeaches commented 9 years ago

Comment #18 originally posted by Milosz.Lewandowski on 2014-10-27T11:01:42.000Z:

Looks like work has been done and everything works fine? Could we expect rc3 or something in the coming days?

iBotPeaches commented 9 years ago

Comment #19 originally posted by connor.tumbleson on 2014-10-27T11:36:34.000Z:

Not till AOSP Lollipop is released. I need the changes in aapt so I can fix rebuilding for it and also implement # 688.

iBotPeaches commented 9 years ago

Comment #20 originally posted by moshe.island on 2014-10-27T18:55:29.000Z:

Can you please email me the hacked version till formal one is out? Thanks in advance. My email is moshe.island@gmail.com

iBotPeaches commented 9 years ago

Comment #21 originally posted by connor.tumbleson on 2014-10-27T19:20:28.000Z:

I'm deleting all comments asking for a "hacked" version. This a bug tracker not a support forum for collecting unofficial builds. You can safely decode Android Lollipop apks with the current codebase. If you wish to do that, you can pull down the source and build it.

These two commits added that support https://github.com/iBotPeaches/Apktool/commit/99c1ab96da39d7c145552167423d4ca2a1d85291 https://github.com/iBotPeaches/Apktool/commit/5bc76f197f9f5d93caede056e12ee6814c39efff

(Note there was an internal framework update so deleting the framework at $HOME/apktool/framework/1.apk is required)

You however cannot recompile Lollipop apks after decode as AAPT source is not yet available. This bug report will be closed when decode / build works again on Lollipop. Shortly after an official release of RC3 will come with those changes.

iBotPeaches commented 9 years ago

Comment #22 originally posted by chernogaev on 2014-10-29T12:11:11.000Z:

Managed to decompile an app for translation, using Lollipop features with your framework from here http://connortumbleson.com/apktool/frameworks/google-frameworks.apk

Cannot recompile it even if I do not touch anything inside:

c:\AndroidMultitool\Decompiled_apk\BetterBatteryStats_xdaedition_2.0.0.0B2\res\layout\abc_screen_toolbar.xml:5: error: No resource identifier found for attribute 'touchscreenBlocksFocus' in package 'android' c:\AndroidMultitool\Decompiled_apk\BetterBatteryStats_xdaedition_2.0.0.0B2\res\drawable\abc_cab_background_top_material.xml:2: error: No resource identifier found for attribute 'paddingMode' in package 'android' Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [C:\Users\Dmitriy\AppData\Local\Temp\brut_util_Jar_2317141327971076929.tmp, p, --forced-package-id, 127, --min-sdk-version, 8, --target-sdk-version, 21, --version-code, 50, --version-name, 2.0.0.0B2, -F, C:\Users\Dmitriy\AppData\Local\Temp\APKTOOL5399110314482122704.tmp, -0, arsc, -I, C:\Users\Dmitriy\apktool\framework\1.apk, -S, c:\AndroidMultitool\Decompiled_apk\BetterBatteryStats_xdaedition_2.0.0.0B2\res, -M, c:\AndroidMultitool\Decompiled_apk\BetterBatteryStats_xdaedition_2.0.0.0B2\AndroidManifest.xml] at brut.androlib.Androlib.buildResourcesFull(Androlib.java:435) at brut.androlib.Androlib.buildResources(Androlib.java:363) at brut.androlib.Androlib.build(Androlib.java:286) at brut.androlib.Androlib.build(Androlib.java:258) at brut.apktool.Main.cmdBuild(Main.java:236) at brut.apktool.Main.main(Main.java:88) Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [C:\Users\Dmitriy\AppData\Local\Temp\brut_util_Jar_2317141327971076929.tmp, p, --forced-package-id, 127, --min-sdk-version, 8, --target-sdk-version, 21, --version-code, 50, --version-name, 2.0.0.0B2, -F, C:\Users\Dmitriy\AppData\Local\Temp\APKTOOL5399110314482122704.tmp, -0, arsc, -I, C:\Users\Dmitriy\apktool\framework\1.apk, -S, c:\AndroidMultitool\Decompiled_apk\BetterBatteryStats_xdaedition_2.0.0.0B2\res, -M, c:\AndroidMultitool\Decompiled_apk\BetterBatteryStats_xdaedition_2.0.0.0B2\AndroidManifest.xml] at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:470) at brut.androlib.Androlib.buildResourcesFull(Androlib.java:416) ... 5 more Caused by: brut.common.BrutException: could not exec command: [C:\Users\Dmitriy\AppData\Local\Temp\brut_util_Jar_2317141327971076929.tmp, p, --forced-package-id, 127, --min-sdk-version, 8, --target-sdk-version, 21, --version-code, 50, --version-name, 2.0.0.0B2, -F, C:\Users\Dmitriy\AppData\Local\Temp\APKTOOL5399110314482122704.tmp, -0, arsc, -I, C:\Users\Dmitriy\apktool\framework\1.apk, -S, c:\AndroidMultitool\Decompiled_apk\BetterBatteryStats_xdaedition_2.0.0.0B2\res, -M, c:\AndroidMultitool\Decompiled_apk\BetterBatteryStats_xdaedition_2.0.0.0B2\AndroidManifest.xml] at brut.util.OS.exec(OS.java:89) at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:464) ... 6 more

That`s because AAPT source is not yet available, as you have said? Or there is something else? Thank you.

iBotPeaches commented 9 years ago

Comment #23 originally posted by flex360 on 2014-10-29T12:13:20.000Z:

You don't like to read don't you? He clearly said she ull have to wait and you can't recompile for now, only decompile.

iBotPeaches commented 9 years ago

Comment #24 originally posted by pawar.vaibhav016 on 2014-10-29T13:28:26.000Z:

Bro........................i also facing the same issue i am just able to decompile the apk and totally unable tp recompile it.... i am facing this problem since i have updated my java version 7

iBotPeaches commented 9 years ago

Comment #25 originally posted by dankoman30 on 2014-10-29T14:16:50.000Z:

Can all of you please read Connor's comment # 19 on this issue? He specifically states that aapt source is needed to fix apktool for recompiling. This will come when the full source for lollipop is released. It would be awesome if people could read through the issue's comments before asking redundant questions. Everybody who starred this issue gets notifications every time someone comments, and it's getting to the point I'm about to unstar this issue because it's getting annoying.

iBotPeaches commented 9 years ago

Comment #26 originally posted by pawar.vaibhav016 on 2014-10-30T05:39:21.000Z:

apktool d -r apkname.apk this command is working

iBotPeaches commented 9 years ago

Comment #27 originally posted by pawar.vaibhav016 on 2014-10-30T05:40:45.000Z:

so........why normal commmand apktool d apkname.apk and apktool b apkname.apk this commands are not working ................ showing error in aapt file

iBotPeaches commented 9 years ago

Comment #28 originally posted by djbryan3540 on 2014-11-03T22:09:44.000Z:

Here here!

iBotPeaches commented 9 years ago

Comment #29 originally posted by luutinhit.1412 on 2014-11-04T09:03:42.000Z:

I have install framework-res.apk of android L use command: apktool if framework-res.apk But it's error: Exception in thread "main" brut.androlib.AndrolibException: Multiple resources: spec=0x01030128 style/Theme.DeviceDefault, config=[DEFAULT] at brut.androlib.res.data.ResConfig.addResource(ResConfig.java:63) at brut.androlib.res.data.ResConfig.addResource(ResConfig.java:56) at brut.androlib.res.decoder.ARSCDecoder.readEntry(ARSCDecoder.java:186)

    at brut.androlib.res.decoder.ARSCDecoder.readConfig(ARSCDecoder.java:157

) at brut.androlib.res.decoder.ARSCDecoder.readType(ARSCDecoder.java:125) at brut.androlib.res.decoder.ARSCDecoder.readPackage(ARSCDecoder.java:10 0) at brut.androlib.res.decoder.ARSCDecoder.readTable(ARSCDecoder.java:78) at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:47) at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:39) at brut.androlib.res.AndrolibResources.installFramework(AndrolibResource s.java:657) at brut.androlib.Androlib.installFramework(Androlib.java:649) at brut.apktool.Main.cmdInstallFramework(Main.java:256) at brut.apktool.Main.main(Main.java:92)

iBotPeaches commented 9 years ago

Comment #30 originally posted by connor.tumbleson on 2014-11-04T16:56:19.000Z:

Now with AOSP Lollipop, lets get to work. A lot more than I expected, and I mean a lot.

anydpi qualifier - https://github.com/android/platform_frameworks_base/commit/31245b4f06003f1c8cd44c31b387c96ab4e282f9

of interest (aapt is versioned now) - https://github.com/android/platform_frameworks_base/commit/71809ee7f63229d0ea4f6169922ddfbfee330fd2

language / country moved to BCP-47 format - https://github.com/android/platform_frameworks_base/commit/788fa41482b9d398591b7db8b0b01839029611ad

-> reading mcc - https://github.com/android/platform_frameworks_base/blob/lollipop-release/tools/aapt/AaptConfig.cpp#L267 -> reading mnc - https://github.com/android/platform_frameworks_base/blob/lollipop-release/tools/aapt/AaptConfig.cpp#L297

The minimum compatibility level has a new entry. If the density has the anydpi attribute it is bumped to 21 - https://github.com/android/platform_frameworks_base/blob/lollipop-release/tools/aapt/AaptConfig.cpp#L237

the watch aapt qualifier - https://github.com/android/platform_frameworks_base/commit/6c191299a73388cd593809c0b66bafbd08fd2982

addition of --replace-version to allow replacing versionName & versionCode in manifest, instead of us removing them - https://github.com/android/platform_frameworks_base/commit/df08d1c24dbbc242978ee33416d1e54998f88915

Also interesting is split apks, changes to outline of 9patch generation, supporting multiple resource tables that have same package, and much more.

To answer the questions that most of you are wondering.

Q) but but it already works with some Lollipop apps, what is all of this? A) Applications haven't utilized this newer stuff yet.

Q) Whats next? A) aapt source won't change anytime soon now that its pushed. I will get the newer aapts into apktool asap, then begin work on the other changes

Q) When will RC3 come? A) After I handle this change to BCP-47 format for locale/language, add support for anydpi qualifier, update the min compat section for API 21, rebuild all internal aapts and test for regression.

Q) When? WHEN?? WHEN????!?! A) Give me a week / two. Nothing looks terribly difficult. I'm typing this from class, so I might have missed a commit or two that are relevant to Apktool. Please don't spam this bug report as lots are following and receive an email for every response. I will post status updates as things are completed.

iBotPeaches commented 9 years ago

Comment #31 originally posted by connor.tumbleson on 2014-11-11T17:42:02.000Z:

Status Update

We encountered a problem with AOSP builds of aapt not working in our specific use case. After a few days of examining the source, I tracked it back to the AssetManager. My knowledge of that area of AOSP is next to none.

For that reason, I reported a bug. Within 4 hours it was assigned to someone which is amazing compared to the success of other bug reports to AOSP: https://code.google.com/p/android/issues/detail?id=79068

In the meantime, I'm trying to patch AssetManager myself, but it's a learning game right now.

Most of the apktool changes are already fixed locally. So once the blocker of aapt is solved, we should theoretically be good to go.

As usual, please do not comment as everyone gets notified. I will update again when the aapt situation is resolved.

iBotPeaches commented 9 years ago

Comment #32 originally posted by connor.tumbleson on 2014-11-14T19:37:36.000Z:

Issue 703 has been merged into this issue.

iBotPeaches commented 9 years ago

Comment #33 originally posted by connor.tumbleson on 2014-11-17T13:01:05.000Z:

Issue 705 has been merged into this issue.

iBotPeaches commented 9 years ago

Comment #34 originally posted by connor.tumbleson on 2014-11-21T17:56:20.000Z:

https://github.com/iBotPeaches/Apktool/pull/97

I'd say this is very close to being fixed. All the current Lollipop APKs I've thrown at it have been handled without error. aapt has become very restrictive however. This means apks that compiled before hand might not compile immediately this time. Manual intervention might be required.

I've thought about this and I don't think its Apktool's job to fix up APKs to make them in a suitable format for recompilation. In an IDE w/ linting support like Android Studio and the source at hand, it would make sense to guide the user for the changes required with a new build engine. Note not all apks are affected by this. This is only when apks utilized methods that weren't official like

Please don't post asking for a binary. If you can't build a version yourself from this pull request, then await for the official binary. (Hoping for this weekend)

If you do build the version and test it out. Make sure to remove all frameworks in $HOME/apktool/framework/*.apk. A change was made which requires those to be rebuild. You WILL receive errors if you don't do this.

iBotPeaches commented 9 years ago

Comment #35 originally posted by purple2k on 2014-11-23T07:34:41.000Z:

Thanks, connor.

I'm trying to build it myself from your pull request on Windows, however when I run "gradlew.bat build fatJar", I get the error message:

Exception in thread "main" java.lang.RuntimeException: Could not determine wrapper version. at org.gradle.wrapper.GradleWrapperMain.wrapperVersion(GradleWrapperMain.java:106) at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48) Caused by: java.lang.RuntimeException: No build receipt resource found. at org.gradle.wrapper.GradleWrapperMain.wrapperVersion(GradleWrapperMain.java:92) ... 1 more

Am I missing anything?

Otherwise - if anyone was successful at building this, care to upload your jar?

Thanks :)

iBotPeaches commented 9 years ago

Comment #36 originally posted by purple2k on 2014-11-23T13:38:13.000Z:

Never mind, successfully built. For those curious, the problem was that I had a special character (exclamation mark) in the path.

iBotPeaches commented 9 years ago

Comment #37 originally posted by connor.tumbleson on 2014-11-26T17:59:55.000Z:

This has been merged: https://github.com/iBotPeaches/Apktool/commit/02b5c7c57bece45ef4c512289b30d3728e8f0a29

Binaries to follow tonight. Lots of prep work in writing docs to do a release.