Navigation Menu

Skip to content

Commit

Permalink
fix: Allow building React Native from source (microsoft#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Jun 24, 2020
1 parent a1b5cd8 commit 062b83e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 8 deletions.
16 changes: 10 additions & 6 deletions android/app/build.gradle
Expand Up @@ -5,13 +5,13 @@ buildscript {
apply from: "$buildscriptDir/../test-app-util.gradle"

repositories {
jcenter()
google()
jcenter()
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "com.android.tools.build:gradle:3.6.1"
classpath "com.android.tools.build:gradle:3.6.2"
}
}

Expand All @@ -20,8 +20,8 @@ repositories {
url("${findNodeModulesPath(rootDir, "react-native")}/android")
}

jcenter()
google()
jcenter()
}

apply plugin: "com.android.application"
Expand All @@ -35,8 +35,8 @@ apply from: file("${testAppDir}/test-app.gradle")
applyTestAppModule(project, "com.sample")

project.ext.react = [
enableFlipper: getFlipperVersion(rootDir),
enableHermes: true,
enableFlipper: getFlipperVersion(rootDir),
enableHermes: true,
]

android {
Expand Down Expand Up @@ -87,7 +87,11 @@ dependencies {
releaseImplementation files("$hermesPath/hermes-release.aar")
debugImplementation files("$hermesPath/hermes-debug.aar")

implementation "com.facebook.react:react-native:+"
if (buildReactNativeFromSource(rootDir)) {
implementation project(':ReactAndroid')
} else {
implementation "com.facebook.react:react-native:+"
}

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation "androidx.appcompat:appcompat:1.1.0"
Expand Down
24 changes: 24 additions & 0 deletions android/react-native-build.gradle
@@ -0,0 +1,24 @@
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'de.undercouch:gradle-download-task:4.0.4'
}
}

allprojects {
repositories {
google()
jcenter()
}
configurations.all {
resolutionStrategy {
dependencySubstitution {
substitute module("com.facebook.react:react-native:+") with project(":ReactAndroid")
}
}
}
}
5 changes: 5 additions & 0 deletions android/test-app-util.gradle
@@ -1,5 +1,10 @@
import java.nio.file.Paths

ext.buildReactNativeFromSource = { baseDir ->
def reactNativePath = findNodeModulesPath(baseDir, 'react-native')
return !file("${reactNativePath}/android").exists()
}

ext.findFile = { fileName ->
def currentDir = file(rootDir)
while (currentDir != null) {
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Expand Up @@ -11,7 +11,7 @@
},
"peerDependencies": {
"react": "~16.8.6 || ~16.9.0 || ~16.11.0 || ~16.13.1",
"react-native": "^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63",
"react-native": "^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63 || 1000.0.0",
"react-native-macos": "^0.60 || ^0.61.39"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -41,7 +41,7 @@
},
"peerDependencies": {
"react": "~16.8.6 || ~16.9.0 || ~16.11.0 || ~16.13.1",
"react-native": "^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63",
"react-native": "^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63 || 1000.0.0",
"react-native-macos": "^0.60 || ^0.61.39"
},
"devDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions test-app.gradle
@@ -1,9 +1,20 @@
import groovy.json.JsonSlurper
import java.nio.file.Paths
import org.gradle.initialization.DefaultSettings

private static void apply(Settings settings) {
def projectDir = settings.findNodeModulesPath(settings.rootDir, "react-native-test-app")

if (settings.buildReactNativeFromSource(settings.rootDir)) {
def buildFile = Paths.get("${projectDir}/android/react-native-build.gradle")
settings.rootProject.buildFileName = settings.rootDir.toPath().relativize(buildFile)

def reactNativeDir = settings.findNodeModulesPath(settings.rootDir, "react-native")
settings.include(":ReactAndroid")
settings.project(":ReactAndroid")
.projectDir = new File("${reactNativeDir}/ReactAndroid")
}

settings.include(":app")
settings.project(":app")
.projectDir = new File("${projectDir}/android/app")
Expand Down

0 comments on commit 062b83e

Please sign in to comment.