-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
[Android] Add support for Build Variants to react.gradle #4686
[Android] Add support for Build Variants to react.gradle #4686
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
What is stage alpha? |
@mkonicek it's an example of a build variant that could be used. "stage" would be the flavor and "alpha" would be the build type. The script finds all the build variants and creates bundle tasks for them, improves upon the previous hardcoded "bundleDebugJsAndAssets" and "bundleReleaseJsAndAssets" tasks |
Thanks for the explanation but still need more context. Where would you use the output of bundleStageAlphaJsAndAssets and bundleBetaJsAndAssets? Would you upload them to the Play store? What's the difference between bundleDevDebugJsAndAssets and bundleDebugJsAndAssets? |
A: The output could be used for testing or uploaded to a tool such as hockey app for internal dogfooding
A: The difference here is the Gradle config. The first uses flavors and build types, and the second only uses build types. The tasks will perform the same action however the use of build variants are useful for Android developers who are dogfooding and developing an app. I have explained in greater detail below. Build types only The config would look like this: android {
buildTypes {
debug {
applicationIdSuffix ".debug"
}
alpha {
applicationIdSuffix ".alpha"
}
release {
...
}
}
} This will generate the tasks:
Flavor + Build types I may want to install the alpha app in the stage environment and install the debug app in the stage environment. I can only achieve this with this configuration. The config would look like this: android {
productFlavors {
dev {
applicationId = "com.example.dev"
}
stage {
applicationId = "com.example.stage"
}
prod {
applicationId = "com.example"
}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
alpha {
applicationIdSuffix ".alpha"
}
release {
...
}
}
} This will generate the tasks:
|
@@ -18,6 +19,10 @@ apply plugin: "com.android.application" | |||
* // whether to bundle JS and assets in debug mode | |||
* bundleInDebug: false, | |||
* | |||
* // whether to bundle JS and assets in another build variant | |||
* // bundleInStageAlpha: true, | |||
* // bundleInBeta: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkonicek I assume you are referring to this? I could change it to something more generic like bundleIn{variantName}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a bit more info here, like explaining the properties, and may be a link on how to configure build variants,
e.g. -
// whether to bundle JS and assets in a build variant (if you have build variants configured, see <link>)
// the configuration property is in the format `bundleIn${productFlavor}${buildType`
// bundleInStageAlpha: true,
// bundleInBeta: true,
@AndrewJack updated the pull request. |
Updated react config comments in build.gradle |
OK thanks for the explanation, get the flavors some. However, I feel like this adds a lot of complexity into the template and the code will have to be maintained. Not everyone might necessarily need these features - no one has been asking about these so far. Do you think it would make more sense to publish this as a blogpost somewhere and people can easily add it to their build files if needed? |
@mkonicek Even if we don't want to merge the build flavours features to the core, I like how the file has been refactored to remove duplicate code. For example the |
Ok, that makes sense, but I agree with @satya164. |
Maybe a separate React Native Gradle plugin would be useful? That would keep the template simple but allow the plugin to be improved separately. |
@AndrewJack updated the pull request. |
OK I played around with Gradle variants today and finally understand variants and flavors somewhat. I like how this removes code duplication, keeps the existing behavior and adds extensibility. @foghina Are you happy with this being merged? |
@@ -18,6 +19,12 @@ apply plugin: "com.android.application" | |||
* // whether to bundle JS and assets in debug mode | |||
* bundleInDebug: false, | |||
* | |||
* // whether to bundle JS and assets in a build variant (if configured). | |||
* // See https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Build-Variants |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a shorter URL: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
Slightly related PR here: #5160 |
I will make the requested changes today. |
name: "$bundleJsAndAssetsTaskName", | ||
type: Exec) { | ||
group = "react" | ||
description = "bundle Js And assets for ${targetName}." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: uppercase S, lowercase A ("bundle JS and...")
This is pretty amazing, sorry for taking a long time to review. Thanks for the PR! We should merge #5160 today so you can rebase on top of that and get this merged as well. |
@AndrewJack updated the pull request. |
1 similar comment
@AndrewJack updated the pull request. |
@AndrewJack updated the pull request. |
Thanks for rebasing this so quickly! I see you're making updates, let me know when we should merge :) |
@AndrewJack updated the pull request. |
1 similar comment
@AndrewJack updated the pull request. |
@mkonicek All done, just had to test it. |
commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file", | ||
entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir | ||
} else { | ||
commandLine "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't --dev
be false
in release build?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to we want to handle this?
- Another config value
- if release then --dev false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if release then dev false is sensible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combination of both isn't too hard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AndrewJack dunno. can't think of a scenario where someone will want production build to have dev warnings. Also if someone does, he can always manually change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@satya164 I would use it for a tester build, to get more logs out of a build.
Its easy to add if someone needs it, so I will just add the "if release option".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AndrewJack sound good.
@AndrewJack updated the pull request. |
workingDir reactRoot | ||
|
||
// Set up dev mode | ||
def devEnabled = !targetName.toLowerCase().contains("release") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dev mode can be made configurable like this:
def devEnabled = config."devMode${targetName}" ?: !targetName.toLowerCase().contains("release")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Sick PR! @facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1655573684725605/int_phab to review. |
bd7d10e
Summary: This PR adds support for Android Gradle [Build Variants](https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Build-Variants) when generating the JS bundle. **Before**: only supported "bundleDebugJsAndAssets" and "bundleReleaseJsAndAssets" **Now**: all variants are supported Examples: "bundleDevDebugJsAndAssets", "bundleStageAlphaJsAndAssets", or "bundleBetaJsAndAssets" The Gradle script will automatically create bundle tasks for each build variant found in a project. Closes facebook#4686 Reviewed By: svcscm Differential Revision: D2815856 Pulled By: foghina fb-gh-sync-id: 4518de70d178205bc3e5044d2446b56c40298da2
Summary: This PR adds support for Android Gradle [Build Variants](https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Build-Variants) when generating the JS bundle. **Before**: only supported "bundleDebugJsAndAssets" and "bundleReleaseJsAndAssets" **Now**: all variants are supported Examples: "bundleDevDebugJsAndAssets", "bundleStageAlphaJsAndAssets", or "bundleBetaJsAndAssets" The Gradle script will automatically create bundle tasks for each build variant found in a project. Closes facebook/react-native#4686 Reviewed By: svcscm Differential Revision: D2815856 Pulled By: foghina fb-gh-sync-id: 4518de70d178205bc3e5044d2446b56c40298da2
This PR adds support for Android Gradle Build Variants when generating the JS bundle.
Before: only supported "bundleDebugJsAndAssets" and "bundleReleaseJsAndAssets"
Now: all variants are supported
Examples: "bundleDevDebugJsAndAssets", "bundleStageAlphaJsAndAssets", or "bundleBetaJsAndAssets"
The Gradle script will automatically create bundle tasks for each build variant found in a project.