Skip to content

Comments

fix: use standard res-auto namespace for app attributes#20022

Merged
BrayanDSO merged 1 commit intoankidroid:mainfrom
pankaj0695:fix-20018
Jan 7, 2026
Merged

fix: use standard res-auto namespace for app attributes#20022
BrayanDSO merged 1 commit intoankidroid:mainfrom
pankaj0695:fix-20018

Conversation

@pankaj0695
Copy link
Contributor

Purpose / Description

Some preference XML files used a deprecated custom app namespace URI (http://arbitrary.app.namespace/com.ichi2.anki) instead of the standard http://schemas.android.com/apk/res-auto and/or a non-standard prefix (app1) for custom attributes.
This caused aapt to fail resolving custom attributes and resulted in build errors like attribute max not found.

Fixes

Approach

Replaced the deprecated app namespace URI with the standard xmlns:app="http://schemas.android.com/apk/res-auto" in affected preference XML files.
Renamed the custom attribute prefix from app1 to app so the custom attributes resolve consistently via res-auto.

How Has This Been Tested?

Tested on Android Studio emulator: Medium Phone, API 29 (Android 10).
Verified the affected preference screens load correctly and the app builds without aapt attribute/namespace errors.

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

Copy link
Member

@BrayanDSO BrayanDSO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested, but the code looks good

@BrayanDSO BrayanDSO added the Needs Second Approval Has one approval, one more approval to merge label Jan 5, 2026
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work :/

Image

Copy link
Member

@BrayanDSO BrayanDSO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs fixing in IncrementerNumberRangePreference as well

val resAuto = attrs.getAttributeIntValue("http://schemas.android.com/apk/res-auto", "min", Int.MIN_VALUE)
if (resAuto != Int.MIN_VALUE) return resAuto

return attrs.getAttributeIntValue(AnkiDroidApp.XML_CUSTOM_NAMESPACE, "min", 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason AnkiDroidApp.XML_CUSTOM_NAMESPACE is still in use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s still used for backwards compatibility with legacy android.preference.* preferences (NumberRangePreference, StepsPreference) that read custom attrs via getAttribute*Value(namespaceUri, ...). I’m reading res-auto first and keeping AnkiDroidApp.XML_CUSTOM_NAMESPACE as a fallback to avoid breaking any older XML.
Would you like me to remove the legacy namespace support from this and the StepsPreference code?

Copy link
Member

@david-allison david-allison Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand it, Brayan would like the entire namespace gone.

The details of custom XML namespaces in Android aren't something I'm familiar with, but I can't see a reason we'd want to keep it if the default app: namespace would work, and from a high-level perspective, removing the whole namespace is cleaner architecturally.

@BrayanDSO am I correct in my thinking here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's only used at cram_deck_options, it can be ignored since #19669 will be merged soon.

About the rest, I couldn't have said it better myself.

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Jan 5, 2026
@pankaj0695
Copy link
Contributor Author

I have made the requested changes and also tested it.

Screenshot 2026-01-05 at 9 07 25 PM Screenshot 2026-01-05 at 9 07 42 PM

@david-allison david-allison added Needs Review and removed Needs Author Reply Waiting for a reply from the original author Needs Second Approval Has one approval, one more approval to merge labels Jan 5, 2026
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app1 still exists:

xmlns:app1="http://schemas.android.com/apk/res-auto"

@pankaj0695
Copy link
Contributor Author

Now I am using RES_AUTO_NAMESPACE everywhere and also change app1 to app and also checked for its occurrences in the code

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as-per comment

Please check the 'files changed' before submitting so we're reviewing a clean & final change

<attr name="summaryFormat" format="string"/>
</declare-styleable>

<declare-styleable name="NumberRangePreferenceCompat">
Copy link
Member

@david-allison david-allison Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be unused. I would have expected a declare-styleable for each preference, rather than using the hardcoded namespace.

Why did you choose the namespace option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is unused because I'm not reading min/max via R.styleable in preference, I used http://schemas.android.com/apk/res-auto as a shortcut.
Should I define a declare-styleable for each preference(NumberRangePreference, NumberRangePreferenceCompat & StepsPreference) and read attributes via R.styleable, instead of using the namespace approach?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why you chose the hardcoded namespace option. It's not something I'm too familiar with.

declare-styleable seems better intuitively, but I want to understand your reasoning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I did it this way because the preference was using XML_CUSTOM_NAMESPACE so I thought to use RES_AUTO_NAMESPACE the similar way. But now I will use declare-styleable which is better and update the code accordingly.

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Jan 6, 2026
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cheers. Needs squashing

Comment on lines 42 to 43
<attr name="min" />
<attr name="max"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconsistent spacing

fix NumberRangePreference

remove XML_CUSTOM_NAMESPACE

used RES_AUTO_NAMESPACE everywhere its needed and change app1 to app

Remove RES_AUTO_NAMESPACE and instead used declare-styleable

fix spacing in attrs.xml
@BrayanDSO BrayanDSO added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Author Reply Waiting for a reply from the original author Needs Review labels Jan 7, 2026
@BrayanDSO BrayanDSO added this pull request to the merge queue Jan 7, 2026
Merged via the queue into ankidroid:main with commit f157e17 Jan 7, 2026
15 checks passed
@github-actions github-actions bot added this to the 2.24 release milestone Jan 7, 2026
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Jan 7, 2026
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.

Deprecate usage of app1 in preferences

3 participants