-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
AndroidX support #1588
Comments
@OleksandrKucherenko it is something that I'd like to switch over to eventually yes, I've quickly gone through the project and checked what we use it for overall, the majority of it was NonNull/Nullable annotations - I've just switched all these over to use The 2x All that remains then is the usage in Notifications & Messaging, if you'd like to send a PR for this that'd be super handy - it might not get a direct merge but it would definitely form the basis of swapping it out for v6.0.0. If you could come on our discord chat I'd be up for chatting about it and if there's anything else Android side that you think needs doing 👍 Loving
|
Hi. Would just like to note that I have just tried to upgrade to AndroidX as an attempt to solve some support library dependency issues in other packages. Unfortunately the only thing blocking me now is react-native-firebase - ( |
@sinewave440hz you can use old |
I see. Given that I've otherwise successfully built my app using AndroidX, could you suggest more specifically how I can get my app to build? I have 20 errors that are related to this that I'm not sure how to fix: error: package android.support.annotation does not exist |
Did the lib been upgraded to androidx? |
Is there a workaround for this? New versions of other libraries require us to upgrade to AndroidX and then we're stuck not able to build, because of this issue. :( Version 6 feels like it could take months. I thought this is going to be solved by jetifier... but I have it enabled and still firebase is giving me these errors. Edit: For anyone else, the workaround is this:
|
My best guess now is that react-native libraries will need to be delivered as AARS so jetifier can work forwards (for those libraries that have not converted, like react-native-firebase v5) and with an support-library compatibility AAR distributed for those apps that can't convert. You could try packaging the react-native-firebase v5 code into a JAR and adding it as a local dependency yourself if you like, jetifier would work then. |
Interesting workaround by the way - you could use patch-package (works really really well) to automate that patch if/until libraries adopt it, if it works well |
Yerp, for example this is how people can use v6 now without AndroidX if they need to, here's the patch I've been recommending: diff --git a/node_modules/@react-native-firebase/app/android/gradle.properties b/node_modules/@react-native-firebase/app/android/gradle.properties
index d015431..e69de29 100644
--- a/node_modules/@react-native-firebase/app/android/gradle.properties
+++ b/node_modules/@react-native-firebase/app/android/gradle.properties
@@ -1,2 +0,0 @@
-android.useAndroidX=true
-android.enableJetifier=true
\ No newline at end of file
diff --git a/node_modules/@react-native-firebase/app/android/src/main/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java b/node_modules/@react-native-firebase/app/android/src/main/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java
index 521a2e0..d63afae 100644
--- a/node_modules/@react-native-firebase/app/android/src/main/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java
+++ b/node_modules/@react-native-firebase/app/android/src/main/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java
@@ -17,7 +17,7 @@ package io.invertase.firebase.app;
*
*/
-import androidx.annotation.Keep;
+import android.support.annotation.Keep;
import com.google.firebase.components.Component;
import com.google.firebase.components.ComponentRegistrar;
diff --git a/node_modules/@react-native-firebase/app/android/src/main/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitter.java b/node_modules/@react-native-firebase/app/android/src/main/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitter.java
index 5b1726b..5970656 100644
--- a/node_modules/@react-native-firebase/app/android/src/main/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitter.java
+++ b/node_modules/@react-native-firebase/app/android/src/main/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitter.java
@@ -19,7 +19,7 @@ package io.invertase.firebase.common;
import android.os.Handler;
import android.os.Looper;
-import androidx.annotation.MainThread;
+import android.support.annotation.MainThread;
import android.util.Log;
import com.facebook.react.bridge.Arguments;
diff --git a/node_modules/@react-native-firebase/app/android/src/main/java/io/invertase/firebase/common/ReactNativeFirebaseInitProvider.java b/node_modules/@react-native-firebase/app/android/src/main/java/io/invertase/firebase/common/ReactNativeFirebaseInitProvider.java
index 42fec16..fcf0c42 100644
--- a/node_modules/@react-native-firebase/app/android/src/main/java/io/invertase/firebase/common/ReactNativeFirebaseInitProvider.java
+++ b/node_modules/@react-native-firebase/app/android/src/main/java/io/invertase/firebase/common/ReactNativeFirebaseInitProvider.java
@@ -23,7 +23,7 @@ import android.content.Context;
import android.content.pm.ProviderInfo;
import android.database.Cursor;
import android.net.Uri;
-import androidx.annotation.Nullable;
+import android.support.annotation.Nullable;
import javax.annotation.OverridingMethodsMustInvokeSuper;
Took me ~5 mins to generate that, if people really need something then there are ways 🙃 for both ways AndroidX removal or AndroidX converting.
If more people contributed this would go a lot quicker. I myself am majorly burnt out working on v6 but I'm still going, hearing stuff like this isn't motivating me I can tell you that. 😩 There are only 2 maintainers working on this + @mikehardy actively helping out with issues, testing & triage. If anyone wants it quicker then I'd suggest contributing time or donating to pay for other contributors time. Not to rant though, I just genuinely wish more people contributed, /dreams |
Interestingly, it looks like all your support usage is annotations? Nullable is just a lint hint and the Keep might be implemented in a packaged proguard rule - you might be upgradable to androidx by deleting all references ;-). And yes, always better when the level of contribution rises to the level of requests for help :) |
@mikehardy indeed it's all annotations currently - until we hit messaging & AdMob, at which point the usages goes way beyond that 😞 but doesn't stop them being removed from the other modules I guess 🤔 |
Oh - if it goes beyond that I'd just ignore it then, it's a binary thing you either need androidx or not and if you can't get to zero save the time. I believe we're going to have a solution soon, there were some good AndroidX + react-native library results last night. We might be down to just making nitty-gritty tooling / CLI decisions shortly |
Play Services just shipped AndroidX breaking changes - if you must upgrade your android Firebase SDK dependencies
Then it will likely work (it worked for me). Update 20190811 - To be clear on one thing - there is a change on the tip of the v5.x.x branch that is unreleased (it will be in 5.5.7) that allows for better library specification for AndroidX in react-native 0.60 - I use the branch reference as my dependency currently: https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh#L12 But everything continues to work for me, I have successfully completed a migration to react-native 0.60.4 + AndroidX + Cocoapods and it hurt to do, but it all works with issues in react-native-firebase fixed along the way. Cheers |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
May I say, THANK YOU? I seem to finally be back on track to finishing my app now after the breaking changes I discovered last Tuesday. So again, I thank you. |
You’re welcome! Glad it helped. Remember to hook the jetifier call in package.json postinstall or you’ll blow up unexpectedly again after any module upgrades :-) |
@EskelCz you saved my live 👍 I'm new to the "switching to androidX" mess and spend a few evenings trying to fix the build (in an app that has to be on Google Play on Monday...), thanks! |
@michaelkowalski replying to say that @EskelCz solution is out of date and I would not recommend it. Altering things in node_modules is a last resort, and even if you did it you would want to use patch_package. The current community recommendation for an AndroidX migration is to use Android Studio to migrate your current app, and then to use the |
@mikehardy thanks for your reply! Yes, I saw the rest of the discussion and agree that it's far from the best solution. However for a quick fix it's great because it lets me generate the apk. After the Monday release I will certainly come back here and fix the issue in a more elegant way :) EDIT: ok, I did it now ;) works like a charm. Thanks for the library! However I had to install jetifier by yarn, the npm way led me to not being able to execute the command. |
The issue still persists for me, I am using androidX and enableJetifier
Packages:
I am now only getting three errors: I've added jetifier and run Any other thoughts on this @mikehardy, Thank you |
I am unable to reproduce - works for me with jetifier |
I'm having the same problem with @StuartMorris0 |
I worked with update core android from normal to androidX lib |
I would say upgrade core to |
Manually changing all the deprecated Imports to the new Androidx ones worked for me: |
You guys, the jetifier javascript package does that for you. Or, you can manually change the imports on every new install of every new version on every new machine - your choice I suppose? |
The two commands that @mikehardy suggested worked for me.
To make this work just delete node_module folder(rm -rf node_modules) and npm install. If this does not work for you, you can add your own script and added it in "postinstall", Eg:
and your packageFixer.js file is going to look like this:
This approach requires more work but can help you. You will need to repeat this script(not file) for each file that needs androidx |
I'm still stuck on these dependency issues. Not sure what the cause of it is, but it only started once I upgraded to RN 60.
|
@ccorcos ^ - try such overrides for gradle dependencies |
@OleksandrKucherenko that is some serious groovy code for gradle! It looks right (except maybe you could bump gradle to 3.12.3 (vs 3.12.1) - it is the latest that is still compatible down to API16 (for react-native) May I ask you to share your react-native native module dependency list so I could get an idea of which libraries are causing such conflicts? Because with my dependency list I don't have conflicts. I suspect maybe code-push or expokit but I'd like to see. Thanks! |
@mikehardy In my case overrides used for the project that has a dependency to ~20 react-native packages. Unfortunately, not all modules are updated to the latest versions, or even have a version that is compatible with AndroidX. that why born this code with global overrides, that deeply force versions of a specific java/android libs in all configurations. Most issues with RN 0.6x and AndroidX were in alignment/sync of different configurations used in the project. After such override all errors from build plugins, versions mismatch are gone. BUT it quite risky, no one guaranty backward compatibility (exception is only okhttp lib). So test your project carefully, upgrade version of each dependency and "commit" the result if app running well. |
I just spent couple days migrating our whole app from RN 0.53 to 0.60.5. The example provided by @mikehardy was a life saver. At one point I was doing:
with every dependency in the project. Probably over the top, but after 2 days of getting random gms dependency issues, I didn't care. That worked. Thanks @mikehardy, you are the man! |
Glad that helped, the rn60 upgrade is rough but your project is probably sparkly clean now ;-) - I know mine was pretty spiffy when I was done with it |
It may cause to other dependencies |
As this is one of google top result: |
[Edited: Note for people that want to use AndroidX - it is possible]
🔽 please see the comment below 🔽
#1588 (comment)
The text was updated successfully, but these errors were encountered: