1
- import java.nio.file.Paths
2
-
3
- def getExtOrDefault (name ) {
4
- return rootProject. ext. has(name) ? rootProject. ext. get(name) : project. properties[" Worklets_" + name]
5
- }
6
-
7
- def getExtOrIntegerDefault (name ) {
8
- return getExtOrDefault(name). toInteger()
9
- }
10
-
11
- def isNewArchitectureEnabled () {
12
- return rootProject. hasProperty(" newArchEnabled" ) && rootProject. getProperty(" newArchEnabled" ) == " true"
13
- }
14
-
15
- static def findNodeModules (baseDir ) {
16
- def basePath = baseDir. toPath(). normalize()
17
- // Node's module resolution algorithm searches up to the root directory,
18
- // after which the base path will be null
19
- while (basePath) {
20
- def nodeModulesPath = Paths . get(basePath. toString(), " node_modules" )
21
- def reactNativePath = Paths . get(nodeModulesPath. toString(), " react-native" )
22
- if (nodeModulesPath. toFile(). exists() && reactNativePath. toFile(). exists()) {
23
- return nodeModulesPath. toString()
24
- }
25
- basePath = basePath. getParent()
1
+ buildscript {
2
+ repositories {
3
+ google()
4
+ mavenCentral()
26
5
}
27
- throw new GradleException (" react-native-worklets-core: Failed to find node_modules/ path!" )
28
- }
29
6
30
- def JS_RUNTIME = {
31
- // Override JS runtime with environment variable
32
- if (System . getenv(" JS_RUNTIME" )) {
33
- return System . getenv(" JS_RUNTIME" )
7
+ dependencies {
8
+ classpath " com.android.tools.build:gradle:7.2.1"
34
9
}
35
-
36
- // Check if Hermes is enabled in app setup
37
- def appProject = rootProject. allprojects. find { it. plugins. hasPlugin(' com.android.application' ) }
38
- if (appProject?. hermesEnabled?. toBoolean()) {
39
- return " hermes"
40
- }
41
-
42
- // Use JavaScriptCore (JSC) by default
43
- return " jsc"
44
- }. call()
45
-
46
- def nodeModules = findNodeModules(projectDir)
47
-
48
- def reactNativeArchitectures () {
49
- def value = project. getProperties(). get(" reactNativeArchitectures" )
50
- return value ? value. split(" ," ) : [" armeabi-v7a" , " x86" , " x86_64" , " arm64-v8a" ]
51
10
}
52
11
53
12
apply plugin : " com.android.library"
13
+ apply plugin : " com.facebook.react"
54
14
55
- if (isNewArchitectureEnabled()) {
56
- apply plugin : " com.facebook.react"
57
- }
58
-
59
- task prepareHeaders (type : Copy ) {
60
- from fileTree(' ../cpp' ). filter { it. isFile() }
61
- into " ${ project.buildDir} /headers/rnworklets/react-native-worklets-core/"
62
- includeEmptyDirs = false
15
+ def getExtOrDefault (name ) {
16
+ return rootProject. ext. has(name) ? rootProject. ext. get(name) : project. properties[" Worklets_" + name]
63
17
}
64
18
65
- task deleteCmakeCache () {
66
- doFirst {
67
- delete " ${ projectDir} /.cxx"
68
- }
19
+ def getExtOrIntegerDefault (name ) {
20
+ return rootProject. ext. has(name) ? rootProject. ext. get(name) : (project. properties[" Worklets_" + name]). toInteger()
69
21
}
70
22
71
23
android {
24
+ namespace " com.worklets"
25
+
26
+ ndkVersion getExtOrDefault(" ndkVersion" )
72
27
compileSdkVersion getExtOrIntegerDefault(" compileSdkVersion" )
73
28
74
29
defaultConfig {
@@ -77,39 +32,27 @@ android {
77
32
78
33
externalNativeBuild {
79
34
cmake {
80
- arguments " -DANDROID_STL=c++_shared" ,
81
- " -DANDROID_TOOLCHAIN=clang" ,
82
- " -DREACT_NATIVE_DIR=${ nodeModules} /react-native" ,
83
- " -DJS_RUNTIME=${ JS_RUNTIME} "
84
- abiFilters (* reactNativeArchitectures())
35
+ cppFlags " -O2 -frtti -fexceptions -Wall -fstack-protector-all"
85
36
}
86
37
}
87
38
}
88
39
89
- buildFeatures {
90
- prefab true
91
- }
92
-
93
- compileOptions {
94
- sourceCompatibility JavaVersion . VERSION_1_8
95
- targetCompatibility JavaVersion . VERSION_1_8
96
- }
97
-
98
40
externalNativeBuild {
99
41
cmake {
100
42
path " CMakeLists.txt"
101
43
}
102
44
}
103
45
46
+ buildFeatures {
47
+ buildConfig true
48
+ prefab true
49
+ }
50
+
104
51
buildTypes {
105
52
debug {
106
53
externalNativeBuild {
107
54
cmake {
108
- if (JS_RUNTIME == " hermes" ) {
109
- arguments " -DHERMES_ENABLE_DEBUGGER=1"
110
- } else {
111
- arguments " -DHERMES_ENABLE_DEBUGGER=0"
112
- }
55
+ arguments " -DHERMES_ENABLE_DEBUGGER=1"
113
56
}
114
57
}
115
58
}
@@ -119,62 +62,33 @@ android {
119
62
arguments " -DHERMES_ENABLE_DEBUGGER=0"
120
63
}
121
64
}
65
+ minifyEnabled false
122
66
}
123
67
}
124
68
125
- sourceSets {
126
- main {
127
- if (isNewArchitectureEnabled()) {
128
- java. srcDirs + = [" src/newarch" ]
129
- } else {
130
- java. srcDirs + = [" src/oldarch" ]
131
- }
132
- }
133
- }
134
-
135
- packagingOptions {
136
- excludes = [
137
- " META-INF" ,
138
- " META-INF/**" ,
139
- " **/libc++_shared.so" ,
140
- " **/libfbjni.so" ,
141
- " **/libjsi.so" ,
142
- " **/libfolly_json.so" ,
143
- " **/libfolly_runtime.so" ,
144
- " **/libglog.so" ,
145
- " **/libhermes.so" ,
146
- " **/libhermes-executor-debug.so" ,
147
- " **/libhermes_executor.so" ,
148
- " **/libreactnativejni.so" ,
149
- " **/libturbomodulejsijni.so" ,
150
- " **/libreact_nativemodule_core.so" ,
151
- " **/libjscexecutor.so" ,
152
- ]
153
- }
154
-
155
- buildFeatures {
156
- prefabPublishing true
69
+ lintOptions {
70
+ disable " GradleCompatible"
157
71
}
72
+ }
158
73
159
- prefab {
160
- rnworklets {
161
- headers " ${ project.buildDir} /headers/rnworklets/"
162
- }
163
- }
74
+ repositories {
75
+ mavenCentral()
76
+ google()
164
77
}
165
78
79
+
166
80
dependencies {
167
- implementation " com.facebook.react:react-android"
168
- if (JS_RUNTIME == " hermes" ) {
169
- implementation " com.facebook.react:hermes-android"
170
- }
171
- }
81
+ // For < 0.71, this will be from the local maven repo
82
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
83
+ // noinspection GradleDynamicVersion
84
+ implementation " com.facebook.react:react-native:+"
172
85
173
- preBuild. dependsOn(prepareHeaders)
86
+ // Requires Hermes Runtime
87
+ implementation " com.facebook.react:hermes-android"
88
+ }
174
89
175
- tasks. configureEach { task ->
176
- // C++ clean
177
- if (task. name. contains(" clean" )) {
178
- task. dependsOn(deleteCmakeCache)
179
- }
90
+ react {
91
+ jsRootDir = file(" ../src/" )
92
+ libraryName = " Worklets"
93
+ codegenJavaPackageName = " com.worklets"
180
94
}
0 commit comments