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

[BUG] Recompilation error: "invalid value for type 'layout'. Expected a reference" #2618

Open
antoshkin opened this issue Jul 19, 2021 · 20 comments

Comments

@antoshkin
Copy link

antoshkin commented Jul 19, 2021

Information

  1. Apktool Version (apktool -version) - 2.5.1
  2. Operating System (Mac, Linux, Windows) - Ubuntu 20
  3. APK From? (Playstore, ROM, Other) - apkpure.com

Stacktrace/Logcat

bro@local:\~/ig-apk$ **apktool d ig-196-apkpure.apk**
...
...
...
bro@local:~/ig-apk$ **apktool b --use-aapt2 -o out.apk ig-196-apkpure**
I: Using Apktool 2.5.1-eaab72-SNAPSHOT
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether resources has changed...
I: Building resources...
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:12: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:13: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:14: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:15: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:16: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:17: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:18: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:19: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:20: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:21: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:22: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:23: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:24: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:25: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:26: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:27: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:28: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:29: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:30: error: invalid value for type 'layout'. Expected a reference.
W: /home/bro/ig-apk/ig-196-apkpure/res/values-v22/layouts.xml:31: error: invalid value for type 'layout'. Expected a reference.
brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_77580703989672702302554212405921978723.tmp, compile, --dir, /home/bro/ig-apk/ig-196-apkpure/res, --legacy, -o, /home/bro/ig-apk/ig-196-apkpure/build/resources.zip]

Sample of layouts.xml:
...
<item type="layout" name="guide_grid_row">L|46188|5C4|BCF2</item>
<item type="layout" name="guide_ufi_bar">L|4674C|F90|E5CC</item>
<item type="layout" name="gumstick">L|476DC|A50|AC5A</item>
...

Steps to Reproduce

  1. apktool d ig-196-apkpure.apk
  2. apktool b --use-aapt2 -o out.apk ig-196-apkpure

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

armeabi-v7a / Android 5.0+

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything? yes
  2. Are you using the latest apktool version? yes
@iBotPeaches
Copy link
Owner

I replicate. Logging some info to help for debugging this later.

➜  2618 aapt d resources Instagram_v196.0.0.32.126_apkpure.com.apk --values | grep 'guide_grid_row'
      spec resource 0x7f0c04bc com.instagram.android:layout/guide_grid_row: flags=0x00000400
        resource 0x7f0c04bc com.instagram.android:layout/guide_grid_row: t=0x03 d=0x00002781 (s=0x0008 r=0x00)
        resource 0x7f0c04bc com.instagram.android:layout/guide_grid_row: t=0x03 d=0x00002174 (s=0x0008 r=0x00)
➜  Instagram_v196.0.0.32.126_apkpure.com grep -r -i 'guide_grid_row' *
Binary file build/resources.zip matches
res/values-v22/layouts.xml:    <item type="layout" name="guide_grid_row">L|46188|5C4|BCF2</item>
res/values/layouts.xml:    <item type="layout" name="guide_grid_row">L|2AE8F8|590|E594</item>
res/values/public.xml:    <public type="layout" name="guide_grid_row" id="0x7f0c04bc" />

@TheLukaDragar
Copy link

Can confirm having the same issue on M1 Mac and Windows. Recompiling the Instagram app.

@tranb3r
Copy link

tranb3r commented Apr 21, 2022

Any update on this issue?
Is there any workaround?

@HD421
Copy link

HD421 commented May 25, 2022

Hey there, just had the same error and steps how I fixed it in my case:

  1. Run 'apktool empty-framework-dir' command before re-building an app
  2. Run apktool b -o out.apk ig-196-apkpure (it seems that issue was with --use-aapt2 flag in my case)

@Splinterjke
Copy link

it seems that issue was with --use-aapt2 flag

I do confirm, it fixed the latest whatsapp beta compilation errors.

@qyzhaojinxi
Copy link

not work for me

@ghost
Copy link

ghost commented Jan 12, 2024

from what ive found
the file is decompiled correctly and those values are used to retrieve the layout resource from instagram's proprietary resource format (assets/layouts.bin.xz)

source: method(jadx) X.C1Mj.getLayout(int) and X.C24601Mp.A00()
from instagram apk version 315.0.0.0.6 alpha (371500513)

the resource format seems to contain axml blocks too
source: constructor(jadx) X.C1NA.C1NA(Resources, File)

@iBotPeaches
Copy link
Owner

I thought about this a bit. Clearly Instagram is doing some trickey here with storing references to their odd layouts.bin.xz file. aapt2 screams at this and crashes compilation.

https://github.com/search?q=repo%3AiBotPeaches%2Fplatform_frameworks_base%20%22invalid%20value%20for%20type%22&type=code

We could easily patch out this check and see how the application reacts. It just seems dangerous for Apktool as this is a good build-time check that is only becoming a problem for apps like Instagram.

@Nikvothe
Copy link

Nikvothe commented May 5, 2024

@iBotPeaches Could this have been done on purpose to prevent people from reverse engineering their way out of their recent mandatory dialog box to accept being tracked for ads?

The unskippable dialog box has been driving me crazy for weeks so I spent these last few days learning about apktool and Smali, and of course now it blocks compilation at the end.

You know I don't care if instagram steals and sells all my data but I'm not giving consent.
I think the resources to run this dialogBox get downloaded after logging in, and triggered in the second "onCreate" lifecycle of Instagram. Meaning the first time I log in on a clean Instagram install I'll be fine until I close the app.

Is there perhaps some other way to bypass this behaviour?

Any suggestions are highly appreciated.

IMG_20240505_170809

@GiorgosXou
Copy link

I'm able to compile using --use-aapt1 but for some reason the momment I login the app crashes

@GiorgosXou
Copy link

First I tried to sign the original one (just to see if instagram plays any trickery) and worked just fine. Then I did the same for just the recompiled apk and (as mentioned above) althought I was able to open the app, the momment I logged-in it crashed... So I'm really skeptical as to if this is a problem with apktool itselft or instagram does some trickery there too.

@78sven
Copy link

78sven commented Jun 13, 2024

Any updates on this bug? Has anyone found a workaround ?

@nicelyjobs
Copy link

nicelyjobs commented Jun 21, 2024

i also got same error + 2 more (it's start on newest updated apk's only, on old apk version still works)

I: Building resources...
W: C:\apktool\mik\res\values-land\layouts.xml:3: error: invalid value for type 'layout'. Expected a reference.
W: C:\apktool\mik\res\values-land\layouts.xml:4: error: invalid value for type 'layout'. Expected a reference.
W: C:\apktool\mik\res\values-land\layouts.xml:5: error: invalid value for type 'layout'. Expected a reference.
W: C:\apktool\mik\res\values-land\layouts.xml:6: error: invalid value for type 'layout'. Expected a reference.
W: C:\apktool\mik\res\values-land\layouts.xml: error: file failed to compile.
W: C:\apktool\mik\res\values-ldrtl\layouts.xml:3: error: invalid value for type 'layout'. Expected a reference.
W: C:\apktool\mik\res\values-ldrtl\layouts.xml: error: file failed to compile.
W: C:\apktool\mik\res\values-night\mipmaps.xml:3: error: invalid value for type 'mipmap'. Expected a reference.
W: C:\apktool\mik\res\values-night\mipmaps.xml: error: file failed to compile.
W: C:\apktool\mik\res\values-sw600dp\layouts.xml:3: error: invalid value for type 'layout'. Expected a reference.
W: C:\apktool\mik\res\values-sw600dp\layouts.xml:4: error: invalid value for type 'layout'. Expected a reference.
W: C:\apktool\mik\res\values-sw600dp\layouts.xml: error: file failed to compile.
W: C:\apktool\mik\res\values-v26\layouts.xml:3: error: invalid value for type 'layout'. Expected a reference.
W: C:\apktool\mik\res\values-v26\layouts.xml:4: error: invalid value for type 'layout'. Expected a reference.
W: C:\apktool\mik\res\values-v26\layouts.xml: error: file failed to compile.
W: C:\apktool\mik\res\values-watch\layouts.xml:3: error: invalid value for type 'layout'. Expected a reference.
W: C:\apktool\mik\res\values-watch\layouts.xml:4: error: invalid value for type 'layout'. Expected a reference.
W: C:\apktool\mik\res\values-watch\layouts.xml: error: file failed to compile.
W: C:\apktool\mik\res\values\animators.xml:3: error: invalid value for type 'animator'. Expected a reference.
W: C:\apktool\mik\res\values\animators.xml:4: error: invalid value for type 'animator'. Expected a reference.
brut.androlib.exceptions.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\Username\AppData\Local\Temp\brut_util_Jar_160069859907321700514368744111369315017.tmp, compile, --dir, C:\apktool\mik\res, --legacy, -o, C:\apktool\mik\build\resources.zip]

@zhangxinguo1491625
Copy link

I would like to ask if this problem has been solved. I have also encountered

@andiweli
Copy link

I also encounter this issue. Andy idea how to solve it?

@mikeanjelo
Copy link

mikeanjelo commented Sep 18, 2024

any one found solution to this problem ?

i have tried "Delete framework\1.apk" and disable aapt2 , but did not work

#EDIT 1:

  • also i tried using apktool V 2.10 but also did not Work

#EDIT 2: [Worked for me]

  • Download and use apktool V2.7.0.
  • Make sure to delete the file : "C:\Users{username}\AppData\Local\apktool\framework\1.apk" before compile (once).
  • Don't use aapt2.

@Alawsi
Copy link

Alawsi commented Sep 22, 2024

✅ It worked, thank you @mikeanjelo

1 - I deleted the 1.apk From "C:\Users{username}\AppData\Local\apktool\framework\1.apk" .

2 - I installed version 2.7.0 :

https://bitbucket.org/iBotPeaches/apktool/downloads/

3 - Now run the command: apktool b <Your-File>

@vishhvak
Copy link

vishhvak commented Oct 2, 2024

@Alawsi What is the solution for m1 mac?

@mamiiblt
Copy link

definitely delete old framework file and use aapt1 works for build but app will crashes before login. Probably instagram added some new things...

@mamiiblt
Copy link

#EDIT 2: [Worked for me]

  • Download and use apktool V2.7.0.
  • Make sure to delete the file : "C:\Users{username}\AppData\Local\apktool\framework\1.apk" before compile (once).
  • Don't use aapt2.

it's definitely work for latest alpha bases on instafel too

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

No branches or pull requests