Skip to content
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] Upcoming changes for libraries in React Native 0.73 #671

Closed
cortinico opened this issue Jun 16, 2023 · 34 comments
Closed

[Android] Upcoming changes for libraries in React Native 0.73 #671

cortinico opened this issue Jun 16, 2023 · 34 comments

Comments

@cortinico
Copy link
Member

cortinico commented Jun 16, 2023

TL;DR

React Native 0.73 will depend on Android Gradle Plugin (AGP) 8.x. This will require all the libraries to specify a namespace in their build.gradle file. We added a compatibility layer for libraries that haven't specified a namespace, but please consider updating your libraries nonetheless.

Details

I'd like to share some of the upcoming changes that will happen in 0.73, which is still a bit far, but we'd rather start earlier rather than later.

React Native 0.73 will depend on Android Gradle Plugin (AGP) 8.x, which brings a lot of improvements for Android apps but also a series of notable changes.

Most importantly:

Specifically, the last change is a breaking change and will make libraries that are not specifying a namespace incompatible with React Native 0.73 (your project won't build).

Support for namespace was added in AGP 7.3.x, which ships with React Native 0.71. Libraries that published a new version with a namespace declared for 0.71 or 0.72 don't need further update. So we invite library authors to do those changes as soon as possible so by the time 0.73 is out, most of the apps are adapted.

What you need to change

Library authors will have to update their android/build.gradle file as follows:

android {
+   namespace = "com.example.mylibrary"
    ...
}

and remove the package definition from their AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-          package="com.example.mylibrary">
+          >
...
</manifest>

Compatibility Layer

We added a compatiblity layer inside React Native 0.73, that will make sure that namespace is configured for each libraries, even if you don't update the library. This will make sure 0.73 works also with older libraries that are not receiving may updates.
Still consider updating your library to keep up to date with the Android best practices.

Further reading

Official Google documentation on namespaces is here.


Please update your libraries whenever possible, adding the namespace declaration and let us know if this is creating any issues for you.

@a7medev
Copy link

a7medev commented Jun 19, 2023

@cortinico Does removing the package="com.example.mylibrary" part affect support for older versions of React Native?

@ngocle2497
Copy link

ngocle2497 commented Jun 19, 2023

@cortinico Does removing the package="com.example.mylibrary" part affect support for older versions of React Native?

I tried to patch react-native-bootsplash package. it's work (RN 0.71.8)

@a7medev
Copy link

a7medev commented Jun 19, 2023

@MasonLe2497 What about versions older than that? RN 0.71 is already the latest available release. What about versions before 0.69?

@RafikiTiki
Copy link

RafikiTiki commented Jun 19, 2023

@a7medev I verified this by using updated version of Repack in the Release & Debug builds of apps using RN71.x and RN67.x. So far no problems :)

EDIT: I take that back – I messed up while pointing to the new local build of Repack in RN67.x project. In RN67.x the build of the test app using Repack version with this change fails with the following bug (which, tbh, makes sense):

image

In the generated PackageList.java file instead of a valid import of Repack, undefined is placed as a package namespace:

- import com.callstack.repack.ScriptManagerPackage;
+ import undefined.ScriptManagerPackage;

This then leads to the next error: cannot find symbol ScriptManagerPackage

@ngocle2497
Copy link

@cortinico which min RN version can use this change?

@RafikiTiki
Copy link

RafikiTiki commented Jun 19, 2023

Hey everybody, I double-checked the compatibility of this change with older versions of React Native, and unfortunately, it's not compatible with RN67.x. Sorry for the confusion 😞 . I already updated my old comment with details of what exactly fails.

This looks like a breaking change, and libraries should release a new major version targeting RN71 and higher.

@thymikee
Copy link
Member

@RafikiTiki thanks for coming back with the feedback. This is likely due to the RN CLI not able to parse namespace for RN 0.67, as it was added for CLI v10 which targets RN 0.71: react-native-community/cli@5fbb536

If we want to stay compatible with RN version policy, we likely need to backport this to 0.70 at least. We could go further I guess, but I'd need @cortinico let me know if this even makes sense.

@a7medev
Copy link

a7medev commented Jun 19, 2023

@thymikee We develop an SDK for React Native and leaving all these versions behind can be a bit risky.
What is the best approach for supporting 0.73 while still being backward-compatible?

@cortinico
Copy link
Member Author

What about versions older than that? RN 0.71 is already the latest available release. What about versions before 0.69?

For completeness, by the time 0.73 will be out, 0.72 and 0.71 will also be out which supports the namespace directive. I've been discussing with other library maintainers to understand if we want to recommended a snippet that would allow to selectively call namespace only on RN >= 0.71.

And yes, removing package="com.example.mylibrary" from the Manifest also has impact on libraries which are running on RN < 71. If you wish to retain the highest compatibility it's better to don't remove the package directive from the Manifest and add the namespace directive.
Sadly users on 0.71+ will see a warning on console mentioning that package="com.example.mylibrary" can be removed from the library manifest's file which is not really actionable.

@androideveloper
Copy link

Nice! Thanks for starting this @cortinico .
What about the R class being non-transitive by default? Have already caught a couple of libraries with incorrect refs.

The good part is that it helps to reduce the app size, especially for big projects 🎉

Anush-Shand added a commit to CleverTap/clevertap-react-native that referenced this issue Apr 5, 2024
* task(SDK-3753) - Removes manifest entry for CTBackgroundJobService

- No longer required as it is fixed in v6.2.0

* task(SDK-3752) - Updates Example app

* task(SDK-3752) - Adds support for ctv6.2.0

- Updates versions
- Removes all xiaomi related code

* task(SDK-3752) - Fixes a typo in CHANGELOG.md

* task(SDK-3752) - Adds back package name for max compatibility with RN versions
react-native-community/discussions-and-proposals#671 (comment)

* task(SDK-3752) - Updates CHANGELOG.md
@gkasireddy202
Copy link

Hi,
I upgraded my project from 0.68.7 to 0.73.2. I am getting the below error on Android.
I do not want to upgrade my libraries in package.json
The project is using an incompatible version (AGP 8.1.1) of the Android Gradle plugin. Latest supported version is AGP 7.2.1.

kenjdavidson added a commit to kenjdavidson/react-native-bluetooth-classic that referenced this issue Jul 15, 2024
kenjdavidson added a commit to kenjdavidson/react-native-bluetooth-classic that referenced this issue Jul 15, 2024
kenjdavidson added a commit to kenjdavidson/react-native-bluetooth-classic that referenced this issue Jul 22, 2024
RonRadtke pushed a commit to RonRadtke/react-native-blob-util that referenced this issue Jul 22, 2024
This issue is due to: react-native-community/discussions-and-proposals#671
And will reintroduce a warning for old libraries
423blaze pushed a commit to 423blaze/wallet-mobile-sdk that referenced this issue Jul 27, 2024
With React Native 0.73 Android Gradle Plugin 8 is now supported
If 8 and up the java toolchain should take care of the compatibility of java versions between dependencies

Release: react-native-community/discussions-and-proposals#671

Fixes Error: 'compileDebugJavaWithJavac' task (current target is 17) and 'compileDebugKotlin' task (current target is 11) jvm target compatibility

Seen when building for Android

Co-authored-by: Alex Risch <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests