Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .github/actions/androidapp-road-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,24 @@ runs:
yarn run brownfield:publish:android
shell: bash

- name: Resolve AAR variants
id: aar-variants
run: |
if [[ "${{ inputs.flavor }}" == "vanilla" ]]; then
echo "debug=devDebug" >> "$GITHUB_OUTPUT"
echo "release=devRelease" >> "$GITHUB_OUTPUT"
else
echo "debug=debug" >> "$GITHUB_OUTPUT"
echo "release=release" >> "$GITHUB_OUTPUT"
fi
shell: bash

- name: Verify debug AAR exists in Maven Local
run: stat ~/.m2/repository/${{ inputs.rn-project-maven-path }}/0.0.1-SNAPSHOT/brownfieldlib-0.0.1-SNAPSHOT-debug.aar
run: stat ~/.m2/repository/${{ inputs.rn-project-maven-path }}/0.0.1-SNAPSHOT/brownfieldlib-0.0.1-SNAPSHOT-${{ steps.aar-variants.outputs.debug }}.aar
shell: bash

- name: Verify release AAR exists in Maven Local
run: stat ~/.m2/repository/${{ inputs.rn-project-maven-path }}/0.0.1-SNAPSHOT/brownfieldlib-0.0.1-SNAPSHOT-release.aar
run: stat ~/.m2/repository/${{ inputs.rn-project-maven-path }}/0.0.1-SNAPSHOT/brownfieldlib-0.0.1-SNAPSHOT-${{ steps.aar-variants.outputs.release }}.aar
shell: bash

# == AndroidApp ==
Expand Down
1 change: 1 addition & 0 deletions apps/AndroidApp/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ android {
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
missingDimensionStrategy("env", "dev")
}

flavorDimensions += "app"
Expand Down
4 changes: 2 additions & 2 deletions apps/RNApp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ yarn-error.log
!.yarn/versions

# Brownfield
android/BrownfieldLib/libsDebug/
android/BrownfieldLib/libsRelease/
android/BrownfieldLib/libs*Debug/
android/BrownfieldLib/libs*Release/

# Benchmarks
android/gradle-user-home/
Expand Down
11 changes: 11 additions & 0 deletions apps/RNApp/android/BrownfieldLib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ android {
)
}
}

flavorDimensions += "env"
productFlavors {
create("prod") {
dimension = "env"
}
create("dev") {
dimension = "env"
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
9 changes: 9 additions & 0 deletions apps/RNApp/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ android {
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
flavorDimensions "env"
productFlavors {
prod {
dimension "env"
}
dev {
dimension "env"
}
}
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion apps/RNApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"ios": "react-native run-ios",
"build:example:android-rn": "react-native build-android",
"build:example:ios-rn": "react-native build-ios",
"brownfield:package:android": "brownfield package:android --module-name :BrownfieldLib --variant release --verbose",
"brownfield:package:android": "brownfield package:android --module-name :BrownfieldLib --variant devRelease --verbose",
"brownfield:publish:android": "brownfield publish:android --module-name :BrownfieldLib --verbose",
"brownfield:package:ios": "brownfield package:ios --scheme BrownfieldLib --configuration Release --verbose",
"lint": "eslint .",
Expand Down
21 changes: 21 additions & 0 deletions gradle-plugins/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,27 @@ reactBrownfield {

<hr/>

**Flavored Android Builds**

To use product flavors and dimensions in your brownfield module, define them as usual:

```kts
flavorDimensions += "env"

productFlavors {
create("prod") {
dimension = "env"
}
create("dev") {
dimension = "env"
}
}
```

This lets you run tasks like `gradle :brownfieldlib:assembleDevRelease`. However, once you add a flavor and dimension to the brownfield module, you must ensure the same flavor and dimension are defined in the `:app` module (your React Native app). This is required so the `brownfield-gradle-plugin` can correctly look up tasks for JavaScript bundling, Expo resources, and native binaries.

If there is a flavor mismatch, the build will fail. If your `:app` module defines multiple flavors, that is fine. You only need to ensure that every flavor used in the brownfield module also exists in the app module.

## Tooling

- We are using `ktlint` and `detekt` for formatting and linting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ object RNSourceSets {

// 2. Use the onVariants block to configure each variant
componentsExtension.onVariants { variant ->
val variantName = variant.name
val bundledAssetsVariantName =
Utils.getBundledAssetsVariantName(
variantName = variant.name,
variantName = variantName,
buildTypeName = variant.buildType,
isDebuggable = variant.debuggable,
)
val capitalizedBundledAssetsVariantName = bundledAssetsVariantName.capitalized()

// 3. Lazily configure the 'main' source set using .named()
androidExtension.sourceSets.named(variant.name) { sourceSet ->
// 3. Lazily configure the 'variant-specific' source set using .named()
androidExtension.sourceSets.named(variantName) { sourceSet ->
// Paths are collected and added, similar to your improved version
val bundlePathSegments =
listOf(
Expand All @@ -72,17 +73,9 @@ object RNSourceSets {
val appBuildDir = getAppBuildDir()
sourceSet.assets.srcDirs(bundlePathSegments.map { "$appBuildDir/generated/assets/$it" })
sourceSet.res.srcDirs(bundlePathSegments.map { "$appBuildDir/generated/res/$it" })
sourceSet.jniLibs.srcDirs("libs${variantName.capitalized()}")
}
}

// These remain the same, but using .named() is the modern, lazy approach
androidExtension.sourceSets.named("release") {
it.jniLibs.srcDirs("libsRelease")
}

androidExtension.sourceSets.named("debug") {
it.jniLibs.srcDirs("libsDebug")
}
}

private fun getLibraryNameSpace(): String {
Expand Down
Loading