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

Package AAR file #255

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

fourlastor
Copy link

@fourlastor fourlastor commented Jan 3, 2018

This PR introduces pre-packaging of the Android lib in as an AAR archive, as per #239.

This solves a bunch of problems with the current approach, as described in the issue (Android Studio failing to compile from time to time, different build tools version between client and library and compilation time).

I added a dev dependency to react-native, but the library is packaged with a provide directive so it won't include react-native in the artifact, it's still required to compile the library.

The lib version is parsed from package.json and to compile the lib you can invoke ./gradlew generateReactArchive.

What's left to do is to include the artifact inside the published npm library, for which I don't know the process, happy to add more stuff if someone can point me in the right direction :)

The only doubt I had was with the react-native link command, but I tried and it seems like it won't add it to the project, so that should be fine. Ideally there would be a way to customise what link adds to the project on a per-library basis. This also means this PR implies react-native link won't work anymore for Android.

Also, I think this should remove the need to specify the build tools version with an ext variable as this won't create problems anymore.

@sibelius
Copy link
Collaborator

is this a breaking change?

can u upgrade example as well?

@grabbou
Copy link

grabbou commented Feb 12, 2018

Hey, I have a couple of questions to better understand this pull request:

The only doubt I had was with the react-native link command, but I tried and it seems like it won't add it to the project, so that should be fine

I see no code here that would make link skip this library, looks like it can be a temporary unintended bug? Anyway, there's a way to disable linking of a particular platform for a library, by setting rnpm.android to null on a package.json.

Do you think you could use a postlink hook to write a script that manually adds the maven repository part? I am afraid this might be a bit confusing for people that will automatically attempt linking the library.

@fourlastor
Copy link
Author

is this a breaking change?

It shouldn't break anything since I didn't touch the source code of the lib.

can u upgrade example as well?

Will do

I see no code here that would make link skip this library, looks like it can be a temporary unintended bug? Anyway, there's a way to disable linking of a particular platform for a library, by setting rnpm.android to null on a package.json.

Didn't know about that, will add it, thanks :)

Do you think you could use a postlink hook to write a script that manually adds the maven repository part? I am afraid this might be a bit confusing for people that will automatically attempt linking the library.

I can try that, didn't know about postlink, thanks :)

@fourlastor
Copy link
Author

Hey @grabbou @sibelius, I'm back!

Sorry it took so long to get back to you, I've had some other priorities at work and this got delayed.

I'm also moving the issue discussion here so we have only one thread to focus on.

I've been trying to experiment a bit with prelink/postlink, and I've been struggling a bit with some things:

  1. If I set rnpm.android to null, it will skip the linking and it won't run prelink or postlink, this means (I think) there's no way to disable the default link behavior.
  2. I'm not sure if link will pass any arguments to prelink/postlink, I tried to put xargs echo on prelink to check and it seems like it doesn't pass anything to them. That means it's going to be very tricky to get the project config, know where to apply possible diffs, and add the dependencies.
  3. There aren't platform specific hooks for link, which means the script will be run on both iOS and Android

Solution to 2 might be including the same functions we use for running link, and fetching the configs again, but there's little to zero doc on what is what (most of the knowledge I got has been through running in a debugger the link function)

Solution to 3 I suppose would be either pass configs to the prelink script (maybe forcing it to be a js file which exports a well defined function?) or having a commands key in every platform (so, for example, rnpm.android.commands.prelink).

Any idea on what would be the next step?

@radex
Copy link
Member

radex commented Oct 26, 2018

Hey @fourlastor! I don't feel comfortable merging Android PRs, since I'm not really qualified in this area, but is there any prior art as far as AAR packages go in react-native world? I don't think I've seen an RN native module published this way before

@fourlastor
Copy link
Author

fourlastor commented Dec 14, 2018

@radex react native itself is shipped as an AAR library, instead of having the source code in the NPM package.

@satya164
Copy link

The current approach has its advantages. In several projects, we use patch-package to patch the module when we have compatibility issues or fixes that are not merged into the module. Shipping pre-compiled binary will make it much harder.

@sibelius
Copy link
Collaborator

can't we have both approach?

precompiled and enabling patching code as well?

@brentvatne brentvatne removed their request for review September 2, 2020 18:25
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

Successfully merging this pull request may close these issues.

None yet

5 participants