Summary:
This PR adds the basic `ktfmt` setup in OSS to lint Kotlin files before they're imported into the Meta codebase, making collaboration with external contributors smoother for Android related PRs.
I tried to put together certain rules that mimic the current code style and it seems to work well as I get no errors for properly formatted files but this still might need some input to have the correct configuration.
Added two scripts to the main package.json:
- To check the files format you can run: `yarn lint-kotlin-check`
- To apply formatting fixes, run: `yarn lint-kotlin`
## Changelog:
[INTERNAL] - Kotlin: Set up ktfmt in OSS
Pull Request resolved: https://github.com/facebook/react-native/pull/52064
Test Plan:
Unformat any random Kotlin file inside ReactAndroid and then run:
```sh
yarn lint-kotlin-check
yarn lint-kotlin
```
Reviewed By: cipolleschi
Differential Revision: D78272876
Pulled By: cortinico
fbshipit-source-id: 0cf6b976968dfc5c6c478e88d17eb21c18961a34
Summary:
Resolved a build error [issue https://github.com/facebook/react-native/issues/51297](https://github.com/facebook/react-native/issues/51297) caused by assigning a Boolean to a Property<Boolean>.
Switched from direct assignment to using .set(...) to correctly configure allWarningsAsErrors from project properties.
## Changelog:
- Gradle fix: assign allWarningsAsErrors using .set() for Property<Boolean>
<!-- Help reviewers and the release process by writing your own changelog entry.
Pick one each for the category and type tags:
[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - [ANDROID] [FIXED]
For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
Pull Request resolved: https://github.com/facebook/react-native/pull/51300
Test Plan:
Fixes build failure with React Native v0.79.2 and Gradle v8.0.
```
npm run start
npm run android
```
no more build errors
Reviewed By: cortinico
Differential Revision: D74706741
Pulled By: rshest
fbshipit-source-id: 31ec923f49a6da63fb5abb464bc38b99b1e8650a
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/50780
This bumps Kotlin to the latest stable: 2.1.20.
I've also fixed several warnings emitted by the new compiler.
Changelog:
[Android] [Changed] - Kotlin to 2.1.20
Reviewed By: rshest
Differential Revision: D73122000
fbshipit-source-id: 019a01d085b2c115a3efcf567056e9990a1ff0ce
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/49484
This is the last diff to add support for Gradle Configuration caching.
The last missing part here was the execution of the `config` command during Gradle configuration time.
Using Java processes API is not supported as the correct way to do external commands that are CC-friendly
is through the `.providers.exec` API which I'm using here.
Closes https://github.com/facebook/react-native/issues/45154
Changelog:
[Android] [Added] - Add support for Gradle Configuration caching
Reviewed By: cipolleschi
Differential Revision: D69753889
fbshipit-source-id: af1e844b38444659a908abce4029d43ad899c03d
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46955
This is a major bump of Kotlin. It comes with no breaking changes for the Kotlin API, but there are several new warnigns that I had to fix.
Most importantly several `override` methods that are overriding Deprecated API, also need to be deprecated as well in Kotlin.
Changelog:
[Android] [Changed] - Bump Kotlin 1.9.x to 2.0.x
Reviewed By: tdn120
Differential Revision: D64179842
fbshipit-source-id: 295ab2636ce9f9bb04e9d8c7ed27d9f8a1a64338
Summary:
I've noticed that some users are reporting build failures due to warnings inside RNGP.
We do have `allWarningsAsErrors` set to true for everyone (also for users).
That's too aggressive, and can cause build failures which are not necessary. Let's keep it enabled only on our CI (when the `enableWarningsAsErrors` property is set).
## Changelog:
[INTERNAL] - RNGP: Read `enableWarningsAsErrors` property correctly
Pull Request resolved: https://github.com/facebook/react-native/pull/46657
Test Plan: CI
Reviewed By: NickGerleman
Differential Revision: D63459601
Pulled By: cortinico
fbshipit-source-id: 0307e8d6771518038a5abe27ca5a993cb0a9f8c0
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46241
Our test for rebuilding the `autolinking.json` file currently rebuilds everytime if the cached json file ISN'T empty. This means users who have an empty entry get stuck there.
I've also added more validation that the contents of the cached config have at a minimum the `.project.android.packageName` entry in it, otherwise it rebuilds.
Changelog: [Internal]
Closes 46134
Reviewed By: cortinico
Differential Revision: D61911114
fbshipit-source-id: 188c7f975ce05802c8ea06eaa48345c2bc96f2b2
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45575
We should move over to use AssertJ as per our linter.
I'm adding it here to a first test and will use it as a reference for some OSS contributions from outside.
Changelog:
[Internal] [Changed] - Migrate settings-plugin to Assertj
Reviewed By: cipolleschi
Differential Revision: D60037797
fbshipit-source-id: 579ed7bf5fb219e25577af3ab87934503ee7898e
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45572
0.75-rc.5 is currently broken on Windows.
This is due to us invoking `npx react-native-community/cli config` without
a `cmd /c` prefix.
This fixes it by using our function `windowsAwareCommandLine`.
The problem is that this required a lot of refactoring since that util was not available for the settings plugin.
Fixes#45403
Changelog:
[Internal] [Changed] - Fix core autolinking not working on Windows
Reviewed By: cipolleschi
Differential Revision: D60037587
fbshipit-source-id: eefeda7aafc43b9ce08f0f9225b0847fad2f46b7
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45511
This adds react-native.config.js to autolinking default lockfiles
so autolinking can account for changes in that file.
Changelog:
[Internal] [Changed] - Add react-native.config.js to autolinking lockfiles
Reviewed By: blakef
Differential Revision: D59907268
fbshipit-source-id: d5893a3f7b4d5d9f6c6c13042aa6866ad16b2ea4
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45407
This bumps to the latest minor of Gradle
Changelog:
[Android] [Changed] - Gradle to 8.9
Reviewed By: NickGerleman
Differential Revision: D59677575
fbshipit-source-id: 05b9afc6f32a9cd11461bc04522d1e522644867e
Summary:
Fixes: https://github.com/facebook/react-native/issues/45307
## Changelog:
[Android] [Fixed] - if `npx react-native-community/cli config` fails or timeouts proper error is shown and built is aborted, instead of leaving and empty autolinking.json
During build `npx react-native-community/cli config` is generated into autolinking.json. When command fails, we should error and should not leave and empty `autolinking.json`
Pull Request resolved: https://github.com/facebook/react-native/pull/45333
Test Plan:
Output of the reproducer in https://github.com/facebook/react-native/issues/45307 looks like this:
```log
android % ./gradlew assembleDebug
Starting a Gradle Daemon (subsequent builds will be faster)
ERROR: autolinkLibrariesFromCommand: Failed to create /Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/build/generated/autolinking/autolinking.json - process npx react-native-community/cli config exited with error code: 126
FAILURE: Build failed with an exception.
* Where:
Settings file '/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/settings.gradle' line: 3
* What went wrong:
A problem occurred evaluating settings 'android'.
> ERROR: autolinkLibrariesFromCommand: Failed to create /Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/build/generated/autolinking/autolinking.json - process npx react-native-community/cli config exited with error code: 126
* 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 10s
8 actionable tasks: 4 executed, 4 up-to-date
```
Output if you modify the package.json to be invalid looks like this:
```log
android % ./gradlew assembleDebug
ERROR: autolinkLibrariesFromCommand: process npx react-native-community/cli config exited with error code: 1
JSONError: JSON Error in /Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/package.json:
35 | "node": ">=18"
36 | },
> 37 | SOMETHING_NON_JSON
| ^
38 | "packageManager": "yarn@3.6.4",
39 | "resolutions": {
40 | "rtn-centered-text": "portal:../RTNCenteredText"
Unexpected token "S" (0x53) in JSON at position 1019 while parsing near "...ode\": \">=18\"\n },\n SOMETHING_NON_JSON\n ..."
35 | "node": ">=18"
36 | },
> 37 | SOMETHING_NON_JSON
| ^
38 | "packageManager": "yarn@3.6.4",
39 | "resolutions": {
40 | "rtn-centered-text": "portal:../RTNCenteredText"
at parseJson (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/parse-json/index.js:29:21)
at loadJson (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/loaders.js:48:16)
at #loadConfiguration (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:116:36)
at #loadConfigFileWithImports (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:87:54)
at #readConfiguration (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:84:82)
at search (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:50:63)
at emplace (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/util.js:36:20)
at ExplorerSync.search (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:78:42)
at getUserDefinedOptionsFromMetaConfig (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/index.js:32:37)
at mergeOptionsBase (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/index.js:60:31)
FAILURE: Build failed with an exception.
* Where:
Settings file '/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/settings.gradle' line: 3
* What went wrong:
A problem occurred evaluating settings 'android'.
> ERROR: autolinkLibrariesFromCommand: process npx react-native-community/cli config exited with error code: 1
* 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 2s
8 actionable tasks: 4 executed, 4 up-to-date
```
Reviewed By: cipolleschi
Differential Revision: D59582430
Pulled By: cortinico
fbshipit-source-id: bedb9563175cc5c46f5af80cf309769e56b803cc
Summary:
Fixes https://github.com/facebook/react-native/issues/45222
## Changelog:
[ANDROID] [FIXED] - Fix autolink plugin for libraries that are platform-specific
Pull Request resolved: https://github.com/facebook/react-native/pull/45223
Test Plan: And a library that does not have Android native code such as react-native-segmented-control/segmented-control and sync gradle
Reviewed By: rshest
Differential Revision: D59221562
Pulled By: cortinico
fbshipit-source-id: 55739d63ded63e46897d0d770281f937668c1f50
Summary:
Use the hard-coded config for Helloworld instead of assuming the community cli is there to generate a config, which we can no longer assume.
Changelog: [Internal]
Pull Request resolved: https://github.com/facebook/react-native/pull/45221
Test Plan:
This works in my local environment:
```
bundle exec pod install
```
and
```
./gradlew generateAutolinkingPackageList
```
Changelog: [Internal]
Reviewed By: javache
Differential Revision: D59162715
Pulled By: blakef
fbshipit-source-id: 95ff2c3929f12ee0ecf468cb80d2df1281eb746e
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44832
I'm renaming this folder as now we have 2 gradle plugins + we currently have
`package/react-native-gradle-plugin/react-native-gradle-plugin/` which is confusing so we can just call this folder `packages/gradle-plugin/`
to be consistent with the NPM package name
Changelog:
[Internal] [Changed] - packages/react-native-gradle-plugin/ -> packages/gradle-plugin/
Reviewed By: blakef
Differential Revision: D58284883
fbshipit-source-id: 5a7bb40a5d80f6fbab4ffb29e44107453f1013ec