-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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] How to publish custom modules for android. #2679
Comments
Right now you can publish native code to maven central / jcenter and JS code to npm, and simply ask users to add both to their apps. This is not ideal and in the future we might want to look at a unified dependency system. One such system that I can imagine is have developers still publish separately to npm / maven / cocoapods, but in their package.json specify the maven and cocoapods dependencies. So when a user adds that dependency to their npm project we pick it up and automatically add the maven and cocopods deps to android and iOS. WDYT? |
That would also require us to write code that picks up new native modules / views from added dependencies. Right now you have to manually add those to your |
I'm probably not the best person to answer this coz i don't have much experience with cocoapods/jcenter. From past experience, npm worked really well for ios modules and then manually drag and drop to xcode project(one time task/not after every npm install). |
Having to distribute on npm / jcenter / cocoapods would be really annoying. If we can leverage |
Currently I'm in favor of npm for distribution and cocoapods/gradle for linking. |
I think there are two things we lose from the JAR:
As a general engineering principle I'd rather things be fast and push caching as low as possible, where it makes sense. In this case if we could always build from source and tell gradle/javac to be smart when the lib source files haven't changed I think that'd be much better. |
I see what you mean and def agree to it. I just published react-native-mail and tried to npm install and use it in a project. Here is what i had to do:
Seems like npm is a good option. |
@ide @chirag04 plus 1 to distributing over NPM. I think it's been working relatively well for iOS packages...and @chirag04 if there really is only 3 lines to get something installed into an Android project (or at least 3 lines for simple packages), seems like we have a winner :) I also think that linking external packages might be something that react-native-cli could help with down the road. |
So I think it should be possible to use a custom gradle plugin to add files to the classpath. That plugin could then walk the If that doesn't work, it should definitely be possible to create an autogenerated I 100% do believe though that Android dependencies should be distributed through npm, and ideally as uncompiled code as @ide said. The barrier to entry for component maintainers is many times higher if they have to publish to both maven and npm, and there's also a lot of potential confusion for users if they need to keep their |
Sorry for the delay on this. I agree that distributing Java sources via npm is the easiest way for contributors. People are already doing that and modules that contain Java code even have a little Android icon at React.parts. Since we all agree, let's say this part is decided :) Now we just need to figure out an easy way to consume the modules. I haven't had time to look into this yet but @chirag04's approach looks good. We could just include that in all projects generated by |
Nice. peerDependencies is probably the only concern left then. @mkonicek thoughts on that? |
Could we check peer deps at runtime? I'm more concerned about subtle runtime bugs than code that doesn't compile because of mismatched versions. For example we could expose the RN release number via JS and Java and ObjC so module authors could check it. |
I did some search around and seems like there are ways to handle looping @satya164 who is active on android stuff. Would you have ideas? |
I'm not familiar with peerDependencies yet. Will try to find time to look into it soon. |
@mkonicek Quick idea about peerDependencies: if the custom module and main project both depend on same lib, then let the custom module depend on the lib installed by main project. eg: Also, It works in ios by giving two header search paths:
|
OK I read a bit about the peerDependencies, let's check my understanding of what peerDependencies are for: Let's say you want to write a module, called
Now let's say
Now, the Java code in The module did, however, declare a dependency on ^0.11.4, which says the JS, Java, and Obj-C code are all designed to work with React Native ^0.11.4. We release 0.11.4 Android binaries and 0.11.4 Obj-C sources whenever we release 0.11.4 to npm, all parts (JS, Obj-C, Java) of the framework are always defined by a single version number. I believe this is how it works on iOS right now, correct? Can we do it the same way on Android? |
An important question is: what do you do if you want your Obj-C or Java code have a dependency on some other Obj-C / Java library? Let's say you want to use One simple way of doing that on Android would be to simply publish wire-2.0.0.jar to npm along with your module code and tell Gradle to look for jars in |
A bit unrelated to the peerDependencies discussion but just talked to Tadeu about having a script (later down the road) to make installing cross-platform libraries easier. Something like:
There was a related PR long time ago: #485 |
@mkonicek link sounds awesome. you got most of it with
For external deps like |
@chirag04 Sorry for the late reply. This thread is long and I didn't have enough time. I don't have any experince with distributing modules via maven/jcenter though. I recently tried some Android modules from npm and they were straight forward to set up. While distributing Java code through npm seems a good approach, I'm wondering, are the dependencies of those packages automatically downloaded by gradle? For external deps, I think, it can get cumbersome to add dependencies manually, and update them. |
Yes, we should probably add something like this to new projects by default to allow that:
A 3rd party module, like When writing apps, people just need to be careful to upgrade React Native's both JS (in package.json) and Java code (in build.gradle) when upgrading to a newer React Native version. This could be a pain though ..
Not yet but we should make it so, see point 1. |
Created #3267 for a separate discussion on publishing React Native itself to JCenter vs npm. |
FYI I'm going to be available sporadically for the next 3 weeks (conference and vacation). Plan to pick this up and make publishing and consuming modules on Android a good experience once I'm back. |
Hey guys, I just looked at this issue again. It was super useful discussion. Some of what we talked about here inspired my work on "react-native link" and Mike Grabowski and Alexey Kureev implemented a much better version of it rnpm. For creating new modules there is 'react-native new-library' which rnpm might improve further. I'll close this now, thanks again for the input on this. I'm going to update the Known issues part since rnpm already solved it. |
Currently npm and cocopod is just for publishing custom mdules for ios. Let's document the best way for android also.
keeping this as a tracking issue for the known issue(http://facebook.github.io/react-native/docs/known-issues.html#content)
cc @brentvatne @ide @mkonicek
The text was updated successfully, but these errors were encountered: