react-native-share: Android release build doesn't work with react-native@0.60 (AndroidX support is needed)
Steps to reproduce
- Init new fresh project with latest react-native@0.60.3
- Install latest react-native-share (with autolinking)
- Run RELEASE Android build assembling
Expected behaviour
Release Android build is assembled.
Actual behaviour
Release Android build is failed.
Error
error: package android.support.v4.content does not exist
[05:45:01]: ▸ import android.support.v4.content.FileProvider;
[05:45:01]: ▸ ^
[05:45:01]: ▸ /Users/distiller/mobile-web-app/node_modules/react-native-share/android/src/main/java/cl/json/RNShareFileProvider.java:5: error: cannot find symbol
[05:45:01]: ▸ public class RNShareFileProvider extends FileProvider {
[05:45:01]: ▸ ^
[05:45:01]: ▸ symbol: class FileProvider
[05:45:01]: ▸ /Users/distiller/mobile-web-app/node_modules/react-native-share/android/src/main/java/cl/json/RNShareModule.java:7: error: package android.support.annotation does not exist
[05:45:01]: ▸ import android.support.annotation.Nullable;
[05:45:01]: ▸ ^
[05:45:01]: ▸ /Users/distiller/mobile-web-app/node_modules/react-native-share/android/src/main/java/cl/json/RNSharePathUtil.java:12: error: package android.support.annotation does not exist
[05:45:01]: ▸ import android.support.annotation.NonNull;
[05:45:01]: ▸ ^
[05:45:01]: ▸ /Users/distiller/mobile-web-app/node_modules/react-native-share/android/src/main/java/cl/json/RNSharePathUtil.java:13: error: package android.support.v4.content does not exist
[05:45:01]: ▸ import android.support.v4.content.CursorLoader;
[05:45:01]: ▸ ^
[05:45:01]: ▸ /Users/distiller/mobile-web-app/node_modules/react-native-share/android/src/main/java/cl/json/RNSharePathUtil.java:14: error: package android.support.v4.content does not exist
[05:45:01]: ▸ import android.support.v4.content.FileProvider;
[05:45:01]: ▸ ^
[05:45:01]: ▸ /Users/distiller/mobile-web-app/node_modules/react-native-share/android/src/main/java/cl/json/RNShareModule.java:126: error: cannot find symbol
[05:45:01]: ▸ public void open(ReadableMap options, @Nullable Callback failureCallback, @Nullable Callback successCallback) {
[05:45:01]: ▸ ^
[05:45:01]: ▸ symbol: class Nullable
[05:45:01]: ▸ location: class RNShareModule
[05:45:01]: ▸ /Users/distiller/mobile-web-app/node_modules/react-native-share/android/src/main/java/cl/json/RNShareModule.java:126: error: cannot find symbol
[05:45:01]: ▸ public void open(ReadableMap options, @Nullable Callback failureCallback, @Nullable Callback successCallback) {
[05:45:01]: ▸ ^
[05:45:01]: ▸ symbol: class Nullable
[05:45:01]: ▸ location: class RNShareModule
[05:45:01]: ▸ /Users/distiller/mobile-web-app/node_modules/react-native-share/android/src/main/java/cl/json/RNShareModule.java:143: error: cannot find symbol
[05:45:01]: ▸ public void shareSingle(ReadableMap options, @Nullable Callback failureCallback, @Nullable Callback successCallback) {
[05:45:01]: ▸ ^
[05:45:01]: ▸ symbol: class Nullable
[05:45:01]: ▸ location: class RNShareModule
[05:45:01]: ▸ /Users/distiller/mobile-web-app/node_modules/react-native-share/android/src/main/java/cl/json/RNShareModule.java:143: error: cannot find symbol
[05:45:01]: ▸ public void shareSingle(ReadableMap options, @Nullable Callback failureCallback, @Nullable Callback successCallback) {
[05:45:01]: ▸ ^
[05:45:01]: ▸ symbol: class Nullable
[05:45:01]: ▸ location: class RNShareModule
[05:45:01]: ▸ /Users/distiller/mobile-web-app/node_modules/react-native-share/android/src/main/java/cl/json/RNShareModule.java:169: error: cannot find symbol
[05:45:01]: ▸ public void isPackageInstalled(String packagename, @Nullable Callback failureCallback, @Nullable Callback successCallback) {
[05:45:01]: ▸ ^
[05:45:01]: ▸ symbol: class Nullable
[05:45:01]: ▸ location: class RNShareModule
[05:45:01]: ▸ /Users/distiller/mobile-web-app/node_modules/react-native-share/android/src/main/java/cl/json/RNShareModule.java:169: error: cannot find symbol
[05:45:01]: ▸ public void isPackageInstalled(String packagename, @Nullable Callback failureCallback, @Nullable Callback successCallback) {
[05:45:01]: ▸ ^
[05:45:01]: ▸ symbol: class Nullable
[05:45:01]: ▸ location: class RNShareModule
[05:45:01]: ▸ /Users/distiller/mobile-web-app/node_modules/react-native-share/android/src/main/java/cl/json/RNShareModule.java:180: error: cannot find symbol
[05:45:01]: ▸ public void isBase64File(String url, @Nullable Callback failureCallback, @Nullable Callback successCallback) {
Environment
- React Native version: 0.60.3
- React Native platform + platform version: iOS 12.2, Android 9.0 (any 6.0+)
react-native-share
Version: 1.2.1
Notes
Main breaking change in react-native@0.60 is AndroidX libraries support. Upgrade of libraries is needed for react-native-share to avoid errors. As example we can see same changes were merged in https://github.com/react-native-community/react-native-camera/pull/2306
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 25 (2 by maintainers)
Just tested on a fresh project using:
And it works for both dev/release mode. However, i needed to manually link react-native-share.
@mikehardy @jordangrant I described my issue previously, I have react native project with all files migrated to support react-native@0.60 breaking changes. That means I have enabled jetifier by default in gradle settings. So, I noticed that debug build is working correctly, so jetifier can find and replace all libraries before build automatically. But when I deploy Android app on CircleCI and assemble Release build I see the error from first message in this Issue:
package android.support.v4.content does not exist. That means jetifier didn’t update libraries automatically for production build. You can reproduce that easily: Just create new freshreact-native@0.60+project and addreact-native-share@1.2.1and try to build debug and release Android apps. You will be able to see success debug build and failed release build. That’s why I created this PR and migrated to androidx libraries manually. Newreact-native-share@2.0.0will contain androidx support breaking change. If you need to use previous android libs withreact-native@<=0.59.10just please usereact-native-share@1.2.1which is reflected in updated README file. I’m not sure what we are looking here now in this discussion? Do we want to leave repo as is and just understand why Jetifier doesn’t work in Android release build? Maybe Jetifier doesn’t automatically update libs during build process for release app, maybe we need to manually migrate all libs withnpx jetifierin postinstall script. But why do we need postinstall scripts if react-native contains one special settins to enable jetifier and automatically replace libs during building an app? I mean theoptions in
android/gradle.propertiesin my project. I think it should work for both debug/release builds? Or no?@oleksandr-dziuban I am the jetifier author, I spent a month discussing it with RN-community in the related issue and testing solutions - I know this 😃. What I’m getting at is that your temporary is a different length of time than others temporary. jetifier is supposed to work regardless. And libraries are supposed to migrate regardless
I am absolutely 👍 on the AndroidX pull request (and am on record with the same, on this pull request I think?) - I think it is great and thank you for doing it.
But jetifier should still work. If you can figure out exactly why it is not working, so we can fix it, that would be great.
@guillaume-tgl Hello, I have problem only in release build mode. Debug build works fine. I have a lot of another react-native-… dependencies, project fully migrated to react-native@0.60.3. “jetifier” is enabled in Android gradle.properties by default now. Do I need to do some custom steps to use react-native-share with jetifier?
I just updated the example to RN60 and it seems to work #567 - but yes, in order to use the java object ‘ShareApplication’ in your MainApplication you have to manually link it for Android, auto-linking doesn’t work with that style.
However, with the implementation of an internal FileProvider via #490 it is not necessary to import or implement anything in MainApplication and auto-linking should work. I demonstrate this in #570
Ok, thanks
@oleksandr-dziuban we definitely want to update the library for AndroidX, no question there
However, the issue here is still conflating java-jetifier and javascript-jetifier. The status of your android/gradle.properties file is related yes, but separate. It is for java-jetifier
I’m not sure how any support class references could remain in node_modules after javascript-jetifier has run, so this actually appears to be a failure in setup somehow
Anyway, it’s odd. I’ll add react-native-share to the rn-androidx-demo CI suite for jetifier and investigate, but my general take is still that react-native-share 1.2.x should work just fine with react-native 0.60. I’ll prove that assertion though
@mikehardy I have checked previously, jetifier handle AndroidX Support fine only for Debug build. In my production project I saw error in release build, so we need to migrate to androidx packages anyway. For react-native0.59 people just can use react-native-share@1.2.1, it is working fine. But to support react-native0.60 they need to use react-native-share@2.0.0. I reflected that in README in my PR.
@guillaume-tgl @arivanandan @jgcmarins @heracek Hello guys, I have fixed AndroidX issues in release build and added react-native@0.60.+ support. Please check PR: https://github.com/react-native-community/react-native-share/pull/550
I have checked production release builds on CI with my fork, everything is assembling correctly. Thanks