Repository navigation
fix: namespace for libraries which define with legacy convention #495
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@callstack/react-native-brownfield': patch | ||
| --- | ||
|
|
||
| fix: resolve the namespace from AndroidManifest.xml `package` for libraries without a `namespace` in build.gradle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
...kotlin/com/callstack/react/brownfield/utils/AndroidArchiveLibraryNamespaceFallbackTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| package com.callstack.react.brownfield.utils | ||
|
|
||
| import com.callstack.react.brownfield.shared.UnresolvedArtifactInfo | ||
| import org.gradle.testfixtures.ProjectBuilder | ||
| import org.junit.jupiter.api.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertFailsWith | ||
|
|
||
| class AndroidArchiveLibraryNamespaceFallbackTest { | ||
| private fun artifactFor(moduleName: String) = | ||
| UnresolvedArtifactInfo( | ||
| moduleGroup = "com.example", | ||
| moduleName = moduleName, | ||
| moduleVersion = "1.0.0", | ||
| file = null, | ||
| isExpoPublishDependency = false, | ||
| ) | ||
|
|
||
| @Test | ||
| fun `falls back to the AndroidManifest package when build-gradle declares no namespace`() { | ||
| val root = ProjectBuilder.builder().build() | ||
| val subProject = | ||
| ProjectBuilder.builder() | ||
| .withParent(root) | ||
| .withName("react-native-launch-arguments") | ||
| .build() | ||
|
|
||
| // No `namespace` declaration, mirroring libraries whose build.gradle predates AGP namespaces. | ||
| subProject.projectDir.mkdirs() | ||
| subProject.buildFile.writeText( | ||
| """ | ||
| apply plugin: 'com.android.library' | ||
| """.trimIndent(), | ||
| ) | ||
| subProject.projectDir.resolve("src/main").mkdirs() | ||
| subProject.projectDir.resolve("src/main/AndroidManifest.xml").writeText( | ||
| """ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="com.reactnativelauncharguments"> | ||
| </manifest> | ||
| """.trimIndent(), | ||
| ) | ||
|
|
||
| val library = AndroidArchiveLibrary(root, artifactFor("react-native-launch-arguments"), "devRelease") | ||
|
|
||
| assertEquals("com.reactnativelauncharguments", library.getPackageName()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `prefers the namespace declared in build-gradle over the manifest package`() { | ||
| val root = ProjectBuilder.builder().build() | ||
| val subProject = | ||
| ProjectBuilder.builder() | ||
| .withParent(root) | ||
| .withName("react-native-screens") | ||
| .build() | ||
|
|
||
| subProject.projectDir.mkdirs() | ||
| subProject.buildFile.writeText( | ||
| """ | ||
| apply plugin: 'com.android.library' | ||
| android { | ||
| namespace = "com.swmansion.rnscreens" | ||
| } | ||
| """.trimIndent(), | ||
| ) | ||
| subProject.projectDir.resolve("src/main").mkdirs() | ||
| subProject.projectDir.resolve("src/main/AndroidManifest.xml").writeText( | ||
| """ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="com.swmansion.rnscreens.legacy"> | ||
| </manifest> | ||
| """.trimIndent(), | ||
| ) | ||
|
|
||
| val library = AndroidArchiveLibrary(root, artifactFor("react-native-screens"), "devRelease") | ||
|
|
||
| assertEquals("com.swmansion.rnscreens", library.getPackageName()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `reads the package from the manifest root element and ignores comments and child attributes`() { | ||
| val root = ProjectBuilder.builder().build() | ||
| val subProject = | ||
| ProjectBuilder.builder() | ||
| .withParent(root) | ||
| .withName("react-native-legacy-manifest") | ||
| .build() | ||
|
|
||
| subProject.projectDir.mkdirs() | ||
| subProject.buildFile.writeText( | ||
| """ | ||
| apply plugin: 'com.android.library' | ||
| """.trimIndent(), | ||
| ) | ||
| subProject.projectDir.resolve("src/main").mkdirs() | ||
| subProject.projectDir.resolve("src/main/AndroidManifest.xml").writeText( | ||
| """ | ||
| <!-- legacy location: package="com.example.stale" --> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="com.reactnativelegacymanifest"> | ||
| <application> | ||
| <activity | ||
| android:name=".LegacyActivity" | ||
| android:exported="false" | ||
| android:targetPackage="com.example.target" /> | ||
| </application> | ||
| </manifest> | ||
| """.trimIndent(), | ||
| ) | ||
|
|
||
| val library = AndroidArchiveLibrary(root, artifactFor("react-native-legacy-manifest"), "devRelease") | ||
|
|
||
| assertEquals("com.reactnativelegacymanifest", library.getPackageName()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `errors when neither build-gradle nor the manifest declare a namespace`() { | ||
| val root = ProjectBuilder.builder().build() | ||
| val subProject = | ||
| ProjectBuilder.builder() | ||
| .withParent(root) | ||
| .withName("no-namespace-anywhere") | ||
| .build() | ||
|
|
||
| subProject.projectDir.mkdirs() | ||
| subProject.buildFile.writeText( | ||
| """ | ||
| apply plugin: 'com.android.library' | ||
| """.trimIndent(), | ||
| ) | ||
|
|
||
| val library = AndroidArchiveLibrary(root, artifactFor("no-namespace-anywhere"), "devRelease") | ||
|
|
||
| assertFailsWith<IllegalStateException> { library.getPackageName() } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/react-native-brownfield/src/expo-config-plugin/android/utils/constants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| export const BROWNFIELD_PLUGIN_VERSION = '2.0.0-alpha10'; | ||
| export const BROWNFIELD_PLUGIN_VERSION = '2.0.0-alpha11'; | ||
| export const brownfieldGradlePluginDependency = `classpath("com.callstack.react:brownfield-gradle-plugin:${BROWNFIELD_PLUGIN_VERSION}")`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.