Skip to content

Commit b2c497f

Browse files
committed
refactor: simplify gradle configuration
1 parent 23f26f5 commit b2c497f

File tree

2 files changed

+5
-75
lines changed

2 files changed

+5
-75
lines changed

.github/workflows/build-templates.yml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,6 @@ jobs:
201201
run: |
202202
yarn turbo run build:android --cache-dir=".turbo/cache"
203203
204-
- name: Cache iOS build
205-
if: env.ios_build == 1
206-
uses: mikehardy/buildcache-action@v1
207-
208204
- name: Cache cocoapods
209205
if: env.ios_build == 1
210206
id: library-cocoapods-cache
@@ -225,17 +221,7 @@ jobs:
225221
yarn example pods
226222
env:
227223
NO_FLIPPER: 1
228-
229-
- name: Cache iOS build artifacts
230-
if: env.ios_build == 1
231-
uses: actions/cache@v3
232-
with:
233-
path: |
234-
~/Library/Developer/Xcode/DerivedData
235-
key: ${{ runner.os }}-library-xcode-derived-data-${{ hashFiles(format('{0}/**/Podfile', env.work_dir)) }}-${{ hashFiles(format('{0}/**/yarn.lock', env.work_dir)) }}
236-
restore-keys: |
237-
${{ runner.os }}-library-xcode-derived-data-${{ hashFiles(format('{0}/**/Podfile', env.work_dir)) }}-
238-
${{ runner.os }}-library-xcode-derived-data-
224+
CI: 0 # Hermes is built from source when CI=1
239225

240226
- name: Build example (iOS)
241227
if: env.ios_build == 1

packages/create-react-native-library/templates/native-common/android/build.gradle

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,6 @@ def isNewArchitectureEnabled() {
2222
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
2323
}
2424

25-
def resolveReactNativeDirectory() {
26-
def reactNativeLocation = rootProject.hasProperty("reactNativeDir") ? rootProject.getProperty("reactNativeDir") : null
27-
28-
if (reactNativeLocation != null) {
29-
return file(reactNativeLocation)
30-
}
31-
32-
try {
33-
// Resolve React Native location with Node
34-
// This will make sure that we get installation location correctly in monorepos
35-
def reactNativePackageJsonPathStdout = new ByteArrayOutputStream()
36-
37-
exec {
38-
commandLine("node", "-p", "require.resolve('react-native/package.json')")
39-
ignoreExitValue true
40-
standardOutput = reactNativePackageJsonPathStdout
41-
}
42-
43-
def reactNativeFromProjectNodeModules = file(reactNativePackageJsonPathStdout.toString().trim()).getParentFile();
44-
45-
if (reactNativeFromProjectNodeModules.exists()) {
46-
return reactNativeFromProjectNodeModules
47-
}
48-
} catch (e) {
49-
// Ignore
50-
}
51-
52-
throw new Exception(
53-
"${project.name}: Failed to resolve 'react-native' in the project. " +
54-
"If you have a non-standard project structure, you can specify 'reactNativeDir' with the path to 'react-native' in your 'gradle.properties' file."
55-
)
56-
}
57-
5825
apply plugin: "com.android.library"
5926
<% if (project.kotlin) { -%>
6027
apply plugin: "kotlin-android"
@@ -72,13 +39,6 @@ def getExtOrIntegerDefault(name) {
7239
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["<%- project.name -%>_" + name]).toInteger()
7340
}
7441

75-
def reactNativeRootDir = resolveReactNativeDirectory()
76-
def reactProperties = new Properties()
77-
file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
78-
79-
def reactNativeVersion = reactProperties.getProperty("VERSION_NAME")
80-
def (reactNativeMajorVersion, reactNativeMinorVersion) = reactNativeVersion.split("\\.").collect { it.isInteger() ? it.toInteger() : it }
81-
8242
android {
8343
<% if (project.cpp) { -%>
8444
ndkVersion getExtOrDefault("ndkVersion")
@@ -151,33 +111,17 @@ android {
151111
repositories {
152112
mavenCentral()
153113
google()
154-
155-
if (reactNativeMajorVersion == 0 && reactNativeMinorVersion < 71) {
156-
def androidSourcesDir = file("$reactNativeRootDir/android")
157-
def androidSourcesName = "React Native sources"
158-
159-
if (androidSourcesDir.exists()) {
160-
maven {
161-
url androidSourcesDir.toString()
162-
name androidSourcesName
163-
}
164-
}
165-
}
166114
}
167115

168116
<% if (project.kotlin) { -%>
169117
def kotlin_version = getExtOrDefault("kotlinVersion")
170118
<% } -%>
171119

172120
dependencies {
173-
if (reactNativeMajorVersion == 0 && reactNativeMinorVersion < 71) {
174-
//noinspection GradleDynamicVersion
175-
implementation "com.facebook.react:react-native:+"
176-
// From node_modules
177-
} else {
178-
implementation "com.facebook.react:react-android"
179-
}
180-
121+
// For < 0.71, this will be from the local maven repo
122+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
123+
//noinspection GradleDynamicVersion
124+
implementation "com.facebook.react:react-native:+"
181125
<% if (project.kotlin) { -%>
182126
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
183127
<% } -%>

0 commit comments

Comments
 (0)