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

Comments

Projects
None yet
6 participants
@minhtrong0305

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 from Decompiling apk file extracted folders missing -v4 to Decompiling apk file its extracted folders missing -v4 Apr 27, 2015

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Apr 27, 2015

Owner

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

Yes, I duplicate the problem.

Owner

iBotPeaches commented Apr 27, 2015

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

Yes, I duplicate the problem.

@Furniel

This comment has been minimized.

Show comment
Hide comment
@Furniel

Furniel May 20, 2015

Contributor

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

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

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches May 20, 2015

Owner

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

Owner

iBotPeaches commented May 20, 2015

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

@BurgerZ

This comment has been minimized.

Show comment
Hide comment
@BurgerZ

BurgerZ May 20, 2015

Contributor

@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.

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

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches May 20, 2015

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)

Owner

iBotPeaches commented May 20, 2015

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

This comment has been minimized.

Show comment
Hide comment
@Furniel

Furniel May 21, 2015

Contributor

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

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

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches May 21, 2015

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.

Owner

iBotPeaches commented May 21, 2015

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

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches May 22, 2015

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.

Owner

iBotPeaches commented May 22, 2015

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

This comment has been minimized.

Show comment
Hide comment
@Phone-Guru

Phone-Guru Jul 24, 2015

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.

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

This comment has been minimized.

Show comment
Hide comment
@Phone-Guru

Phone-Guru Jul 24, 2015

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

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

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Aug 14, 2015

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.

Owner

iBotPeaches commented Aug 14, 2015

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

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Oct 4, 2015

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.

Owner

iBotPeaches commented Oct 4, 2015

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 iBotPeaches closed this Oct 4, 2015

@pirracas77

This comment has been minimized.

Show comment
Hide comment
@pirracas77

pirracas77 Apr 1, 2016

It seems that the behaviour is still present.

I'm using Apktool v2.1.0

01/04/2016 17:39

.
01/04/2016 17:39 ..
01/04/2016 17:39 anim
01/04/2016 17:39 drawable
01/04/2016 17:39 drawable-hdpi-v4
01/04/2016 17:39 drawable-land-hdpi-v4
01/04/2016 17:39 drawable-land-xhdpi-v4
01/04/2016 17:39 drawable-land-xxhdpi-v4
01/04/2016 17:39 drawable-ldrtl-hdpi-v4
01/04/2016 17:39 drawable-ldrtl-sw600dp-hdpi-v13
01/04/2016 17:39 drawable-ldrtl-sw600dp-xhdpi-v13
01/04/2016 17:39 drawable-ldrtl-sw600dp-xxhdpi-v13
01/04/2016 17:39 drawable-ldrtl-xhdpi-v4
01/04/2016 17:39 drawable-ldrtl-xxhdpi-v4
01/04/2016 17:39 drawable-nodpi-v4
01/04/2016 17:39 drawable-sw600dp-hdpi-v13
01/04/2016 17:39 drawable-sw600dp-xhdpi-v13
01/04/2016 17:39 drawable-sw600dp-xxhdpi-v13
01/04/2016 17:39 drawable-sw800dp-hdpi-v13
01/04/2016 17:39 drawable-xhdpi-v4
01/04/2016 17:39 drawable-xxhdpi-v4
01/04/2016 17:39 layout
01/04/2016 17:39 layout-land
01/04/2016 17:39 layout-ldrtl
01/04/2016 17:39 layout-port
01/04/2016 17:39 layout-sw600dp-land-v13
01/04/2016 17:39 layout-sw600dp-port-v13
01/04/2016 17:39 layout-sw600dp-v13
01/04/2016 17:39 menu
01/04/2016 17:39 mipmap-hdpi-v4
01/04/2016 17:39 mipmap-mdpi-v4
01/04/2016 17:39 mipmap-xhdpi-v4
01/04/2016 17:39 xml

It seems that the behaviour is still present.

I'm using Apktool v2.1.0

01/04/2016 17:39

.
01/04/2016 17:39 ..
01/04/2016 17:39 anim
01/04/2016 17:39 drawable
01/04/2016 17:39 drawable-hdpi-v4
01/04/2016 17:39 drawable-land-hdpi-v4
01/04/2016 17:39 drawable-land-xhdpi-v4
01/04/2016 17:39 drawable-land-xxhdpi-v4
01/04/2016 17:39 drawable-ldrtl-hdpi-v4
01/04/2016 17:39 drawable-ldrtl-sw600dp-hdpi-v13
01/04/2016 17:39 drawable-ldrtl-sw600dp-xhdpi-v13
01/04/2016 17:39 drawable-ldrtl-sw600dp-xxhdpi-v13
01/04/2016 17:39 drawable-ldrtl-xhdpi-v4
01/04/2016 17:39 drawable-ldrtl-xxhdpi-v4
01/04/2016 17:39 drawable-nodpi-v4
01/04/2016 17:39 drawable-sw600dp-hdpi-v13
01/04/2016 17:39 drawable-sw600dp-xhdpi-v13
01/04/2016 17:39 drawable-sw600dp-xxhdpi-v13
01/04/2016 17:39 drawable-sw800dp-hdpi-v13
01/04/2016 17:39 drawable-xhdpi-v4
01/04/2016 17:39 drawable-xxhdpi-v4
01/04/2016 17:39 layout
01/04/2016 17:39 layout-land
01/04/2016 17:39 layout-ldrtl
01/04/2016 17:39 layout-port
01/04/2016 17:39 layout-sw600dp-land-v13
01/04/2016 17:39 layout-sw600dp-port-v13
01/04/2016 17:39 layout-sw600dp-v13
01/04/2016 17:39 menu
01/04/2016 17:39 mipmap-hdpi-v4
01/04/2016 17:39 mipmap-mdpi-v4
01/04/2016 17:39 mipmap-xhdpi-v4
01/04/2016 17:39 xml

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Apr 1, 2016

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.

Owner

iBotPeaches commented Apr 1, 2016

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