feat: introduce com.facebook.react.library as separate library plugin - #57912
feat: introduce com.facebook.react.library as separate library plugin#57912hurali97 wants to merge 4 commits into
Conversation
Co-authored-by: Lukmccall <kosmatylukasz@gmail.com>
|
In this PR, we only use RN library plugin in Also, there are internal Tasks currently a part of RNGP, which are used by
I believe all the internal libraries should use the library plugin and not worry about showcasing backward compat by using RNGP. Also, we may move with the first option, since it seems rather simpler but offers less abstraction as it will contain internal tasks as part of a public package. |
|
If we wish to extract the RN library plugin to a separate repo, then we have a few options. The RN Library plugin depends on Usage will look something like below in awesome-rn-library/android/build.gradle: diff --git a/android/build.gradle b/android/build.gradle
index fee43d64..3b3f5ade 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -23,7 +23,7 @@ buildscript {
classpath('com.android.tools.build:gradle:8.2.1')
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', rnsDefaultKotlinVersion)}"
classpath "com.diffplug.spotless:spotless-plugin-gradle:6.25.0"
+ classpath("com.facebook.react:react-native-library-plugin:0.0.1") // or RN version if we want to tie it to a specific RN version
}
}Approaches:
The first approach would require us to publish the required plugins to maven and then they will be auto resolved by gradle during dependency resolution. However, there is higher chance of The second approach is where we leverage the current shape of resolving Now, we extract the RN Library plugin to a separate repo but it still depends on There is also a third path, where we dont extract the RN library plugin to separate repo but still publish it to maven central. However, since now it's a part of includeBuild("../node_modules/@react-native/gradle-plugin") {
dependencySubstitution {
substitute module(
"com.facebook.react:react-native-gradle-plugin"
) using project(":react-native-gradle-plugin")
substitute module(
"com.facebook.react:react-native-gradle-plugin-shared"
) using project(":react-native-gradle-plugin-shared")
substitute module(
"com.facebook.react:shared"
) using project(":shared")
}
}However, this may create some complications and extra steps for the end users. Depending upon how and where we decide to constraint it, in |
cortinico
left a comment
There was a problem hiding this comment.
The biggest problem I see here is that you'll be versioning this library plugin with the same version of react-native.
That is a problem as a library will now have to depend on a given version of @react-native/gradle-plugin right?
Instead I believe this plugin should live in a separate repo and be released on-demand whenever needed. If we do so, we also need to make sure the Kotlin classes are not clashing with the same Kotlin classes inside RNGP (i.e. we can't really share code between the two).
Summary:
This PR extracts the library facing changes from RNGP to a separate RN Library plugin. We now have
com.facebook.react- meant to be applied by the applications andcom.facebook.react.librarymeant to be applied by the libraries.The foundation works in a compatible way. Which means that the existing libraries which applies the RNGP, will now get a deprecation notice to switch to the RN library plugin while still allowing existing libraries to work for the defined future releases.
Maintaining this compatibility requires us to introduce a new shared (
react-native-gradle-plugin-shared) plugin which is only shared between RNGP and RN Library plugin. We can't put this shared code as it requires AGP dependency, in the existing shared plugin as it is also consumed by the settings plugin. So we have to take this tradeoff for having an extra plugin until we fully deprecate using RNGP in libraries.The consumption of the RN library plugin is as simple as the following change in
awesome-rn-library/android/build.gradle:Since each third party library project is linked as a sub project to the application and in there at
awesome-app/android/settings.gradlewe defineincludeBuild(...gradle-plugin)- the RN library plugin gets resolved as well as part of the dependency resolution.Changelog:
[ANDROID] [ADDED] - Introduce com.facebook.react.library as a separate and preferred library plugin
Test Plan:
react-native-screens,react-native-worklets,react-native-reaniamtedandreact-native-safe-area-contextCase 1, we see deprecation notice when all these 4 libraries use RNGP with backward compat
Case 2, we see deprecation notice when 3 libraries use RNGP while RN screen uses new library plugin
Case 1, builtin kotlin not enabled, on AGP v8
Case 2, builtin kotlin enabled, on AGP v9
TBA