1 | buildscript {
|
2 |
|
3 |
|
4 |
|
5 | if (project == rootProject) {
|
6 | repositories {
|
7 | google()
|
8 | mavenCentral()
|
9 | }
|
10 |
|
11 | dependencies {
|
12 | classpath("com.android.tools.build:gradle:7.3.1")
|
13 | }
|
14 | }
|
15 | }
|
16 |
|
17 | apply plugin: 'com.android.library'
|
18 |
|
19 | def safeExtGet(name) {
|
20 | rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties[name]
|
21 | }
|
22 |
|
23 | android {
|
24 | namespace 'com.reactnativerestart'
|
25 |
|
26 | compileSdkVersion safeExtGet('compileSdkVersion')
|
27 |
|
28 | defaultConfig {
|
29 | minSdkVersion safeExtGet('minSdkVersion')
|
30 | targetSdkVersion safeExtGet('targetSdkVersion')
|
31 | versionCode 1
|
32 | versionName "1.0"
|
33 | }
|
34 | buildTypes {
|
35 | release {
|
36 | minifyEnabled false
|
37 | }
|
38 | }
|
39 | lintOptions {
|
40 | disable 'GradleCompatible'
|
41 | }
|
42 | compileOptions {
|
43 | sourceCompatibility JavaVersion.VERSION_11
|
44 | targetCompatibility JavaVersion.VERSION_11
|
45 | }
|
46 | }
|
47 |
|
48 | repositories {
|
49 | mavenCentral()
|
50 | google()
|
51 |
|
52 | def found = false
|
53 | def defaultDir = null
|
54 | def androidSourcesName = 'React Native sources'
|
55 |
|
56 | if (rootProject.ext.has('reactNativeAndroidRoot')) {
|
57 | defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
|
58 | } else {
|
59 | defaultDir = new File(
|
60 | projectDir,
|
61 | '/../../../node_modules/react-native/android'
|
62 | )
|
63 | }
|
64 |
|
65 | if (defaultDir.exists()) {
|
66 | maven {
|
67 | url defaultDir.toString()
|
68 | name androidSourcesName
|
69 | }
|
70 |
|
71 | logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
|
72 | found = true
|
73 | } else {
|
74 | def parentDir = rootProject.projectDir
|
75 |
|
76 | 1.upto(5, {
|
77 | if (found) return true
|
78 | parentDir = parentDir.parentFile
|
79 |
|
80 | def androidSourcesDir = new File(
|
81 | parentDir,
|
82 | 'node_modules/react-native'
|
83 | )
|
84 |
|
85 | def androidPrebuiltBinaryDir = new File(
|
86 | parentDir,
|
87 | 'node_modules/react-native/android'
|
88 | )
|
89 |
|
90 | if (androidPrebuiltBinaryDir.exists()) {
|
91 | maven {
|
92 | url androidPrebuiltBinaryDir.toString()
|
93 | name androidSourcesName
|
94 | }
|
95 |
|
96 | logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
|
97 | found = true
|
98 | } else if (androidSourcesDir.exists()) {
|
99 | maven {
|
100 | url androidSourcesDir.toString()
|
101 | name androidSourcesName
|
102 | }
|
103 |
|
104 | logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
|
105 | found = true
|
106 | }
|
107 | })
|
108 | }
|
109 |
|
110 | if (!found) {
|
111 | throw new GradleException(
|
112 | "${project.name}: unable to locate React Native android sources. " +
|
113 | "Ensure you have you installed React Native as a dependency in your project and try again."
|
114 | )
|
115 | }
|
116 | }
|
117 |
|
118 | dependencies {
|
119 | api 'com.facebook.react:react-native:+'
|
120 | implementation 'com.jakewharton:process-phoenix:2.1.2'
|
121 | }
|