-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Avoid referencing resource names within Resource Loader #5388
Conversation
@benjaminRomano thanks for the pull request and sorry for the delay in reviewing it. Do you have an update on your test Plan, ("TODO: still building locally and verifying")? Can you update your commit message with the answer? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you squash this commit with your other commits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be extra safe, would it be possible for you to flag guard this change, roll it out in your binary, verify there are no issues, and then clean-up the flag?
See recent pull requests where this was done:
I tried to build locally, but I'm hitting the following error when running
I'm OK with wiring an experiment if need be, but it's likely unnecessary precautions. The content URI format being used has been around since Cupcake (ref): https://developer.android.com/reference/android/content/ContentResolver#the-android.resource-scheme_android_resource-scheme The equivalent code in AOSP can be found here: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/content/ContentResolver.java;l=1499?q=SCHEME_ANDROID_RESOURCE Tracing the AOSP source code, it can be verified that migrating the the new content URI scheme is safe. Effectively, About a month or two ago, we migrated all our content URIs to the new format for Snapchat and did not encounter any issues as expected.
I can do this once I've addressed all comments, but you'll also be able to squash merge my commits and re-write the commit messages when you merge changes through Github. |
Sorry for the late reply. I use JDK 17 to build. On my macOS device, I run
to build Glide. Thanks for addressing my other comments. Unfortunately, this repo is not configured to allow squashing and merging (and I don't have permission to change that). Can you take care of the squashing? |
Squash merged my commits. it should be good to go now. Unfortunately, I still can't get the dependency error. If I find some time, I'll dig into it further. Potentially this is an issue with some kind of global gradle config being mis-configured |
@falhassen when should I expect new version of Glide to be released? |
@benjaminRomano unfortunately getting a new version of Glide may take some time. However, you can immediately deploy the new changes in your app by depending on a Glide snapshot, following Glide's instructions: https://bumptech.github.io/glide/dev/snapshots.html#about-snapshots. I believe 5.0.0-SNAPSHOT/ should have your commit. |
@falhassen following up here. Any luck in getting publishing working? We cannot easily consume SNAPSHOTs internally due to how we mirror external dependencies into our own internal repositories. |
Prior to this change, did you see images that failed to load? If so, can you give an example? Were you calling something like:
And if you enable this optimization but don't have this PR, then the image load fails? |
Prior to stripping our Resource Table names, the images load as expected. With resource name stripping in the Resource Table, the wrong image was getting loaded. All Glide image loads going through this code path would load the same incorrect image.
Unfortunately, There's a lot of indirection in our codebase so I don't have a clear example of how we are constructing the request and I've personally not worked on our Glide codebase myself so I'm not sure how to create a trivial example (basically just need to ensure the ResourceLoader code path modified is triggered is enough). As an aside, creating a full sample of this issue is a bit tough as AGP doesn't support this yet AFAIK. Best that could be done is use https://github.com/shwenzhang/AndResGuard to forcibly strip resource names. |
Interesting. And do you know that this fixes that issue? What version of Glide are you currently using (5.x or 4.x)? One way to work around this while you wait for a release is to use a LibraryModule to
You'd need to replace |
Yep! This fix is ultimately what we did for other callsites we found in our app that were broken due to the same issue.
4.15.0
Thanks for the suggestion. I did try to see if it would be possible to swap out the implementation in our codebase, but couldn't make sense of our Glide initialization logic internally (lots and lots of indirection 😅) The request isn't urgent from our side. Whenever we can get this fix, we'll be able to shave off ~200KB of app size from the resource names but not causing any blocking issues for us. |
Following up here, did we figure out how to get Glide open source releases going again? |
Description
We are working on enabling the collapse names optimization of
aapt2
that removes the resource names from the Resource Table as an app size optimization. However, once enabled, we ran into issues loading resources.One requirement of removing resource names from the Resource Table is ensuring that resources are not referenced by resource name when loaded. If they are referenced by resource name, they must be explicitly kept with keep rules. (ref).
Motivation and Context
ResourceLoader is using the
android.resource://<package_name>/<resource_type>/<resource_name>
content URI to resolve Drawable resources, which is incompatible with collapse names optimization.Fortunately, the ContentResolver for resources has another URI scheme that enables loading resources without referencing the name:
android.resource://<package_name>/<resource_id>
, which can be used instead (ref).Test Plan
Pre-merge passes (TODO: still building locally and verifying)