Skip to content

Commit

Permalink
Consume Android artifacts from npm
Browse files Browse the repository at this point in the history
Summary:
This lets us say goodbye to Maven Central. This will greatly simplify
and speed up the release process as releasing Android artifacts to
Maven Central adds a lot of [complexity](https://github.com/facebook/react-native/blob/master/Releases-publish.md)
and delays the whole release by several hours when we have to wait
for the artifacts to propagate.

This diff assumes there's a local Maven repo at
`node_modules/react-native/android`.

The second part once this lands is to change our `release.sh` script to
output the artifacts under `react-native/android` before publishing to
npm.

This adds 3.7MB to the size of `node_modules` of any app. However,
we just download eagerly what we'd normally download later via Gradle.

**Test plan**

Released RN including a local Maven repo into Sinopia:

    $ cd react-native
    # Updated version in gradle.properties to 0.21.0
    $ ./gradlew ReactAndroid:installArchives
    # Moved everything in .m2/repository/com/facebook/react to react-native/android
    $ ls react-native/android
    com/facebook/react/react-native/0.21.0/react-native-0.21.0.aar
    com/facebook/react/react-native/0.21.0/react-native-0.21.0.pom
    com/facebook/react/react-native/maven-metadata.xml
    ...

    # Set version in package.json to 0.21.0
    $ npm set registry http://localhost:4873/
    $ npm publish

Created and ran an app:

   $ cd /tmp
   $ react-native init AndroidNpm
   $ cd AndroidNpm
   $ react-native run-android

It worked.

Checked that we're using the artifacts from node_modules/react-native/android:

    $ cd android
    $ ./gradlew app:dependencies
    compile - Classpath for compiling the main sources.
    +--- com.android.support:appcompat-v7:23.0.1
    |    \--- com.android.support:support-v4:23.0.1
    |         \--- com.android.support:support-annotations:23.0.1
    \--- com.facebook.react:react-native:+ -> 0.21.0
         +--- com.google.code.findbugs:jsr305:3.0.0
         +--- com.facebook.stetho:stetho-okhttp:1.2.0
    ...

Checked that Android Studio can find the source jars (you can navigate to RN sources in Android Studio). Opened the new project as described in the [docs](https://facebook.github.io/react-native/docs/android-setup.html#editing-your-app-s-java-code-in-android-studio).

public

Reviewed By: bestander

Differential Revision: D2912557

fb-gh-sync-id: 251c180518a3fb9bb8e80963b236e982d65533be
shipit-source-id: 251c180518a3fb9bb8e80963b236e982d65533be
  • Loading branch information
Martin Konicek authored and facebook-github-bot-4 committed Feb 9, 2016
1 parent 758d9e8 commit 702f999
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
9 changes: 4 additions & 5 deletions local-cli/generator-android/templates/src/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ import com.android.build.OutputFile
apply from: "react.gradle"

/**
* Set this to true to create three separate APKs instead of one:
* - A universal APK that works on all devices
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
Expand Down Expand Up @@ -93,9 +92,9 @@ android {
}
splits {
abi {
enable enableSeparateBuildPerCPUArchitecture
universalApk false
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
Expand Down Expand Up @@ -123,5 +122,5 @@ android {
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:0.13.0"
compile "com.facebook.react:react-native:+" // From node_modules
}
4 changes: 4 additions & 0 deletions local-cli/generator-android/templates/src/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$projectDir/../../node_modules/react-native/android"
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"files": [
"React",
"React.podspec",
"ReactAndroid",
"android",
"Libraries",
"packager",
"cli.js",
Expand Down

6 comments on commit 702f999

@mangogogos
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this allow you to make changes to react android code directly without having to follow the steps at https://facebook.github.io/react-native/docs/android-building-from-source.html#content ?

@ide
Copy link
Contributor

@ide ide commented on 702f999 Feb 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mangogogos no, this means the AAR is distributed with npm instead of maven.

@satya164
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@mkonicek
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mangogogos This commit actually also removed the Android sources from the npm package. Didn't realize they were useful for that use case (I always modify files in the GitHub checkout). Adding them back in the next release: 403176a.

Sorry about removing them in the first place!

@satya164
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkonicek Won't having the sources in the npm package increase the size? people who want to compile can always clone/install from GitHub.

@satya164
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkonicek Seems the ReactAndroid folder is 4.8M. IMHO we shouldn't have it in the NPM package.

Please sign in to comment.