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

Enable non-final resource IDs #21179

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft

Conversation

jkmassel
Copy link
Contributor

@jkmassel jkmassel commented Aug 29, 2024

Mostly just curious if this will work – Android Studio says it'll speed up build times


To Test:


Regression Notes

  1. Potential unintended areas of impact

    • TODO
  2. What I did to test those areas of impact (or what existing automated tests I relied on)

    • TODO
  3. What automated tests I added (or what prevented me from doing so)

    • TODO

PR Submission Checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Testing Checklist (strike-out the not-applying and unnecessary ones):

  • WordPress.com sites and self-hosted Jetpack sites.
  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • Talkback.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • Large and small screen sizes. (Tablet and smaller phones)
  • Multi-tasking: Split screen and Pop-up view. (Android 10 or higher)

@jkmassel jkmassel force-pushed the enable/android-nonFinalResIds branch from 8657fb8 to 683099c Compare August 29, 2024 20:06
@dangermattic
Copy link
Collaborator

1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

Copy link

sonarcloud bot commented Aug 29, 2024

@wpmobilebot
Copy link
Contributor

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr21179-683099c
Commit683099c
Direct Downloadwordpress-prototype-build-pr21179-683099c.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr21179-683099c
Commit683099c
Direct Downloadjetpack-prototype-build-pr21179-683099c.apk
Note: Google Login is not supported on these builds.

@nbradbury
Copy link
Contributor

@jkmassel This PR has been a draft for over a month. Do we need to close it or update it to be ready for review?

@jkmassel
Copy link
Contributor Author

@jkmassel This PR has been a draft for over a month. Do we need to close it or update it to be ready for review?

I have no idea if this is how it should be done or even a good idea – I'm hoping @wzieba or @ParaskP7 could weigh in, but I figured I'd ask after the FluxC stuff lands?

@ParaskP7
Copy link
Contributor

ParaskP7 commented Oct 18, 2024

👋 @jkmassel @nbradbury and thanks for the ping!

I have no idea if this is how it should be done or even a good idea.

In terms of keeping up with the standards, this is indeed a good idea. As of AGP 8.0, the default value is true, meaning resource IDs are non-final by default. As such, it is (usually) better to use the default whenever possible.

Mostly just curious if this will work – Android Studio says it'll speed up build times

FYI:

  • When set to true (non-final IDs), resource IDs can be dynamically modified at runtime.
  • When set to false (final IDs), resource IDs are constants and cannot be changed at runtime.

Performance wise, non-final IDs could actually have a slight performance impact, as the values need to be looked up at runtime rather than being inlined as constants. However, this impact is generally minimal in most applications. Thus, I wouldn't worry too much about that.

PS: This became an AGP default because if has the potential for build time improvements and allowing for more flexible runtime resource loading and manipulation.


NOTE: If you proceed with this change I would recommend the following:

  1. When updating an switch statements with if/else, to do it via AS and via automatic refactoring. Avoid manual refactor, just to be on the safe side. You could command + enter on that switch keyword and select Replace 'switch' with 'if'.
  2. For updating the const val into val, I would recommend against that. Instead, just delete the constant and use the actual resource directly whenever needed, even if that means replacing the constant multiple times here and there, main and test source included. For example:
    • On this const val AVATAR_LEFT_OFFSET_DIMEN = R.dimen.margin_small_medium bit of code.
    • This R.dimen.margin_small_medium could be already considered as constant. No need to transform that to AVATAR_LEFT_OFFSET_DIMEN and reuse this instead, I personally think this is an overkill, and actually, in this case doesn't serve us well. Having it as a non constant var breaks the coding guideline (camel-case vs upper-case) but more importantly has the potential for this var to be updated down the line, which could result in more problems.

Hope I helped a bit! 🙏


Btw, this android.nonFinalResIds value change would also need to be update in .mobile-secrets and then this change applied via bundle exec fastlane run configure_apply on this repo.

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

Successfully merging this pull request may close these issues.

5 participants