@@ -2,6 +2,8 @@ apply plugin: "com.android.application"
22apply plugin : ' kotlin-android'
33apply plugin : ' kotlinx-serialization'
44
5+ import com.android.build.OutputFile
6+
57Properties props = new Properties ()
68props. load(new FileInputStream (" $project . rootDir /../version.properties" ))
79props. each { prop ->
@@ -101,7 +103,7 @@ apply from: "../../node_modules/react-native/react.gradle"
101103 * Upload all the APKs to the Play Store and people will download
102104 * the correct one based on the CPU architecture of their device.
103105 */
104- def enableSeparateBuildPerCPUArchitecture = true
106+ def enableSeparateBuildPerCPUArchitecture = false
105107
106108/**
107109 * Run Proguard to shrink the Java bytecode in release builds.
@@ -131,7 +133,10 @@ def useIntlJsc = true
131133 */
132134def enableHermes = true ;
133135
134- def nativeArchitectures = project. getProperties(). get(" reactNativeDebugArchitectures" )
136+ def reactNativeArchitectures () {
137+ def value = project. getProperties(). get(" reactNativeArchitectures" )
138+ return value ? value. split(" ," ) : [" armeabi-v7a" , " x86" , " x86_64" , " arm64-v8a" ]
139+ }
135140
136141android {
137142 ndkVersion rootProject. ext. ndkVersion
@@ -144,6 +149,7 @@ android {
144149 targetSdkVersion rootProject. ext. targetSdkVersion
145150 versionCode project. ext. get(" versionCode" )
146151 versionName project. ext. get(" versionName" )
152+ buildConfigField " boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , isNewArchitectureEnabled(). toString()
147153 multiDexEnabled true
148154 vectorDrawables. useSupportLibrary = true
149155 }
@@ -157,7 +163,7 @@ android {
157163 reset()
158164 enable enableSeparateBuildPerCPUArchitecture
159165 universalApk false // If true, also generate a universal APK
160- include " armeabi-v7a " , " arm64-v8a " , " x86_64 " , " x86 "
166+ include ( * reactNativeArchitectures())
161167 }
162168 }
163169 /* signingConfigs {
@@ -184,11 +190,12 @@ android {
184190 buildTypes {
185191 debug {
186192 // signingConfig signingConfigs.debug
187- if (nativeArchitectures) {
188- ndk {
189- abiFilters nativeArchitectures. split(' ,' )
190- }
193+ // if (nativeArchitectures) {
194+ ndk {
195+ // abiFilters nativeArchitectures.split(',')
196+ abiFilters ( * reactNativeArchitectures())
191197 }
198+ // }
192199 proguardFiles getDefaultProguardFile(" proguard-android.txt" ), " proguard-rules.pro"
193200 }
194201 release {
@@ -209,7 +216,7 @@ android {
209216 // https://developer.android.com/studio/build/configure-apk-splits.html
210217 // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
211218 def versionCodes = [" armeabi-v7a" : 1 , " arm64-v8a" : 3 , " x86" : 2 , " x86_64" : 4 ]
212- def abi = output. getFilter(com.android.build. OutputFile. ABI )
219+ def abi = output. getFilter(OutputFile . ABI )
213220 if (abi != null && defaultConfig. versionCode != null ) { // null for the universal-debug, universal-release variants
214221 output. versionCodeOverride =
215222 defaultConfig. versionCode * 1000 + versionCodes. get(abi)
@@ -222,7 +229,8 @@ android {
222229
223230dependencies {
224231 implementation fileTree(dir : " libs" , include : [" *.jar" ])
225- implementation " com.facebook.react:react-native:0.66.3" // From node_modules
232+ implementation " com.facebook.react:react-native:+" // From node_modules
233+ // implementation project(':ReactAndroid')
226234
227235 implementation " androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
228236 implementation project(' :react-native-splash-screen' )
@@ -233,6 +241,9 @@ dependencies {
233241 def hermesPath = " ../../node_modules/hermes-engine/android/" ;
234242 debugImplementation files(hermesPath + " hermes-debug.aar" )
235243 releaseImplementation files(hermesPath + " hermes-release.aar" )
244+ /* implementation("com.facebook.react:hermes-engine:+") { // From node_modules
245+ exclude group:'com.facebook.fbjni'
246+ }*/
236247 } else {
237248 implementation jscFlavor
238249 }
@@ -274,6 +285,22 @@ configurations {
274285 compile. exclude group : " junit" , module : " junit"
275286}
276287
288+ if (isNewArchitectureEnabled()) {
289+ // If new architecture is enabled, we let you build RN from source
290+ // Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
291+ // This will be applied to all the imported transtitive dependency.
292+ configurations. all {
293+ resolutionStrategy. dependencySubstitution {
294+ substitute(module(" com.facebook.react:react-native" ))
295+ .using(project(" :ReactAndroid" ))
296+ .because(" On New Architecture we're building React Native from source" )
297+ substitute(module(" com.facebook.react:hermes-engine" ))
298+ .using(project(" :ReactAndroid:hermes-engine" ))
299+ .because(" On New Architecture we're building Hermes from source" )
300+ }
301+ }
302+ }
303+
277304// Run this once to be able to run the application with BUCK
278305// puts all compile dependencies into folder libs for BUCK to use
279306task copyDownloadableDepsToLibs (type : Copy ) {
@@ -283,3 +310,11 @@ task copyDownloadableDepsToLibs(type: Copy) {
283310
284311apply from : file(" ../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle" ); applyNativeModulesAppBuildGradle(project)
285312apply from : " ../../node_modules/react-native-vector-icons/fonts.gradle"
313+
314+ def isNewArchitectureEnabled () {
315+ // To opt-in for the New Architecture, you can either:
316+ // - Set `newArchEnabled` to true inside the `gradle.properties` file
317+ // - Invoke gradle with `-newArchEnabled=true`
318+ // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
319+ return project. hasProperty(" newArchEnabled" ) && project. newArchEnabled == " true"
320+ }
0 commit comments