Skip to content

Commit 49ced03

Browse files
authored
Improve new architecture code (#850)
1 parent fd09332 commit 49ced03

35 files changed

+434
-444
lines changed

RNPermissions.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Pod::Spec.new do |s|
1616

1717
s.source = { :git => package["repository"]["url"], :tag => s.version }
1818
s.source_files = "ios/*.{h,mm}"
19+
# s.frameworks = <frameworks>
1920

2021
if ENV['RCT_NEW_ARCH_ENABLED'] == "1" then
2122
install_modules_dependencies(s)

android/build.gradle

Lines changed: 21 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,29 @@
1-
def safeExtGet(prop, fallback) {
2-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
3-
}
4-
51
buildscript {
6-
// The Android Gradle plugin is only required when opening the android folder stand-alone.
7-
// This avoids unnecessary downloads and potential conflicts when the library is included as a
8-
// module dependency in an application project.
9-
if (project == rootProject) {
10-
repositories {
11-
google()
12-
mavenCentral()
13-
}
14-
dependencies {
15-
classpath("com.android.tools.build:gradle:4.2.2")
16-
}
2+
ext.safeExtGet = {prop, fallback ->
3+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
174
}
18-
}
19-
20-
apply plugin: "com.android.library"
21-
22-
def resolveReactNativeDirectory() {
23-
// monorepo workaround (react-native can be hoisted or in project's own node_modules)
24-
def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
25-
if (reactNativeFromProjectNodeModules.exists()) {
26-
return reactNativeFromProjectNodeModules
5+
repositories {
6+
google()
7+
gradlePluginPortal()
278
}
28-
29-
def reactNativeFromNodeModulesWithLibrary = file("${projectDir}/../../react-native")
30-
if (reactNativeFromNodeModulesWithLibrary.exists()) {
31-
return reactNativeFromNodeModulesWithLibrary
9+
dependencies {
10+
classpath("com.android.tools.build:gradle:7.3.1")
3211
}
33-
34-
throw new Exception(
35-
"[react-native-permissions] Unable to resolve react-native location in " +
36-
"node_modules. You should add project extension property (in app/build.gradle) " +
37-
"`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
38-
)
3912
}
4013

41-
def REACT_NATIVE_DIR = resolveReactNativeDirectory()
42-
43-
def reactProperties = new Properties()
44-
file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
45-
46-
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
47-
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
48-
4914
def isNewArchitectureEnabled() {
50-
// To opt-in for the New Architecture, you can either:
51-
// - Set `newArchEnabled` to true inside the `gradle.properties` file
52-
// - Invoke gradle with `-newArchEnabled=true`
53-
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
5415
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
5516
}
5617

18+
apply plugin: "com.android.library"
19+
5720
if (isNewArchitectureEnabled()) {
5821
apply plugin: "com.facebook.react"
5922
}
6023

6124
android {
62-
// Used to override the NDK path/version on internal CI or by allowing
63-
// users to customize the NDK path/version from their root project (e.g. for M1 support)
64-
if (rootProject.hasProperty("ndkPath")) {
65-
ndkPath rootProject.ext.ndkPath
66-
}
67-
if (rootProject.hasProperty("ndkVersion")) {
68-
ndkVersion rootProject.ext.ndkVersion
69-
}
70-
71-
compileSdkVersion safeExtGet("compileSdkVersion", 33)
7225
buildToolsVersion safeExtGet("buildToolsVersion", "33.0.0")
26+
compileSdkVersion safeExtGet("compileSdkVersion", 33)
7327

7428
if (project.android.hasProperty("namespace")) {
7529
namespace "com.zoontek.rnpermissions"
@@ -84,40 +38,34 @@ android {
8438
}
8539
}
8640
defaultConfig {
41+
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())
8742
minSdkVersion safeExtGet("minSdkVersion", 21)
8843
targetSdkVersion safeExtGet("targetSdkVersion", 33)
8944
}
9045
lintOptions {
9146
abortOnError false
9247
}
93-
sourceSets.main {
94-
java {
95-
if (!isNewArchitectureEnabled()) {
96-
srcDirs += 'src/paper/java'
48+
sourceSets {
49+
main {
50+
if (isNewArchitectureEnabled()) {
51+
java.srcDirs += ["src/newarch"]
52+
} else {
53+
java.srcDirs += ["src/oldarch"]
9754
}
9855
}
9956
}
10057
}
10158

10259
repositories {
103-
mavenLocal()
104-
mavenCentral()
10560
maven {
10661
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
107-
url "$rootDir/../node_modules/react-native/android"
108-
}
109-
maven {
110-
// Android JSC is installed from npm
111-
url "$rootDir/../node_modules/jsc-android/dist"
62+
url("$rootDir/../node_modules/react-native/android")
11263
}
64+
mavenCentral()
11365
google()
11466
}
11567

11668
dependencies {
117-
if (isNewArchitectureEnabled() && REACT_NATIVE_MINOR_VERSION < 71) {
118-
implementation project(":ReactAndroid")
119-
} else {
120-
//noinspection GradleDynamicVersion
121-
implementation 'com.facebook.react:react-native:+'
122-
}
69+
//noinspection GradleDynamicVersion
70+
implementation "com.facebook.react:react-native:+" // From node_modules
12371
}

0 commit comments

Comments
 (0)