Skip to content

Commit 062b83e

Browse files
authored
fix: Allow building React Native from source (#131)
1 parent a1b5cd8 commit 062b83e

File tree

6 files changed

+52
-8
lines changed

6 files changed

+52
-8
lines changed

android/app/build.gradle

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ buildscript {
55
apply from: "$buildscriptDir/../test-app-util.gradle"
66

77
repositories {
8-
jcenter()
98
google()
9+
jcenter()
1010
}
1111

1212
dependencies {
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
14-
classpath "com.android.tools.build:gradle:3.6.1"
14+
classpath "com.android.tools.build:gradle:3.6.2"
1515
}
1616
}
1717

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

23-
jcenter()
2423
google()
24+
jcenter()
2525
}
2626

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

3737
project.ext.react = [
38-
enableFlipper: getFlipperVersion(rootDir),
39-
enableHermes: true,
38+
enableFlipper: getFlipperVersion(rootDir),
39+
enableHermes: true,
4040
]
4141

4242
android {
@@ -87,7 +87,11 @@ dependencies {
8787
releaseImplementation files("$hermesPath/hermes-release.aar")
8888
debugImplementation files("$hermesPath/hermes-debug.aar")
8989

90-
implementation "com.facebook.react:react-native:+"
90+
if (buildReactNativeFromSource(rootDir)) {
91+
implementation project(':ReactAndroid')
92+
} else {
93+
implementation "com.facebook.react:react-native:+"
94+
}
9195

9296
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
9397
implementation "androidx.appcompat:appcompat:1.1.0"

android/react-native-build.gradle

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
buildscript {
2+
repositories {
3+
google()
4+
jcenter()
5+
}
6+
dependencies {
7+
classpath 'com.android.tools.build:gradle:3.6.2'
8+
classpath 'de.undercouch:gradle-download-task:4.0.4'
9+
}
10+
}
11+
12+
allprojects {
13+
repositories {
14+
google()
15+
jcenter()
16+
}
17+
configurations.all {
18+
resolutionStrategy {
19+
dependencySubstitution {
20+
substitute module("com.facebook.react:react-native:+") with project(":ReactAndroid")
21+
}
22+
}
23+
}
24+
}

android/test-app-util.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import java.nio.file.Paths
22

3+
ext.buildReactNativeFromSource = { baseDir ->
4+
def reactNativePath = findNodeModulesPath(baseDir, 'react-native')
5+
return !file("${reactNativePath}/android").exists()
6+
}
7+
38
ext.findFile = { fileName ->
49
def currentDir = file(rootDir)
510
while (currentDir != null) {

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"peerDependencies": {
1313
"react": "~16.8.6 || ~16.9.0 || ~16.11.0 || ~16.13.1",
14-
"react-native": "^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63",
14+
"react-native": "^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63 || 1000.0.0",
1515
"react-native-macos": "^0.60 || ^0.61.39"
1616
},
1717
"devDependencies": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"peerDependencies": {
4343
"react": "~16.8.6 || ~16.9.0 || ~16.11.0 || ~16.13.1",
44-
"react-native": "^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63",
44+
"react-native": "^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63 || 1000.0.0",
4545
"react-native-macos": "^0.60 || ^0.61.39"
4646
},
4747
"devDependencies": {

test-app.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
import groovy.json.JsonSlurper
2+
import java.nio.file.Paths
23
import org.gradle.initialization.DefaultSettings
34

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

8+
if (settings.buildReactNativeFromSource(settings.rootDir)) {
9+
def buildFile = Paths.get("${projectDir}/android/react-native-build.gradle")
10+
settings.rootProject.buildFileName = settings.rootDir.toPath().relativize(buildFile)
11+
12+
def reactNativeDir = settings.findNodeModulesPath(settings.rootDir, "react-native")
13+
settings.include(":ReactAndroid")
14+
settings.project(":ReactAndroid")
15+
.projectDir = new File("${reactNativeDir}/ReactAndroid")
16+
}
17+
718
settings.include(":app")
819
settings.project(":app")
920
.projectDir = new File("${projectDir}/android/app")

0 commit comments

Comments
 (0)