Status Update
Comments
pu...@gmail.com <pu...@gmail.com> #2
EDIT: last line should read:
There is no such issue with 8.3.0-alpha10
so...@google.com <so...@google.com>
je...@google.com <je...@google.com>
cm...@google.com <cm...@google.com> #3
This is very likely the
android.enableNewResourceShrinker.preciseShrinking
is now true by default.
This leads to more shrinking than before (e.g. values can now be removed)
You can disable it in your project by setting android.enableNewResourceShrinker.preciseShrinking=false
in gradle.properties
if that fixes it then it's either a bug in the precise shrinking mode, or your keep rules are incomplete but things happened to work when more was kept implicitly
pu...@gmail.com <pu...@gmail.com> #4
I confirm that android.enableNewResourceShrinker.preciseShrinking=false
fixes the issue.
Though I cannot think what could be wrong in my keep rules.
It crashes very early loading the main layout of the app.
Here's the full Stack Trace. Resources#getResourceEntryName
is called (by io.github.inflationx:calligraphy3:3.1.1
) with a TextView
id that cannot be found:
E 34:55.297 Caused by: android.view.InflateException: Binary XML file line #36 in <package redacted>:layout/abc_search_view: Binary XML file line #36 in <package redacted>:layout/abc_search_view: Error inflating class TextView
E 34:55.297 Caused by: android.view.InflateException: Binary XML file line #36 in <package redacted>:layout/abc_search_view: Error inflating class TextView
E 34:55.297 Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f0902cd
E 34:55.297 at android.content.res.ResourcesImpl.getResourceEntryName(ResourcesImpl.java:293)
E 34:55.297 at android.content.res.Resources.getResourceEntryName(Resources.java:2340)
E 34:55.297 at io.github.inflationx.calligraphy3.Calligraphy.matchesResourceIdName(Calligraphy.java:94)
E 34:55.297 at io.github.inflationx.calligraphy3.Calligraphy.isActionBarTitle(Calligraphy.java:57)
E 34:55.297 at io.github.inflationx.calligraphy3.Calligraphy.getStyleForTextView(Calligraphy.java:33)
E 34:55.297 at io.github.inflationx.calligraphy3.Calligraphy.onViewCreatedInternal(Calligraphy.java:139)
E 34:55.297 at io.github.inflationx.calligraphy3.Calligraphy.onViewCreated(Calligraphy.java:117)
E 34:55.297 at io.github.inflationx.calligraphy3.CalligraphyInterceptor.intercept(CalligraphyInterceptor.java:19)
E 34:55.297 at io.github.inflationx.viewpump.internal.-InterceptorChain.proceed(-InterceptorChain.java:30)
E 34:55.297 at io.github.inflationx.viewpump.ViewPump.inflate(ViewPump.java:36)
E 34:55.297 at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater$WrapperFactory2.onCreateView(-ViewPumpLayoutInflater.java:395)
E 34:55.297 at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1065)
E 34:55.297 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1001)
E 34:55.297 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
E 34:55.297 at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
E 34:55.297 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
E 34:55.297 at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
E 34:55.297 at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater.inflate(-ViewPumpLayoutInflater.java:70)
E 34:55.297 at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
E 34:55.297 at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater.inflate(-ViewPumpLayoutInflater.java:61)
E 34:55.297 at androidx.appcompat.widget.SearchView.<init>(SearchView.java:290)
E 34:55.297 at androidx.appcompat.widget.SearchView.<init>(SearchView.java:276)
E 34:55.297 at java.lang.reflect.Constructor.newInstance0(Constructor.java)
E 34:55.297 at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
E 34:55.297 at android.view.LayoutInflater.createView(LayoutInflater.java:858)
E 34:55.297 at android.view.LayoutInflater.createView(LayoutInflater.java:780)
E 34:55.297 at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater.createCustomViewInternal(-ViewPumpLayoutInflater.java:235)
E 34:55.297 at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater.access$createCustomViewInternal(-ViewPumpLayoutInflater.java:19)
E 34:55.297 at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater$PrivateWrapperFactory2ViewCreator.onCreateView(-ViewPumpLayoutInflater.java:464)
E 34:55.297 at io.github.inflationx.viewpump.internal.-FallbackViewCreationInterceptor.intercept(-FallbackViewCreationInterceptor.java:14)
E 34:55.297 at io.github.inflationx.viewpump.internal.-InterceptorChain.proceed(-InterceptorChain.java:30)
E 34:55.297 at io.github.inflationx.calligraphy3.CalligraphyInterceptor.intercept(CalligraphyInterceptor.java:18)
E 34:55.297 at io.github.inflationx.viewpump.internal.-InterceptorChain.proceed(-InterceptorChain.java:30)
E 34:55.297 at io.github.inflationx.viewpump.ViewPump.inflate(ViewPump.java:36)
E 34:55.297 at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater$PrivateWrapperFactory2.onCreateView(-ViewPumpLayoutInflater.java:440)
E 34:55.297 at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:241)
E 34:55.297 at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1073)
E 34:55.297 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1001)
E 34:55.297 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
E 34:55.297 at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
E 34:55.297 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
E 34:55.297 at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
E 34:55.297 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
E 34:55.297 at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
E 34:55.297 at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater.inflate(-ViewPumpLayoutInflater.java:70)
E 34:55.297 at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
E 34:55.297 at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater.inflate(-ViewPumpLayoutInflater.java:61)
E 34:55.297 at <package redacted>.MainTabActivity.onCreate(MainTabActivity.java:1146)
E 34:55.297 at android.app.Activity.performCreate(Activity.java:8342)
E 34:55.297 at android.app.Activity.performCreate(Activity.java:8321)
E 34:55.297 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
E 34:55.297 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3625)
E 34:55.297 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3781)
E 34:55.297 at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
E 34:55.297 at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
E 34:55.297 at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E 34:55.297 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2306)
E 34:55.297 at android.os.Handler.dispatchMessage(Handler.java:106)
E 34:55.297 at android.os.Looper.loopOnce(Looper.java:201)
E 34:55.297 at android.os.Looper.loop(Looper.java:288)
E 34:55.297 at android.app.ActivityThread.main(ActivityThread.java:7918)
E 34:55.297 at java.lang.reflect.Method.invoke(Method.java)
E 34:55.297 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E 34:55.297 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
pu...@gmail.com <pu...@gmail.com> #5
For completeness, the app's MainTabActivity#onCreate
look like this:
setContentView(...);
...
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
LayoutInflater drawerInflater = LayoutInflater.from(this);
drawerInflater.inflate(R.layout.drawer_list, drawerLayout, true); // crash triggered from this line
ri...@google.com <ri...@google.com> #6
So the library where this crash is certainly doing reflective resource lookups, which would need to be kept (if we need to do that)
If possible, could you share a reproduction, if not publicly then with
Otherwise, can you do:
aapt dump --values resources apk_without_precise_shrinking.apk
and provide the actually missing resource (e.g., grep for 0x7f0902cd )
pu...@gmail.com <pu...@gmail.com> #7
From aapt on the APK without precise shrinking:
spec resource 0x7f0902cd <my app package name>:id/search_badge: flags=0x00000000
search_badge
is from layout abc_search_view.xml
from app-compat:1.6.1
.
Interestingly, aapt on that id on the precise APK gives:
INVALID TYPE CONFIG FOR RESOURCE 0x7f0902cd
There are a bunch of these INVALID TYPE CONFIG FOR RESOURCE
lines for other ids too, but it seems a bit random.
I can provide both APKs if necessary
ri...@google.com <ri...@google.com> #8
Just explaining the "INVALID TYPE CONFIG FOR RESOURCE 0x7f0902cd"
The resource shrinker can't fully remove the entries, since the aapt resource id format is: PPTTEEEE where PP is the package id, TT is the type id, and EEEE is the entry id. Instead we "null" out the entry in both the specification table (which is what you copied) and also in the actual entries (but there you simply do not get it with precise shrinking in the aapt output, there should be one for the non precise one though with the actual value)
Please do share the apks with me (
ri...@google.com <ri...@google.com> #9
The problem here is that this is a reflective lookup of the id, which is not kept, and not referenced by code We don't actually collect id references from xml files, so these are not kept if there are no code references (which there is here, it is just reflective, not through R.id.xxxxxxx
For platform we had similar issues, with tests poking at ids from the side, we keep all ids there with a res/raw/shrinker.xml file with the following content:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@id/*"
/>
You should be able to add that to your build for now, I will see if we should make this the default for AGP compilations for now (until we can trace these from all kept layouts)
ri...@google.com <ri...@google.com> #10
For references:
$ disasm.py --no-build --all ~/Downloads/notprecise.apk > /tmp/dis
$ cat /tmp/dis | grep -a "0x7f0902cd\|2131296973"
So no code references
$ aapt dump --values resources ~/Downloads/precise.apk | grep layout/abc_search_view -A 1
spec resource 0x7f0c0019 com.bubblesoft.android.bubbleupnp:layout/abc_search_view: flags=0x00000000
spec resource 0x7f0c001a com.bubblesoft.android.bubbleupnp:layout/abc_select_dialog_material: flags=0x00000000
--
resource 0x7f0c0019 com.bubblesoft.android.bubbleupnp:layout/abc_search_view: t=0x03 d=0x00000320 (s=0x0008 r=0x00)
(string8) "res/dO.xml"
to get the renamed view xml
$ aapt dump xmltree ~/Downloads/precise.apk res/dO.xml | grep -C 7 0x7f0902cd
A: android:id(0x010100d0)=@0x7f0902ce
A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
A: android:layout_height(0x010100f5)=(type 0x10)0xffffffff
E: TextView (line=36)
A: android:textAppearance(0x01010034)=?0x1010041
A: android:textColor(0x01010098)=?0x1010036
A: android:gravity(0x010100af)=(type 0x11)0x10
A: android:id(0x010100d0)=@0x7f0902cd <----------------------------------
A: android:visibility(0x010100dc)=(type 0x10)0x2
A: android:layout_width(0x010100f4)=(type 0x10)0xfffffffe
A: android:layout_height(0x010100f5)=(type 0x10)0xffffffff
A: android:layout_marginBottom(0x010100fa)=(type 0x5)0x201
A: android:drawablePadding(0x01010171)=(type 0x5)0x1
pu...@gmail.com <pu...@gmail.com> #11
Confirming that using res/raw/shrinker.xml
works fine, retaining most of the benefits of the precise shrinker (only +20kb added to the APK with keep rule vs the crashing precise APK without it).
So it might be a good idea to integrate that keep rule by default for now.
ri...@google.com <ri...@google.com> #12
Landed a fix in AGP to default to keeping ids for now, this should hit canary in the next few weeks and you can then delete your shrinker.xml file again
Thanks for the provided apks and info!
an...@google.com <an...@google.com> #13
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
- Android Studio Iguana | 2023.2.1 Canary 12
- Android Gradle Plugin 8.3.0-alpha12
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Thank you for taking the time to submit feedback — we really appreciate it!
pu...@gmail.com <pu...@gmail.com> #14
Thanks for the fix, confirming that shrinker.xml
is not needed anymore.
pu...@gmail.com <pu...@gmail.com> #15
With AS 2023.3.1 Canary 7 / AGP 8.4.0-alpha07, this problem is back again and I had to explicitly add the shrinker.xml file with content above for app to not crash on startup.
ri...@google.com <ri...@google.com> #16
Can you share the generated apk for that with me? That seems very strange
pu...@gmail.com <pu...@gmail.com> #17
APK sent.
ri...@google.com <ri...@google.com> #18
an...@google.com <an...@google.com> #19
The fixes for this issue are now also available in:
- Android Studio Jellyfish | 2023.3.1 Canary 8
- Android Gradle Plugin 8.4.0-alpha08
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
pu...@gmail.com <pu...@gmail.com> #20
Confirming AGP 8.4.0-alpha08 fixes it. Thanks !
Description
Studio Build: Iguana Canary 11 Version of Gradle Plugin: 8.3.0-alpha11
Version of Gradle: 8.4
Version of Java: 17.0.9
OS: Linux
If I generate a (clean) release APK of my app with minification/obfuscation enabled, it will crash on app startup when it loads an XML layout with
android.content.res.Resources$NotFoundException
:There is no such issue with
8.3.0-alpha11