Skip to content

Commit 90f5a65

Browse files
authored
Merge pull request #118 from callstack/feat/expo-support
feat: add expo support for brownfield gradle plugin
2 parents 104a227 + 2d30cfe commit 90f5a65

4 files changed

Lines changed: 64 additions & 2 deletions

File tree

gradle-plugins/react/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ dependencies {
132132

133133
<hr/>
134134

135+
- **Expo Support**
136+
137+
By default expo support is disabled. You can enable it by setting the following to `true`:
138+
139+
```kts
140+
reactBrownfield {
141+
isExpo = true
142+
}
143+
```
144+
145+
This will take care of linking the expo dependencies like `expo-image` to your AAR.
146+
147+
<hr/>
148+
135149
## Tooling
136150

137151
- We are using `ktlint` and `detekt` for formatting and linting

gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/artifacts/ArtifactsResolver.kt

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,48 @@ class ArtifactsResolver(
5050
}
5151
}
5252

53+
private fun embedExpoDependencies() {
54+
/**
55+
* expo project does not exist in example-android-library so doing an
56+
* early exit.
57+
*/
58+
if (baseProject.project.name == "example-android-library") {
59+
return
60+
}
61+
62+
/**
63+
* The expo third party dependencies are linked to `expo` project.
64+
* They are linked via `api` configuration and in two ways. In the
65+
* first way, they are linked as a subProject or local dependencies.
66+
* In the second way, they are linked as local maven hosted dependencies.
67+
*
68+
* We get those dependencies of `expo` project and add those to the consumer
69+
* library project.
70+
*/
71+
val expoProject = baseProject.project.rootProject.project("expo")
72+
val expoConfig = expoProject.configurations.findByName("api")
73+
expoConfig?.dependencies?.forEach {
74+
if (extension.resolveLocalDependencies) {
75+
if (it is DefaultProjectDependency) {
76+
baseProject.project.dependencies.add(
77+
CONFIG_NAME,
78+
expoProject.dependencies.project(mapOf("path" to ":${it.name}")),
79+
)
80+
} else {
81+
baseProject.project.dependencies.add(
82+
CONFIG_NAME,
83+
it,
84+
)
85+
}
86+
}
87+
}
88+
}
89+
5390
private fun embedDefaultDependencies(configName: String) {
91+
if (extension.isExpo) {
92+
embedExpoDependencies()
93+
}
94+
5495
val config = baseProject.project.configurations.findByName(configName)
5596
val defaultDependencies = config?.dependencies?.filterIsInstance<DefaultProjectDependency>()
5697
defaultDependencies?.forEach { dependency ->
@@ -95,7 +136,7 @@ class ArtifactsResolver(
95136
private fun resolveArtifacts(configuration: Configuration): Collection<ResolvedArtifact> {
96137
val artifacts = ArrayList<ResolvedArtifact>()
97138
configuration.resolvedConfiguration.resolvedArtifacts.forEach { artifact ->
98-
if (artifact.type != ARTIFACT_TYPE_AAR || artifact.type != ARTIFACT_TYPE_JAR) {
139+
if (artifact.type != ARTIFACT_TYPE_AAR && artifact.type != ARTIFACT_TYPE_JAR) {
99140
throw ProjectConfigurationException("Unsupported dependency. Please provide either Aar or Jar dependency", listOf())
100141
}
101142
artifacts.add(artifact)

gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/processors/VariantHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class VariantHelper(private val variant: LibraryVariant) : BaseProject() {
148148
filteredSourceSets.forEach { sourceSet ->
149149
val filteredAarLibs = aarLibraries.filter { it.getAssetsDir().exists() }
150150
filteredAarLibs.forEach {
151-
sourceSet.assets.srcDir(it)
151+
sourceSet.assets.srcDir(it.getAssetsDir())
152152
}
153153
}
154154
}

gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/utils/Extension.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ open class Extension {
2929
* Default value is `app`
3030
*/
3131
var appProjectName = "app"
32+
33+
/**
34+
* Sets whether the consumer project is based on Expo.
35+
*
36+
* Default value is `false`
37+
*/
38+
var isExpo = false
3239
}

0 commit comments

Comments
 (0)