Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompiling apk file its extracted folders missing -v4 #928

Closed
minhtrong0305 opened this issue Apr 27, 2015 · 14 comments
Closed

Decompiling apk file its extracted folders missing -v4 #928

minhtrong0305 opened this issue Apr 27, 2015 · 14 comments
Labels

Comments

@minhtrong0305
Copy link

Apktool v2.0.0 Bug: Decompiling apk file in LG G2 Lollipop rom its extracted folders missing -v4 (Ex: drawable-xxhdpi-v4 extract to drawable-xxhdpi)

@minhtrong0305 minhtrong0305 reopened this Apr 27, 2015
@minhtrong0305 minhtrong0305 changed the title Decompiling apk file extracted folders missing -v4 Decompiling apk file its extracted folders missing -v4 Apr 27, 2015
@iBotPeaches
Copy link
Owner

I've added test apk, since an apk was not provided - iBotPeaches/TestApks@9c40d37

Yes, I duplicate the problem.

@Furniel
Copy link
Contributor

Furniel commented May 20, 2015

Looks like after fixing of this bug we have new issue, apktool adds version qualifiers to folders that don't have them.
For example drawable folders in SystemUI.apk(android 4.2.2) originally don't have sdk version qualifiers, but after\during decompilation apktool adds -v4 & -v13 to folder names. We can compile apk back, but after compilation new apk structure has nothing similar to original apk structure.

Files for test:
https://mega.co.nz/#!R8U2ALhT!RZTSKpEf1J1niddf81RPsNSxMBzdHNlx3zNWO8o6QvI

@iBotPeaches
Copy link
Owner

@Furniel I'll double check if my regression caused this, but I believe this is aapt. Check my response here: #934 (comment)

@BurgerZ
Copy link
Contributor

BurgerZ commented May 20, 2015

@iBotPeaches I confirm that. In my tests -v4 qualifier is being added to all decompiled values folders, even if the original apk doesn't have them.

@iBotPeaches
Copy link
Owner

According to the files uploaded to test, there is no problem.

Look at the output

ibotpeaches@raganok:~/Downloads/Apktool/Bug928/files$ aapt d configurations SystemUI.apk 

nodpi-v4
ldpi-v4
sw640dp-ldpi-v13
sw1024dp-ldpi-v13
mdpi-v4
sw600dp-mdpi-v13
sw720dp-mdpi-v13
sw768dp-mdpi-v13
hdpi-v4
sw600dp-hdpi-v13
sw720dp-hdpi-v13
sw800dp-hdpi-v13
xhdpi-v4
sw600dp-v13
port
sw600dp-port-v13
land
sw600dp-land-v13
sw720dp-v13

Then you can see after decode.

ibotpeaches@raganok:~/Downloads/Apktool/Bug928/files/SystemUI/res$ ls
anim
drawable
drawable-hdpi-v4
drawable-ldpi-v4
drawable-mdpi-v4
drawable-nodpi-v4
drawable-sw1024dp-ldpi-v13
drawable-sw600dp-hdpi-v13
drawable-sw600dp-mdpi-v13
drawable-sw640dp-ldpi-v13
drawable-sw720dp-hdpi-v13
drawable-sw720dp-mdpi-v13
drawable-sw768dp-mdpi-v13
drawable-sw800dp-hdpi-v13
layout
layout-land
layout-port
layout-sw600dp-land-v13
layout-sw600dp-port-v13
layout-sw600dp-v13
menu
mipmap-hdpi-v4
mipmap-mdpi-v4
mipmap-xhdpi-v4
raw

(Stripped values)

@Furniel
Copy link
Contributor

Furniel commented May 21, 2015

Yes aapt shows sdk version qualifiers, but that`s doesn't mean that decompiled apk should have them. After decompilation and compilation we should have apk that matching original apk file, but now we have this:
1
2
3

@iBotPeaches
Copy link
Owner

Thanks for the details.

I see now, though was reluctant as I've always been trusting aapt. It must be implicitly adding the version qualifier where required during printout of configurations.

What confuses me is that we have an extensive application in the unit-test pool that has over 40 resource folders, only one of which has a version qualifier (v4), as you can see via this list.

ibotpeaches@raganok:~/Projects/apktool/brut.apktool/apktool-lib/src/test/resources/brut/apktool/testapp/res$ ls
drawable-534dpi
drawable-anydpi
drawable-hdpi
drawable-ldpi
drawable-mdpi
drawable-nodpi
drawable-tvdpi
drawable-xhdpi
drawable-xxhdpi
drawable-xxhdpi-v4
drawable-xxxhdpi
raw
values
values-ast
values-ast-rES
values-b+ast+Latn+IT+AREVELA
values-b+eng+419
values-b+en+Latn+419
values-b+en+Latn+US
values-b+en+US+POSIX
values-en
values-en-rUS
values-fr
values-ldrtl
values-mcc001
values-mcc001-mnc00
values-mcc001-mnc01
values-mcc002
values-mcc003
values-mcc004-mnc04-en-rUS-ldrtl-sw100dp-w200dp-h300dp-xlarge-long-land-desk-night-xhdpi-finger-keyssoft-12key-navhidden-dpad
values-watch
xml

Now unit-tests go [b]uild -> [d]ecode, then it compares the original source to the decoded one. There are no version qualifiers added here, except for the folder that dictated the v4 one. So unit-tests have 0 errors, but the APKs provided by @Furniel and reported by @BurgerZ do experience some errors.

Without the change I have any qualifier that has v4 is ignored.

Does reverting my change fix the above problem? Not sure yet.

Obviously there is a problem though, so re-opening.

@iBotPeaches iBotPeaches reopened this May 21, 2015
@iBotPeaches
Copy link
Owner

Okay, just talking through words here.

So newer aapt adds version qualifiers automatically during build. So v4 is added for any qualifier that is at LEAST supported on API 4. So this includes xhdpi, etc. This means every application I build these days includes these qualifiers (as shown below).

test

So currently, apktool decodes this properly as in the v4 qualifier sticks. If I revert the changes, then minimum SDK = 4 and the SDK pulled from qualifier = 4, thus no change. So drawable-xxhdpi-v4 becomes drawable-xxhdpi. This causes a multiple resource error, and is quite easy to break apktool at this point when clients can simply add those directories to break it.

Now, if we examine the code we have currently.

(apktool)

        if (sdkVersion > 0 && sdkVersion >= getNaturalSdkVersionRequirement()) {
            ret.append("-v").append(sdkVersion);
        }

(aosp)

    if (minSdk > config->sdkVersion) {
        config->sdkVersion = minSdk;
    }

There is a difference. The >= should be >, which then fixes the errors you two are experiencing, but then introduces the mentioned multiple resource problem.

All of this is irrelevant in the greater picture that apktool should decode resources to what they literally are. If the qualifier is drawable-xhdpi, it should be drawable-xhdpi, not drawable-xhdpi-v4.

However in the instance of that, the sdkVersion is set to 4. So either way there will be a problem. Not sure on the correct solution yet.

@Phone-Guru
Copy link

The original Gmail 5.4 apk has -v4 qualifiers which correctly decompile into the folder for editing and remain intact through recompile so not this problem.

@Phone-Guru
Copy link

Using an old version of APKtool 2.0.0 that I had, the -v4 qualifiers disappeared during decompile

@iBotPeaches
Copy link
Owner

Okay, I tracked this problem down (again?)

I have a LINUX rebuild aapt here - http://connortumbleson.com/apktool/aapt_8-8-2015/aapt

Anyone willing to confirm my findings before I build a windows/mac aapt and include in master? Basically aapt is trying to make the apks "future compatible", by doing all these tweaks which cause this.

Since apktool is suppose to simply rebuild to match the original apk as close as possible, it made sense to skip (no-op) these functions.

@iBotPeaches
Copy link
Owner

Okay, I skip all compat functions now - iBotPeaches/platform_frameworks_base@7bff185

In 2.0.2 the apk will not add any version qualifiers. It will maintain whatever the original apk was.

@iBotPeaches
Copy link
Owner

Then that was the way the original apk was. Please open a new bug report, following template and apk provided if you believe regression occurred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants
@Furniel @iBotPeaches @BurgerZ @Phone-Guru @minhtrong0305 and others