-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
[RFC][RNTester] Move Flipper init out of app code #28052
Conversation
RNTester (Android/hermes/arm64-v8a): 3276800 bytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this change. I had issues with manual Flipper set up before. Removing the friction for app devs is 😍😍
@@ -464,6 +464,20 @@ dependencies { | |||
androidTestImplementation("androidx.test:runner:${ANDROIDX_TEST_VERSION}") | |||
androidTestImplementation("androidx.test:rules:${ANDROIDX_TEST_VERSION}") | |||
androidTestImplementation("org.mockito:mockito-core:${MOCKITO_CORE_VERSION}") | |||
|
|||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is swipe refresh used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In React core itself. I wanted to have looked into this but haven't had a chance yet. Somehow the swipe layout no longer compiles now without explicitly depending on it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is great!
Did some more testing and I think this isn't feasible for the template as it works right now. I don't have a full understanding of how the dynamic generation of the Practically speaking, this means you'll get this error when trying to build a debug version of your app generated from the tempalate: I see two options here:
or some similar naming scheme. |
We generate prebuilt archives on releases, its somewhat documented here https://github.com/facebook/react-native/wiki/Building-from-source#publish-your-own-version-of-react-native. What about publishing this as a separate package on npm (or maybe as part of react-native-flipper)? It could be installed / linked in the default template. |
Separate npm artifact could work, but I'm not sure if it's worth the effort, because we'd have to duplicate a lot of code and setup. We'd need another Gradle project, set up the AAR generation, make sure this ends up in the right npm package and also ensure that this can be tested properly. Certainly a possibility, though! |
I think it could be like a regular native module package, it gets built from souce by apps so there is no need to setup aar generation. Thinking about it more what about just including the code in rn-flipper and adding it to the default project template? |
@janicduplessis Could you expand on this? What is |
https://github.com/facebook/flipper/tree/master/react-native/react-native-flipper I’m wondering if it would make sense to move all RN <=> Flipper integration to this package and include it by default in the template. |
Gotcha. I don't think it's a good place, to be honest. This is really just setup code that belongs in your application, ultimately. The reason for moving it out of the template is just so that the default setup looks a bit cleaner. But if somebody were to remove a plugin here, for instance, or change its configuration, they would still effectively need to copy the body of the method. But specifically, the plugins being set up here are very specific to what React Native ships with. If you were to ever move away from Fresco, OkHttp or made an API change to how the The way it is set up right now with all the code being part of the template itself provides the maximum flexibility here and we're only considering moving it out because it is quite verbose and adds a bit of mental overhead, especially when you're new to this kind of development and just want to poke around in the generated code. |
@passy Makes sense, I'm curious how did you test this change? Maybe the error is just that the generated archive wasn't updated with the code changes you made? Running If that isn't the issue we could just make the class available in all builds. It is pretty small anyway, I don't think we do anything special already to remove other debug classes from release builds anyway (https://github.com/facebook/react-native/tree/master/ReactAndroid/src/main/java/com/facebook/react/devsupport). Hopefully proguard can remove those classes. |
If that isn't the issue we could just make the class available in all builds. It is pretty small anyway, I don't think we do anything special already to remove other debug classes from release builds anyway (https://github.com/facebook/react-native/tree/master/ReactAndroid/src/main/java/com/facebook/react/devsupport). Hopefully proguard can remove those classes. The problem here is that we would then need to depend on the Flipper dependencies for the release builds which get transitively pulled in. Alternatively, we make them
Thanks, I'll give that a try. |
I used So I think the correct course of action here is to set up another build artifact that gets generated as part of the I saw that there's some logic for different "variants" in the top-level |
@DanielZlotin I found your fingerprints on some of the logic in |
Right, it's been a long time since I touched this, not up to date on any of this so I could be way off.. |
Maybe @dulmandakh can help here? My knowledge of android build system is not good enough to assist more in figuring out the best way to do this. If this requires too much work I feel like it might just be better to keep the flipper integration as is for android. |
@DanielZlotin Thanks a lot for the context! Still struggling a bit figuring out how to create a separate maven publication that then hooks into the debug configuration. Just grepping around on GitHub it appears to be possible to publish AARs with debug flavours but I could only find this set up in projects that are a lot more "vanilla" then this. |
@passy I just noticed this is still open, should we merge or abandon it? |
@rickhanlonii It's probably too invasive right now. I don't have enough insight into how the internal build process works and so far people seemed to have been okay with the code we add to the app itself, so I'm gonna close this here. |
Summary
This is an attempt to minimise the amount of setup code that's needed to get Flipper up and running in an application. I wanted to showcase this first in RNTester, but I still need to confirm that this pattern would even work with the standard template as the setup there is a bit unusual and I'm unsure if debug flavours will work there as expected.
Anyway, before going into this, I'd like to discuss if this is helpful in striking a better balance between adding code to people's apps and customisability.
Changelog
[Android] [Changed] Move Flipper initialisation into ReactAndroid core
Test Plan
RNTester builds, Flipper connects.