Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32422
While working on the NDK AGP Api I realized that the `enableVmCleanup` function,
that is supposed to cleanup the extra `.so` files from the final artifacts, is broken
for apps with variants. Specifically say for a `liteDebug` app it tries to search for `.so` files inside:
```
intermediates/stripped_native_libs/lite/debug/out/lib
```
while the `.so` files are located inside:
```
intermediates/stripped_native_libs/liteDebug/out/lib
```
I've fixed changing the token of the path from `targetPath` to `variant.name`
Changelog:
[Android] [Fixed] - Fix enableVmCleanup not working for apps with product flavors
Reviewed By: ShikaSD
Differential Revision: D31654704
fbshipit-source-id: 4af3478a3079ebcde4bd8e0c62bf4df7b6c75c0f
Summary:
Ref https://github.com/facebook/react-native/issues/25601#issuecomment-510856047.
From https://github.com/facebook/react-native/pull/31040.
The `hermesFlagsRelease` option only works with the release build type, but not with other build types.
This PR allows hermes flags on a per variant basis to be specified using the `hermesFlagsForVariant` lambda.
It also allows the hermes debugger cleanup to be run on a per variant basis using the `deleteDebugFilesForVariant` lambda.
## Changelog
<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->
[Android] [Fixed] - Fix hermesFlags not working with multiple variants
Pull Request resolved: https://github.com/facebook/react-native/pull/32281
Test Plan:
Set the following options in `android/app/build.gradle` and ensure warnings are hidden when running `./gradlew assembleRelease` and `./gradlew assembleLive`.
```
hermesFlagsForVariant: {
def v -> v.name.toLowerCase().contains('release') || v.name.toLowerCase().contains('live') ? ['-w'] : []
},
deleteDebugFilesForVariant: {
def v -> v.name.toLowerCase().contains('release') || v.name.toLowerCase().contains('live')
},
```
Reviewed By: cortinico
Differential Revision: D31234241
Pulled By: ShikaSD
fbshipit-source-id: 2cb3dd63adbcd023061076b5a3b262a87b470518
Summary:
When using monorepo with react-native you need to provide `android/app/build.gradle` following params(`cliPath`):
```
project.ext.react = [
root: "../../../../",
cliPath: "../../../../node_modules/react-native/cli.js",
entryFile: "...",
hermesCommand: "../../../../node_modules/hermes-engine/%OS-BIN%/hermesc"
]
```
With latest react-native `0.64.2` version you will get:
```
* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'node'' finished with non-zero exit value 1
```
Debugging this issue showed that providing `cliPath` options ends up building wrong path to cli:
```
> Task :app:bundleReleaseJsAndAssets FAILED
node:internal/modules/cjs/loader:944
throw err;
^
Error: Cannot find module '/node_modules/react-native/cli.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
at Function.Module._load (node:internal/modules/cjs/loader:774:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
```
Changed `react.gradle` for proper File creation for `cliPath` to support this configuration option.
## Changelog
[Android] [Fixed] - Changed `react.gradle` `detectCliPath` function logic for `cliPath` case
Pull Request resolved: https://github.com/facebook/react-native/pull/31839
Test Plan: Run `./gradlew assembleRelease` or `./gradlew assembleDebug`
Reviewed By: yungsters
Differential Revision: D30877674
Pulled By: sshic
fbshipit-source-id: 26b75f8d29bf26b01630dde576b9052d0b94d89e
Summary:
Fixes https://github.com/facebook/react-native/issues/29577 and https://github.com/react-native-community/upgrade-support/issues/93, when building an android library the package task has a different name, which was not handled correctly in the react.gradle file. The fix uses the existing `packageTask` variable which is correctly set for applications and libraries. This PR also copies the bundled js file into the correct assets directory, which is different from the assets directory of applications.
## Changelog
<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->
[Android] [Fixed] - Fixed Android library builds with react.gradle file
Pull Request resolved: https://github.com/facebook/react-native/pull/32026
Test Plan: Tested with my android library build which includes the `react.gradle` file and the build succeeded.
Reviewed By: sshic, ShikaSD
Differential Revision: D30368771
Pulled By: cortinico
fbshipit-source-id: 8f0df8c4d0fa38d85f7c0b9af56d88799571191d
Summary:
Homebrew on M1 installs executable binaries in **/opt/homebrew/bin** (See https://brew.sh/2021/02/05/homebrew-3.0.0/), and FBReactNativeSpec.build is failing because it couldn't find node. This PR changes find-node.sh script to add /opt/homebrew/bin into $PATH.
The way **react.gradle** trying to execute node is not using user environment variables, but system defaults, so it couldn't find it. I removed node execution, and hard coded cli path in parity with iOS d1ab03235c/scripts/react-native-xcode.sh (L106)
Fixes https://github.com/facebook/react-native/issues/31621https://github.com/facebook/react-native/issues/31592
## Changelog
[General] [Changed] - find-node.sh supports Homebrew on M1
Pull Request resolved: https://github.com/facebook/react-native/pull/31622
Test Plan: On M1, create a RN project and it'll fail to build iOS app. Apply the patch, and build will succeed.
Reviewed By: ShikaSD
Differential Revision: D28808206
Pulled By: hramos
fbshipit-source-id: 8b313b6685462a15e67d99c61a0202d17fece1ec
Summary:
Minification is not needed for hermes as it does all required optimisations on the bytecode. This is what facebook does internally for hermes bundles and I also validated by comparing the bytecode bundle size on a minified and non-minified bundle.
## Changelog
[General] [Changed] - Don't minify JS bundle by default when using hermes
Pull Request resolved: https://github.com/facebook/react-native/pull/30496
Test Plan: Verified that the JS bundled generated on Android and iOS when using hermes is not minified by checking the generated JS file manually.
Reviewed By: rickhanlonii
Differential Revision: D25235195
Pulled By: cpojer
fbshipit-source-id: ad2131aab4dfd17ab53b6a5720ed0e2f1b09cca4
Summary:
Fix typo in comment
## Changelog
<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->
[CATEGORY] [TYPE] - Message
Pull Request resolved: https://github.com/facebook/react-native/pull/30330
Reviewed By: fkgozali
Differential Revision: D25062086
Pulled By: PeteTheHeat
fbshipit-source-id: 251bf1d4f4986f77ae72f7654796ae1d49c1863d
Summary:
- This fix resolves https://github.com/facebook/react-native/issues/29398
- After updating gradle to 6.5+ and android gradle plugin to 4.1.0+(which is recommended in the latest Android Studio 4.1), Running `:app:assembleRelease` or `:app:bundleRelease` will not contain `index.android.bundle` in Apk/AAB. It will be included when the command executed twice.
<img width="949" alt="Screen Shot 2020-10-17 at 11 32 43 PM" src="https://user-images.githubusercontent.com/6277118/96360808-38165c00-10d5-11eb-8b6e-f098517a24c7.png">
- This is caused by the task ordering update introduced in gradle plugin 4.1.0+/gradle 6.5. `mergeResources` task runs before `currentAssetsCopyTask`(copying the bundle asset file to intermediate output directory) which causes generated Apk/AAB not including the bundle file.
- The fix ensures mergeResources task runs after currentAssetsCopyTask
## Changelog
[Android] [Fixed] - Fix App Bundle/Release build missing index.android.bundle with gradle plugin 4.1.0/gradle 6.5
Pull Request resolved: https://github.com/facebook/react-native/pull/30177
Test Plan:
- Reproducible repository https://github.com/tomoima525/android_build_test_rn
- This project is generated with `create-react-native-app` and updated Gradle version to 6.5 and com.android.tools.build:gradle plugin to 4.1
- Run `./gradlew clean :app:assembleRelease` and `./gradlew clean :app:bundleRelease` => reproduces the issue
- After adding the fix above and run `./gradlew clean :app:assembleRelease` and `./gradlew clean :app:bundleRelease` => The issue is resolved
- Also confirmed the build works properly with android gradle plugin `3.5.3` and `gradle 6.2`(the default value of `create-react-native-app`)
Reviewed By: fkgozali
Differential Revision: D24551605
Pulled By: cpojer
fbshipit-source-id: b0effe2c6ea682748af185061af951e2f2bce722
Summary:
Instead of applying configs from gradle scripts, this introduces a proper Gradle plugin to enable Codegen in an application or library project. In the build.gradle, one enables it by:
```
plugins {
id("com.android.application")
id("com.facebook.react.codegen") // <---
}
// ...
react { // <--- the new plugin extension
enableCodegen = System.getenv("USE_CODEGEN")
jsRootDir = file("$rootDir/RNTester")
reactNativeRootDir = file("$rootDir")
}
```
The plugin supports `react` plugin extension as demonstrated above. Adding this:
* automatically generates all TurboModule Java files via react-native-codegen **before the `preBuild` Gradle task**
* automatically adds the files to the `android {}` project configuration
* is done per project (build.gradle)
This will be the foundation for future React Native gradle plugin beyond just for react-native-codegen.
Changelog: [Internal]
Reviewed By: mdvacca
Differential Revision: D23065685
fbshipit-source-id: 4ea67e48fab33b238c0973463cdb00de8cdadfcc
Summary:
Introduced `architecture.gradle` that sets up pluggable build-time codegen steps for Gradle so that:
* Libraries, including core ReactAndroid, can produce the new architecture codegen (NativeModule **Java** specs in this diff) during build time
* Hosting app (e.g. RNTester) can produce its own set of codegen specs separately
**Please note that this is still work in progress, hence app templates have not been updated to use it yet.**
In order to activate this setup, the env variable `USE_CODEGEN=1` must be set. Eventually, this var will be removed from the logic.
With this change, RNTester:
* Will see all the generated specs populated in the Gradle build dir, which should be equivalent to the currently [**checked in version**](https://github.com/facebook/react-native/tree/master/ReactAndroid/src/main/java/com/facebook/fbreact/specs).
* The specs will compile, but **have not been validated** vs the existing NativeModule .java classes through out the core -- that will be the next step
* The specs are under `com.facebook.fbreact.specs.beta` namespace, which will be configurable in the future. `.beta` is added to avoid conflict with the existing files in the repo.
### Is this all we need to enable TurboModule in Android?
No. There are a few more pieces needed:
* C++ codegen output for JNI layer for each NativeModule spec
* The C++ module lookup for TurboModule Manager
* The JNI build setup in Gradle for these C++ output
* Toggle to enable TurboModule system in the entire app
Changelog: [Internal]
Reviewed By: JoshuaGross
Differential Revision: D22838581
fbshipit-source-id: d972e2fbb37bdbd3354e72b014fc8bb27a33b9ac
Summary:
Running `./gradlew assembleRelease` fails as the path to the CLI contains a new line at the end. We don't run this command in `debug` mode, hence it passed the testing. My bad.
Fixed, checked in both `debug` with `bundleInDebug: true` and `release`.
Fixes https://github.com/facebook/react-native/issues/28700
## Changelog
[INTERNAL] [ANDROID] - Fix `React.gradle` to build Android apps in production
Pull Request resolved: https://github.com/facebook/react-native/pull/28776
Test Plan: Running `./gradlew assembleRelease` works
Reviewed By: hramos
Differential Revision: D21287789
Pulled By: TheSavior
fbshipit-source-id: dc3ec8eef7a919b072b562d2bd455e2f704bc083
Summary:
The `cliPath` has always been optional value and in fact, even had its default value hardcoded in the React gradle file.
In this PR, I am just taking use of it and remove throwing an error, which is going to be a really annoying breaking change.
## Changelog
[ANDROID] [INTERNAL] - Don't require `cliPath`
Pull Request resolved: https://github.com/facebook/react-native/pull/28625
Test Plan:
Run Android project, everything works.
Provide custom `cliPath`, it gets respected
Reviewed By: cpojer
Differential Revision: D21044222
Pulled By: TheSavior
fbshipit-source-id: 8029f988d92abb9f64f30e05932c0d407d0c997e
Summary:
Use the latest published release of hermes-engine. Update RN to invoke `hermesc` instead of `hermes`.
Changelog: [Android] [Changed] - Upgraded to Hermes 0.5.0
allow-large-files
Reviewed By: mhorowitz
Differential Revision: D20998564
fbshipit-source-id: 4824e273bcb044029a5a7e9379f168d3da47da50
Summary:
Recently we removed `npx` usage from `react-native-cli` flow. After checking usages in this repo I found unused reference.
## Changelog
<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->
[Internal] [Removed] - Remove unused `npx` reference
Pull Request resolved: https://github.com/facebook/react-native/pull/28544
Test Plan: Tests pass
Reviewed By: cpojer
Differential Revision: D20873090
Pulled By: hramos
fbshipit-source-id: 12e05e9635a83f19439024766817e4599320af98
Summary:
This fix aims to address the issue when bundling an Android app for release and getting the error exhibited in https://github.com/facebook/react-native/issues/28002 which I also encountered myself.
The config was changed sometime in November 2019 (as part of https://github.com/facebook/react-native/issues/26940, commit a3b0804867) to be very opinionated when it comes to the use of `npx` which Gradle itself cannot find anyway (I have `npx` installed globally and it didn't pick it up).
Another issue that the use of `npx` creates is that Gradle should only ever use the currently installed react-native cli rather than a (possibly) higher version which may not always have backward compatibility.
The proposed change simply throws a more descriptive error rather than defaulting to a tool which may or may not exist on the machine, be it CI or a development environment. I've also modified the RNTester app to reflect the correct config implementation relative to the RNTester app itself.
In real projects, the config inside `android/app/build.gradle` should look similar to the following snippet:
```
project.ext.react = [
cliPath: "$rootDir/../node_modules/react-native/cli.js",
entryFile: "index.js"
];
```
## Changelog
[Android] [Fixed] - Gradle release config
Pull Request resolved: https://github.com/facebook/react-native/pull/28415
Test Plan:
- [x] Successfully bundled an Android release build with correct config
- [x] Works with RNTester app
Reviewed By: mdvacca
Differential Revision: D20714372
Pulled By: hramos
fbshipit-source-id: 4d66139249c6f840582a71a48c64e6a6595f7af0
Summary:
In monorepo environment, `metro` isn't able to resolve `react-native` because the path to it is hardcoded.
I've also added `packagingOptions` to RNTester to make Android builds work for me. Let me know if this is something that is only specific to my setup, and shouldn't be added.
## Changelog
[Android] [Fixed] - Fix `bundleReleaseJsAndAssets` in monorepo env
Pull Request resolved: https://github.com/facebook/react-native/pull/26940
Test Plan:
- [x] - Works in monorepo setup on MacOS
- [x] - Works with RNTester app
Differential Revision: D18323703
Pulled By: cpojer
fbshipit-source-id: b8eb15dfd8a32ae11fd862fc725af9cffea2cf96
Summary:
Fix `react.gradle`'s handling of the case where a configuration isn't explicitly specified by the parent project - e.g. before importing to `build.gradle` files:
```groovy
apply plugin: 'com.android.application'
// Nothing to define:
// project.ext.react = [
// ]
apply from: "../../node_modules/react-native/react.gradle"
```
This is a _ridiculously_ subtle change but it is nevertheless important, as, combined with other groovy quirks, it can result in an overall misbehaviour of the build script.
### Source of the bug
Currently, when a react build config _isn't_ specified by the user, RN's `react.gradle` falls back to `[]` (i.e. in [this line](81a6b6ed3c/react.gradle (L8))). In groovy, `[]` stands for an empty _array_ (actually, an empty `ArrayList` instance). The config, however, is expected to have the nature of a `Map`.
### Effects of the bug
As a bottom line, whenever a configuration isn't specified, the evaluation of [the condition](81a6b6ed3c/react.gradle (L184)) as to whether the bundling task in question should be enabled, results in the following build-time exception:
```
FAILURE: Build failed with an exception.
* Where:
Script '/Users/...../node_modules/react-native/react.gradle' line: 179
* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:bundleDebugJsAndAssets'.
> Could not find method enabled() for arguments [[]] on task ':app:bundleDebugJsAndAssets' of type org.gradle.api.tasks.Exec.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 9s
```
I'm not much of a Groovy person, but while digging in, I've learned that it has the following odd attribute to it:
When accessing a non-existing property of an empty `ArrayList` in a bean-like fashion (i.e. as `array.property1` rather than `array.getProperty('property1')`), a new empty array is returned. This only holds true for _empty_ arrays, as illustrated by the following snippet:
```groovy
def emptyArr = []
def arr = [40, 2]
def result1 = (emptyArr.uninitializedProp == null)
println "$result1, ${emptyArr.uninitializedProp}" // ==> false, []"
def result2 = (arr.uninitializedProp == null) // ==> MissingPropertyException
println result2 // Never reached
```
While this whole scheme could be a bug, it's nonetheless effective in both the latest 2.x.x groovy version and in 2.1.0 (which is the oldest one that seems to be available for download nowadays). The point being is that its a behavior that's sticked.
Note that other evaluations of `config` properties (e.g. [lines 10-19](81a6b6ed3c/react.gradle (L10))) in the script are not effected by this as they are initially only examined in a boolean form, rather than using a null comparison; "Lucky" for us, empty arrays evaluate to `false`.
### Fix
Simply fallback to a groovy map rather than an array whenever `config` hasn't been specified. Namely, initialize it to `[:]`, which results in a new `HashMap` instance, rather than `[]`.
### Workaround
Until effectively fixed, can be worked-around by explicitly setting config to an empty map before the react gradle script is imported by the user:
```groovy
apply plugin: 'com.android.application'
project.ext.react = [:]
apply from: "../../node_modules/react-native/react.gradle"
```
## Changelog
[Android] [Fixed] - Fix 'Could not create task ':app:bundleDebugJsAndAssets'.' error in project with no react config
Pull Request resolved: https://github.com/facebook/react-native/pull/27101
Test Plan: Mostly regression is required here. I've myself ran this over a project with an empty config and the app has launched successfully in both `release` and `debug` flavors.
Differential Revision: D18298542
Pulled By: cpojer
fbshipit-source-id: 88b4715b75f190003c4813e5324a5094a7779f67
Summary:
- Using "System.getenv" allows to specify any entry file using environment variables and without modifying gradle file. Example:
export ENTRY_FILE="another_entry_file.js"
./gradlew assembleDebug
- This functionality is also more align with iOS implementation that uses 'if [[ "$ENTRY_FILE" ]]; then'. See https://github.com/facebook/react-native/pull/23667 for more details.
- Possibility to define entry file on CI without modifying sources (Example: project like [pixels-catcher](https://www.npmjs.com/package/pixels-catcher) requires different entry file)
## Changelog:
[Android] [Added] - Custom entry file on android using `ENTRY_FILE` environment variable
Pull Request resolved: https://github.com/facebook/react-native/pull/26769
Test Plan:
- Create a project from template
- Define `ENTRY_FILE` environment variable
```
export ENTRY_FILE="anotherIndexFile.js"
```
- Build android
```
./gradlew assembleDebug
```
Expected result: App contains bundle file that starts from `anotherIndexFile.js` file.
Differential Revision: D17903165
Pulled By: cpojer
fbshipit-source-id: 6b7cdf229918d101c170aa5fbdca6f3ef293d41c
Summary:
On the Windows platform, with hermes-engine enabled, the assembly crashes with an error:
![image](https://user-images.githubusercontent.com/8634793/65568495-ab11d980-df8c-11e9-83a0-2a2d26447860.png)
The problem lies in calling hermes command without the leading arguments `"cmd", "/c"` ([react.gradle, line: 152](e028ac7af2/react.gradle (L152)) )
## Changelog
[General] [Fixed] - Added a platform check and running commandLine with the corresponding arguments
Pull Request resolved: https://github.com/facebook/react-native/pull/26556
Test Plan:
Under Windows, enable hermes-engine in _build.gradle_ and run the `gradlew assembleRelease` or `gradlew bundleRelease` command
Also check assembly on other available platforms
Differential Revision: D17587023
Pulled By: cpojer
fbshipit-source-id: bab10213b23fac5ab6a46ac4929759dcd43e39c2
Summary:
Yesterday we shipped hermesengine.dev as part of the current 0.60 release. This PR brings those changes to master.
## Changelog
[General] [Added] - Added support for Hermes
Pull Request resolved: https://github.com/facebook/react-native/pull/25613
Test Plan:
* CI is green both on GitHub and at FB
* Creating a new app from source can use Hermes on Android
Reviewed By: cpojer
Differential Revision: D16221777
Pulled By: willholen
fbshipit-source-id: aa6be10537863039cb666292465ba2e1d44b64ef
Summary:
### Problem
According to https://github.com/facebook/react-native/issues/9145, the `--port` setting is not respected when executing `react-native run-android`. The templates that report things like what port the dev server runs on are hard coded as well.
### Solution
This commit replaces the hardcoded instances of port 8081 on Android with a build configuration property. This allows setting of the port React Native Android connects to for the local build server.
For this change to work, there must also be an update to the react native CLI to pass along this setting:
https://github.com/react-native-community/react-native-cli/compare/master...nhunzaker:9145-android-no-port-hardcode-cli
To avoid some noise on their end, I figured I wouldn't submit a PR until it's this approach is deemed workable.
## Changelog
[Android][fixed] - `react-native run-android --port <x>` correctly connects to dev server and related error messages display the correct port
Pull Request resolved: https://github.com/facebook/react-native/pull/23616
Differential Revision: D15645200
Pulled By: cpojer
fbshipit-source-id: 3bdfd458b8ac3ec78290736c9ed0db2e5776ed46
Summary:
If `$buildDir/generated/res/react/${flavorPathSegment}release/raw` contains files during `gradle assembleRelease` script will fail with `Error: Duplicate resources` error.
This patch is based on this issue [22234](https://github.com/facebook/react-native/issues/22234) and pull request [24518](https://github.com/facebook/react-native/pull/24518).
[Android] [Fixed] - Fix duplicate resource error for raw folder in Android build
[CC from Mike Hardy PR]
Reports of success on the linked issue via use of the patch + patch-package for a couple months, I personally use it full time with all gradle builds (./gradlew clean assembleRelease or if you have a 'staging' flavor, e.g. ./gradlew clean assembleStagingRelease)
Related reading, also cross-links with the linked issue here:
https://stackoverflow.com/questions/53239705/react-native-error-duplicate-resources-android
Pull Request resolved: https://github.com/facebook/react-native/pull/24778
Differential Revision: D15277766
Pulled By: cpojer
fbshipit-source-id: 0ccd76d2aa2e13f7c8bfac07d4ef23b74945807a
Summary:
Issue #22234 includes a number of people (myself included) suffering with duplicate resource errors while building in Android. We have been collectively using a patch there but I don't believe any attempt has been made to PR it upstream.
I am not excellent at gradle, so I may have approached this in completely the wrong way, but it works for me in the standard init templates, as well as my current work project which has a complicated 2 buildType + 4 productFlavor configuration. If there is a better way to achieve the result I am happy to learn
The approach here is to determine the generated path the resources land in, then move them into the main build output tree. If they remain in the generated path android merging fails with duplicate resource errors, so that move (vs copy) is important.
[Android] [Fixed] - Fix duplicate resource error in Android build
Pull Request resolved: https://github.com/facebook/react-native/pull/24518
Differential Revision: D15276981
Pulled By: cpojer
fbshipit-source-id: 3fe8c8556e4dcdac5f96a2d4658ac9b5d9b67379
Summary:
This PR bumps Android Gradle Plugin to 3.4.0, which enables R8 shrinker by default and improves build performance significantly.
Disabled R8 for ReactAndroid because it'll strip out AndroidX and other libraries bundled in ReactAndroid.
[Android] [Changed] - bump Android Gradle plugin to 3.4.0
Pull Request resolved: https://github.com/facebook/react-native/pull/24463
Differential Revision: D15107117
Pulled By: hramos
fbshipit-source-id: 35a03dc9955e889c9399faeaf9a862e0fc044fc4
Summary:
The current system would always end up falling back to `true` for release builds
Pull Request resolved: https://github.com/facebook/react-native/pull/18892
Differential Revision: D14069444
Pulled By: hramos
fbshipit-source-id: 16e32a366b3b2e252a98a967da827ba1ebaeff85
Summary:
Using Kotlin DSL in Gradle instead of Groovy will help detect problems early on using static typing, and it has advanced IDE support. This PR prepares Groovy script for Kotlin DSL migration per **Migrating build logic from Groovy to Kotlin** guide. Here is the excerpt:
>As a first migration step, it is recommended to prepare your Groovy build scripts by
> - unifying quotes using double quotes,
> - disambiguating function invocations and property assignments (using respectively parentheses and assignment operator).
See: https://guides.gradle.org/migrating-build-logic-from-groovy-to-kotlin/
[Android] [Changed] - Prepare Gradle scripts for Kotlin DSL migration
Pull Request resolved: https://github.com/facebook/react-native/pull/23355
Differential Revision: D14018504
Pulled By: mdvacca
fbshipit-source-id: 909982c715b640f102cbe723df578c9af7bae08e
Summary:
Add suport to gradle 4.10.1 or high!
The new version of android studio 3.3 recommendete to update gradle project to 4.10.1
> To take advantage of the latest features, improvements, and security fixes, we strongly recommend that you update the Android Gradle plugin to version 3.3.0 and Gradle to version 4.10.1. [Release notes ](https://developer.android.com/studio/releases/gradle-plugin)
>Android plugin 3.2.0 and higher now support building the Android App Bundle—a new upload format that defers APK generation and signing to compatible app stores, such as Google Play. With app bundles, you no longer have to build, sign, and manage multiple APKs, and users get smaller, more optimized downloads. [Learn more](https://developer.android.com/guide/app-bundle/?utm_source=android-studio)
but if the upgrade to the new Android gradle many warnings come up, becouse meny things was obsoleted
> WARNING: API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'.
> WARNING: API 'variant.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'.
> WARNING: API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'.
> It will be removed at the end of 2019.
> For more information, [see ](https://d.android.com/r/tools/task-configuration-avoidance.)
> To determine what is calling variant.getMergeAssets(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Changelog:
----------
[Android] [Deprecated] - fix warinings obsolete to update to gradle 4.10.1 or high
Pull Request resolved: https://github.com/facebook/react-native/pull/23103
Differential Revision: D13817123
Pulled By: cpojer
fbshipit-source-id: 9816e20145a5fded2702cf9317cfb6862f3ebd8b
Summary:
Android App Bundle builds use the packageBundle and bundle tasks instead
of the package and assemble tasks the APK builds use. Because of this,
the resources and js bundles weren't getting copied into the final
artifact. In an App Bundle build, the merged assets must be present
during the buildPreBundle step in order to arrive in the App Bundle.
Pull Request resolved: https://github.com/facebook/react-native/pull/21738
Differential Revision: D13669288
Pulled By: cpojer
fbshipit-source-id: 0e985983f04504b69e447dbc1f3f34cf8f4eb927
Summary: This removes the remaining references to `local-cli`. We already have a `cli.js` file on the root that was just forwarding to the local-cli folder, so I removed that. It also seems that `setupBabel.js` is no longer necessary in RN.
Reviewed By: TheSavior
Differential Revision: D13396218
fbshipit-source-id: a945cb91dae39c4b58c5cabcca6b0f0328fc4717
Summary:
This PR allows Android projects that use `apply plugin: "com.android.library"` to build successfully. A recent regression caused by https://github.com/facebook/react-native/pull/20526 means that building one of these projects always fails with this error:
```
FAILURE: Build failed with an exception.
* Where:
Script '/Users/james/src/SampleLibrary/node_modules/react-native/react.gradle' line: 15
* What went wrong:
A problem occurred configuring project ':app'.
> Could not get unknown property 'applicationVariants' for object of type com.android.build.gradle.LibraryExtension.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
```
This change updates `react.gradle` to cater to both application and library projects by selectively using `android.applicationVariants` or `android.libraryVariants`.
Fixes https://github.com/facebook/react-native/issues/22310.
Pull Request resolved: https://github.com/facebook/react-native/pull/22312
Differential Revision: D13373742
Pulled By: cpojer
fbshipit-source-id: 64c35ab7a6d5d0d840a43729123e70dd8e0d36e0
Summary:
When we use product flavor (e.g. develop/production) with Android Gradle Plugin 3.2,
javascript bundle is not copied due to that merged asset path point to incorrect location.
related #21408
<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.
Help us understand your motivation by explaining why you decided to make this change.
If this PR fixes an issue, type "Fixes #issueNumber" to automatically close the issue when the PR is merged.
_Pull requests that expand test coverage are more likely to get reviewed. Add a test case whenever possible!_
-->
Pull Request resolved: https://github.com/facebook/react-native/pull/21782
Differential Revision: D12854056
Pulled By: hramos
fbshipit-source-id: d1e6a395e762cc4a4f133977d54d0f469fa66b8c
Summary:
Android Gradle Plugin 3.2 uses a new intermediates/merged_assets directory instead of intermediates/assets. This workaround copies the javascript bundle to both directories for compatibility purposes.
Fixes#21132Fixes#18357
Pull Request resolved: https://github.com/facebook/react-native/pull/21409
Differential Revision: D10141860
Pulled By: hramos
fbshipit-source-id: 0fb20fcec67ec2bfd7a8d9052599bbc70464b466
Summary: This change drops the year from the copyright headers and the LICENSE file.
Reviewed By: yungsters
Differential Revision: D9727774
fbshipit-source-id: df4fc1e4390733fe774b1a160dd41b4a3d83302a
Summary:
One of our automated project tools noted that these were all missing their copyright headers.
Pull Request resolved: https://github.com/facebook/react-native/pull/21000
Differential Revision: D9721495
Pulled By: hramos
fbshipit-source-id: 6ccf0f37165a0fe16cf06bd996d615f2286101dc
Summary:
Mirrors #17967 which was imported and reverted
Original:
Better integration with the Android Gradle-based build process, especially the changes introduced by the [Android Gradle Plugin 3.x and AAPT2](https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html).
Fixes#16906, the `android.enableAapt2=false` workaround is no longer required.
Bases the task generation process on the actual application variants present in the project. The current manual process of iterating build types and product flavors could break down when more than one dimension type is present (see https://developer.android.com/studio/build/build-variants.html#flavor-dimensions).
This also exposes a very basic set of properties in the build tasks, so that other tasks can more reliably access them:
```groovy
android.applicationVariants.all { variant ->
// This is the generated task itself:
def reactBundleTask = variant.bundleJsAndAssets
// These are the outputs by type:
def resFileCollection = reactBundleTask.generatedResFolders
def assetsFileCollection = reactBundleTask.generatedAssetsFolders
}
```
I've tested various combinations of product flavors and build types ([Build Variants](https://developer.android.com/studio/build/build-variants.html)) to make sure this is consistent. This is a port of what we're currently deploying to our CI process.
[ ANDROID ] [ BUGFIX ] [ react.gradle ] - Support Android Gradle Plugin 3.x and AAPT2
[ ANDROID ] [ FEATURE ] [ react.gradle ] - Expose the bundling task and its outputs via ext properties
Pull Request resolved: https://github.com/facebook/react-native/pull/20526
Differential Revision: D9164762
Pulled By: hramos
fbshipit-source-id: 544798a912df11c7d93070ddad5a535191cc3284
Summary:
_Quick apologies for the lengthiness of this description. Want to make sure I'm clear and it is understood what is being altered._
Thanks for submitting a PR! Please read these instructions carefully:
- [x] Explain the **motivation** for making this change.
- [x] Provide a **test plan** demonstrating that the code is solid.
- [x] Match the **code formatting** of the rest of the codebase.
- [x] Target the `master` branch, NOT a "stable" branch.
https://github.com/facebook/react-native/issues/5787
```
Unknown source file : /home/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi-v4/images_google.png: error: Duplicate file.
Unknown source file : /home/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi/images_google.png: Original is here. The version qualifier may be implied.
```
At Hudl, we've been attempting to package our React Native code into Library Dependencies _(Cocoapods / Android Artifact Resource (aar))_. Recently in React Native 0.42.0, there was an upgrade to the Android Project's gradle plugin from 1.3.1 to 2.2.3. This update drastically effected the outcome of drawable resources in Android without anyone noticing.
**There are 4 outcomes to consider with this change:**
1. You are developing in an Android Application using Gradle 1.3.1 or lower
2. You are developing in an Android Application using Gradle 2.2.3 or higher
3. You are developing in an Android Library Module using Gradle 1.3.1 or lower
4. You are developing in an Android Library Module using Gradle 2.2.3 or higher
With the upgrade to 2.2.3, Android changed the way aapt builds its resources. Any Library created with 2.2.3, has its resources ending with a `v4` suffix. The reasoning behind this I'm not sure of but assume it deals with Vector support that was added around that time.
The change I've added checks if React Native is being ran in an Android Library vs an Application, and appends the v4 suffix to the merged asset folders.
Multiple test were performed.
1. I first started out validating my assumption about the asset merger by creating a new Android Project to verify my assumptions above.
1. [Application + >= 2.2.3](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/master/app/build/intermediates/res/merged/debug) -- `hdpi` contains my drawable. `hdpi-v4` contains dependency's drawables.
2. [Application + <= 1.3.1](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/Android-LegacyVersion/app/build/intermediates/res/merged/debug) -- Same as above (I expect because deps are compiled against gradle 2.2.3+ themselves.
3. [Library + >= 2.2.3](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/Android-UsingAndroidLibrary/library/build/intermediates/res/merged/debug) -- Only `-v4` folders found! Resources from the library are packages in the app's build output in similar `-v4` folder too.
4. [Library + <= 1.3.1](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/Android-UsingAndroidLibraryLegacyVersion/library/build/intermediates/res/merged/debug) -- Same as ii. & iii. `-v4` contains other resources, but my resources are located in non -v4 folder.
2. I then wanted to validate against React Native itself. So I updated my react native code using this PR/Branch, and tested against my project locally. Unfortunately I cannot share that code as it is private, but before this change I was getting the same error as mentioned in #5787 and now my build runs as intended with the assets being placed where they should be.
Additional resources:
* https://github.com/facebook/react-native/issues/5787
* http://stackoverflow.com/questions/35700272/android-build-tool-adds-v4-qualifier-to-drawable-folders-by-default-in-generated
* https://github.com/facebook/react-native/issues/12710
Please let me know if more information is needed, further test plans, etc. With this change we should be able to upgrade to Gradle 2.3.0 as well to support the latest version of Android Studio.
Closes https://github.com/facebook/react-native/pull/13128
Differential Revision: D7828618
Pulled By: hramos
fbshipit-source-id: a7ad7b63b1b51cbfd2ea7656e4d77321306ce33a
Summary:
The js bundle task does not run when `org.gradle.configureondemand` is set to true. This uses `afterEvaluate` instead of `gradle.projectsEvaluated` which is executed properly.
Add `org.gradle.configureondemand=true`, run RNTester in release mode and make sure the bundle task is run.
[ANDROID] [BUGFIX] [LOCATION] - Fix release bundle task when org.gradle.configureondemand=true
Closes https://github.com/facebook/react-native/pull/18557
Differential Revision: D7396744
Pulled By: mdvacca
fbshipit-source-id: 9ea134cb49e8a087cec16f82b990cd19af76785a
Summary:
This reverts commit d16ff3bd8b.
Currently breaks with the gradle version used by RN, I think there has been some work to update that to a more recent one but for now I think we should just revert it.
It errors with:
```
Could not find method registerGeneratedResFolders() for arguments [file collection] on object of type com.android.build.gradle.internal.api.ApplicationVariantImpl.
```
Tested that RN tester now builds when using the right react.gradle (#18188)
[ ANDROID ] [ BUGFIX ] [ react.gradle ] - REVERT "Support Android Gradle Plugin 3.x and AAPT2"
[ ANDROID ] [ FEATURE ] [ react.gradle ] - REVERT "Expose the bundling task and its outputs via ext properties"
Closes https://github.com/facebook/react-native/pull/18189
Differential Revision: D7155176
Pulled By: hramos
fbshipit-source-id: 87b7b80b39cd345eebac4631efe6697971a1dbdf
Summary:
Better integration with the Android Gradle-based build process, especially the changes introduced by the [Android Gradle Plugin 3.x and AAPT2](https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html).
Fixes#16906, the `android.enableAapt2=false` workaround is no longer required.
Bases the task generation process on the actual application variants present in the project. The current manual process of iterating build types and product flavors could break down when more than one dimension type is present (see https://developer.android.com/studio/build/build-variants.html#flavor-dimensions).
This also exposes a very basic set of properties in the build tasks, so that other tasks can more reliably access them:
```groovy
android.applicationVariants.all { variant ->
// This is the generated task itself:
def reactBundleTask = variant.bundleJsAndAssets
// These are the outputs by type:
def resFileCollection = reactBundleTask.generatedResFolders
def assetsFileCollection = reactBundleTask.generatedAssetsFolders
}
```
I've tested various combinations of product flavors and build types ([Build Variants](https://developer.android.com/studio/build/build-variants.html)) to make sure this is consistent. This is a port of what we're currently deploying to our CI process.
[ ANDROID ] [ BUGFIX ] [ react.gradle ] - Support Android Gradle Plugin 3.x and AAPT2
[ ANDROID ] [ FEATURE ] [ react.gradle ] - Expose the bundling task and its outputs via ext properties
Closes https://github.com/facebook/react-native/pull/17967
Differential Revision: D7017148
Pulled By: hramos
fbshipit-source-id: e52b3365e5807430b9caced51349abf72332a587
Summary:
unbundle is a useful feature, and it should be exposed. In order to get the most use out of
we expose it as an option at build time in the Build Phase on XCode and the project.ext.react
config in the build.gradle.
Because it is best used with inline requires we add a section under performance that describes
how inline requires can be implemented and how to use with the unbundling feature.
Testing:
- Added a section of the doc which explains how the feature can be enabled
- Use the instructions, build a build on iOS + android (using release so that the bundle is created) and confirm that the bundle has the binary header information.
Closes https://github.com/facebook/react-native/pull/15317
Differential Revision: D6054642
Pulled By: hramos
fbshipit-source-id: 067f4d2f78d91215709bd3e3636f460bc2b17e99
Summary:
This PR adds support for configurable devEnabled option when building an android app. This is currently hardcoded.
The reason for making this configurable is this: I have an app that uses code-push and 3 buildConfigs. I want to have a debugging version which has `devEnabled = true`, then a staging version which has `devEnabled = false` (this version of the app is used internally for testing and should behave just like a release version of the app, and when the tests succeed the changes are promoted into the release version to the users out there, using code-push). The last version is a standard release version with `devEnabled = false`.
Currently, `devEnabled` is hardwired like this: `!targetName.toLowerCase().contains("release")` so by default my `staging` buildConfig will have `devEnabled = true` but I'd like it to be false.
With this PR it'd be possible to configure this as follows, while not breaking the current behavior.
`'devDisabledIn${productFlavor}${buildType}'`
`'devDisabledIn${buildType
Closes https://github.com/facebook/react-native/pull/11438
Differential Revision: D4630513
Pulled By: hramos
fbshipit-source-id: b6817cf4c144fc948f76785e9cb5f93a13a6a6a2