Skip to content

feat: detect and report all Android resource references in Manifest files #1450

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

Merged

Conversation

SimonMarquis
Copy link
Contributor

No description provided.

}

private fun parse(manifest: String, dslNamespace: String = ""): ManifestParser.ParseResult {
private fun parse(@Language("XML") manifest: String, dslNamespace: String = ""): ManifestParser.ParseResult {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding this for syntax highlighting in the IDE

@@ -18,8 +19,8 @@ internal class ManifestParser(
val packageName: String,
/** The value of the `android:name` attribute. May be empty. */
val applicationName: String,
/** The values of the `android:theme` attributes of application and activities. May be empty. */
val themes: Set<String>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I merge the themes inside a generic attrRefs.
Also, I parsed it directly as AndroidResSource.AttrRef to make tests more expressive (instead of in explodeAndroidResSource.kt).

@@ -162,7 +161,7 @@ internal data class AndroidResSource(
*
* @see <a href="https://developer.android.com/guide/topics/resources/providing-resources#ResourcesFromXml">Accessing resources from XML</a>
*/
private val TYPE_REGEX = Regex("""@(\w+:)?(?<type>\w+)/(\w+)""")
private val TYPE_REGEX = Regex("""@(\w+:)?(?<type>\w+)/([\w.]+)""")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

. are actually used for styles/themes, otherwise it breaks detects theme set in manifest and detects theme set in manifest on Activity tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also added a unit test for this.

@@ -150,26 +152,60 @@ class ManifestParserTest {
assertThat(manifest.applicationName).isEqualTo("mutual.aid.explode")
}

@Test fun `parse themes`() {
@Test fun `parse resource references`() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this test, I added common references that we are using in our own app. This is definitely not an exhaustive list of all places where references are allowed.

@SimonMarquis SimonMarquis marked this pull request as ready for review May 13, 2025 16:15
Copy link
Owner

@autonomousapps autonomousapps left a comment

Choose a reason for hiding this comment

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

I don't know why it took me so long to get to this - sorry about that. This looks good, but there are some conflicts. Do you mind resolving? Happy to merge once that is done.

@SimonMarquis
Copy link
Contributor Author

SimonMarquis commented Aug 8, 2025

@autonomousapps i've resolved the conflicts 🫡

Edit: talked too soon, let me take care of the compilation issues.

@autonomousapps autonomousapps merged commit dbc0f04 into autonomousapps:main Aug 9, 2025
1 check passed
@SimonMarquis SimonMarquis deleted the android-manifest-res-attr branch August 9, 2025 15:04
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.

2 participants