@@ -10,7 +10,7 @@ buildscript {
1010 }
1111
1212 dependencies {
13- classpath ' com.android.tools.build:gradle:3.5.3 '
13+ classpath " com.android.tools.build:gradle:7.3.1 "
1414 }
1515 }
1616}
@@ -22,30 +22,100 @@ def safeExtGet(prop, fallback) {
2222}
2323println (" buildDir:" + rootProject. buildDir)
2424static def findNodeModules (baseDir ) {
25- def basePath = baseDir. toPath(). normalize()
26- // Node's module resolution algorithm searches up to the root directory,
27- // after which the base path will be null
28- while (basePath) {
29- def nodeModulesPath = Paths . get(basePath. toString(), " node_modules" )
30- def reactNativePath = Paths . get(nodeModulesPath. toString(), " react-native" )
31- if (nodeModulesPath. toFile(). exists() && reactNativePath. toFile(). exists()) {
32- return nodeModulesPath. toString()
33- }
34- basePath = basePath. getParent()
35- }
36- throw new GradleException (" Failed to find node_modules/ path!" )
25+ def basePath = baseDir. toPath(). normalize()
26+ // Node's module resolution algorithm searches up to the root directory,
27+ // after which the base path will be null
28+ while (basePath) {
29+ def nodeModulesPath = Paths . get(basePath. toString(), " node_modules" )
30+ def reactNativePath = Paths . get(nodeModulesPath. toString(), " react-native" )
31+ if (nodeModulesPath. toFile(). exists() && reactNativePath. toFile(). exists()) {
32+ return nodeModulesPath. toString()
33+ }
34+ basePath = basePath. getParent()
35+ }
36+ throw new GradleException (" Failed to find node_modules/ path!" )
3737}
3838def nodeModules = findNodeModules(projectDir)
39- def prebuiltDir = " $buildDir /react-native-0*/jni"
40- def reactProperties = new Properties ()
41- file(" $nodeModules /react-native/ReactAndroid/gradle.properties" ). withInputStream { reactProperties. load(it) }
42- def REACT_NATIVE_VERSION_NAME = reactProperties. getProperty(" VERSION_NAME" )
39+
40+ static def findNodeModulePath (baseDir , packageName ) {
41+ def basePath = baseDir. toPath(). normalize()
42+ // Node's module resolution algorithm searches up to the root directory,
43+ // after which the base path will be null
44+ while (basePath) {
45+ def candidatePath = Paths . get(basePath. toString(), " node_modules" , packageName)
46+ if (candidatePath. toFile(). exists()) {
47+ return candidatePath. toString()
48+ }
49+ basePath = basePath. getParent()
50+ }
51+ return null
52+ }
53+
54+ def safeAppExtGet (prop , fallback ) {
55+ def appProject = rootProject. allprojects. find { it. plugins. hasPlugin(' com.android.application' ) }
56+ appProject?. ext?. has(prop) ? appProject. ext. get(prop) : fallback
57+ }
58+
59+ def resolveBuildType () {
60+ Gradle gradle = getGradle()
61+ String tskReqStr = gradle. getStartParameter(). getTaskRequests()[' args' ]. toString()
62+ return tskReqStr. contains(' Release' ) ? ' release' : ' debug'
63+ }
64+
65+ def isNewArchitectureEnabled () {
66+ // To opt-in for the New Architecture, you can either:
67+ // - Set `newArchEnabled` to true inside the `gradle.properties` file
68+ // - Invoke gradle with `-newArchEnabled=true`
69+ // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
70+ return project. hasProperty(" newArchEnabled" ) && project. newArchEnabled == " true"
71+ }
72+
73+ def resolveReactNativeDirectory () {
74+ def reactNativeLocation = safeAppExtGet(" REACT_NATIVE_NODE_MODULES_DIR" , null )
75+ if (reactNativeLocation != null ) {
76+ return file(reactNativeLocation)
77+ }
78+
79+ // monorepo workaround
80+ // react-native can be hoisted or in project's own node_modules
81+ def reactNativeFromProjectNodeModules = file(" ${ rootProject.projectDir} /../node_modules/react-native" )
82+ if (reactNativeFromProjectNodeModules. exists()) {
83+ return reactNativeFromProjectNodeModules
84+ }
85+
86+ def reactNativeFromNodeModulesWithReanimated = file(" ${ projectDir} /../../react-native" )
87+ if (reactNativeFromNodeModulesWithReanimated. exists()) {
88+ return reactNativeFromNodeModulesWithReanimated
89+ }
90+
91+ throw new GradleException (
92+ " [Reanimated] Unable to resolve react-native location in node_modules. You should project extension property (in `app/build.gradle`) `REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
93+ )
94+ }
95+
96+ def getReanimatedMajorVersion () {
97+ def (major, minor, patch) = getReanimatedVersion(). tokenize(' .' )
98+ return major. toInteger()
99+ }
100+
101+ def toPlatformFileString (String path ) {
102+ if (Os . isFamily(Os . FAMILY_WINDOWS )) {
103+ path = path. replace(File . separatorChar, ' /' as char )
104+ }
105+ return path
106+ }
107+
108+ def reactNativeRootDir = resolveReactNativeDirectory()
43109
44110android {
45- compileSdkVersion safeExtGet(' XlogJsi_compileSdkVersion' , 29 )
111+ ndkVersion rootProject. ext. ndkVersion
112+ compileSdkVersion safeExtGet(' compileSdkVersion' , 34 )
113+ buildFeatures {
114+ prefab true
115+ }
46116 defaultConfig {
47- minSdkVersion safeExtGet(' XlogJsi_minSdkVersion ' , 16 )
48- targetSdkVersion safeExtGet(' XlogJsi_targetSdkVersion ' , 29 )
117+ minSdkVersion safeExtGet(' minSdkVersion ' , 16 )
118+ targetSdkVersion safeExtGet(' targetSdkVersion ' , 34 )
49119 versionCode 1
50120 versionName " 1.0"
51121
@@ -54,8 +124,8 @@ android {
54124 cppFlags " -O2 -frtti -fexceptions -Wall -fstack-protector-all"
55125 abiFilters ' armeabi-v7a' , ' arm64-v8a' // xlog does not support x86 and x86_64
56126 arguments ' -DANDROID_STL=c++_shared' ,
57- " -DNODE_MODULES_DIR=${ nodeModules} " ,
58- " -DBUILD_DIR=${ buildDir} "
127+ " -DNODE_MODULES_DIR=${ nodeModules} " ,
128+ " -DBUILD_DIR=${ buildDir} "
59129 }
60130 }
61131
@@ -86,42 +156,60 @@ android {
86156}
87157
88158repositories {
159+ mavenCentral()
89160 mavenLocal()
90161 maven {
91162 // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
92- url(" $rootDir /../node_modules/react-native/android" )
163+ url " $reactNativeRootDir /android"
164+ }
165+ maven {
166+ // Android JSC is installed from npm
167+ url " $reactNativeRootDir /../jsc-android/dist"
93168 }
94169 google()
95- mavenCentral()
96170}
97171
98172configurations {
99- cmake_depends
173+ cmake_depends
100174}
101175
102176dependencies {
103- // noinspection GradleDynamicVersion
104- implementation " com.facebook.react:react-native:+" // From node_modules
105- api " com.tencent.mars:mars-xlog:1.2.6"
106- cmake_depends " com.tencent.mars:mars-xlog:1.2.6"
177+ implementation " com.facebook.react:react-android" // version substituted by RNGP
178+ implementation " com.facebook.react:hermes-android" // version substituted by RNGP
179+ api " com.tencent.mars:mars-xlog:1.2.6"
180+ cmake_depends " com.tencent.mars:mars-xlog:1.2.6"
181+ }
182+
183+ tasks. whenTaskAdded { task ->
184+ if (task. name. contains(" configureCMakeDebug" )) {
185+ rootProject. getTasksByName(" packageReactNdkDebugLibs" , true ). forEach {
186+ task. dependsOn(it)
187+ }
188+ }
189+ // We want to add a dependency for both configureCMakeRelease and configureCMakeRelWithDebInfo
190+ if (task. name. contains(" configureCMakeRel" )) {
191+ rootProject. getTasksByName(" packageReactNdkReleaseLibs" , true ). forEach {
192+ task. dependsOn(it)
193+ }
194+ }
107195}
108196
109197// 作用是build的时候把 mars-xlog 包里面的 so文件拷贝到 src/main/jniLibs 文件夹
110- task resolveDependencies {
111- project. configurations. each { configuration ->
112- if (" cmake_depends" . equalsIgnoreCase(configuration. name)) {
113- def lib = configuration. resolve()[0 ]
114- copy {
115- from zipTree(lib)
116- into " ${ project.buildDir} /unzipXlog/"
117- include " jni/**/*.so"
118- }
119- copy {
120- from zipTree(" ${ nodeModules} /react-native/android/com/facebook/react/react-native/${ REACT_NATIVE_VERSION_NAME} /react-native-${ REACT_NATIVE_VERSION_NAME} -release.aar" )
121- into " ${ project.buildDir} /unzipReactNative/"
122- include " jni/**/*.so"
123- }
124- }
125- }
198+ tasks . register( ' resolveDependencies' ) {
199+ project. configurations. each { configuration ->
200+ if (" cmake_depends" . equalsIgnoreCase(configuration. name)) {
201+ def lib = configuration. resolve()[0 ]
202+ copy {
203+ from zipTree(lib)
204+ into " ${ project.buildDir} /unzipXlog/"
205+ include " jni/**/*.so"
206+ }
207+ // copy {
208+ // from zipTree("${nodeModules}/react-native/android/com/facebook/react/react-native/${REACT_NATIVE_VERSION_NAME}/react-native-${REACT_NATIVE_VERSION_NAME}-release.aar")
209+ // into "${project.buildDir}/unzipReactNative/"
210+ // include "jni/**/*.so"
211+ // }
212+ }
213+ }
126214}
127215build. dependsOn resolveDependencies
0 commit comments