@@ -6,8 +6,11 @@ buildscript {
66
77plugins {
88 id(" com.android.application" )
9- id(" kotlin-android" )
10- id(" kotlin-kapt" )
9+ id(" org.jetbrains.kotlin.android" ) version " ${ kotlinVersion} "
10+ id(" org.jetbrains.kotlin.kapt" ) version " ${ kotlinVersion} "
11+
12+ // TODO: This is only available on react-native 0.68+
13+ // id("com.facebook.react")
1114}
1215
1316// `react-native run-android` is hard-coded to look for the output APK at a very
@@ -50,11 +53,12 @@ apply(from: "${projectDir}/../../test-app.gradle")
5053applyTestAppModule(project)
5154
5255project. ext. react = [
53- appName : getAppName(),
54- applicationId : getApplicationId(),
55- enableFabric : isFabricEnabled(rootDir),
56- enableFlipper : getFlipperVersion(rootDir),
57- enableHermes : true ,
56+ appName : getAppName(),
57+ applicationId : getApplicationId(),
58+ enableFabric : isFabricEnabled(rootDir),
59+ enableFlipper : getFlipperVersion(rootDir),
60+ enableHermes : true ,
61+ enableTurboModule : false ,
5862]
5963
6064project. ext. signingConfigs = getSigningConfigs()
@@ -69,14 +73,20 @@ android {
6973
7074 // TODO: Remove this block when minSdkVersion >= 24. See
7175 // https://stackoverflow.com/q/53402639 for details.
72- compileOptions {
73- sourceCompatibility JavaVersion . VERSION_1_8
74- targetCompatibility JavaVersion . VERSION_1_8
76+ if (getReactNativeVersionNumber(rootDir) < 6900 ) {
77+ compileOptions {
78+ sourceCompatibility(JavaVersion . VERSION_1_8 )
79+ targetCompatibility(JavaVersion . VERSION_1_8 )
80+ }
7581 }
7682
7783 kotlinOptions {
7884 allWarningsAsErrors = true
79- jvmTarget = JavaVersion . VERSION_1_8
85+ if (getReactNativeVersionNumber(rootDir) < 6900 ) {
86+ jvmTarget = JavaVersion . VERSION_1_8
87+ } else {
88+ jvmTarget = JavaVersion . VERSION_11
89+ }
8090 }
8191
8292 defaultConfig {
@@ -99,6 +109,51 @@ android {
99109 resValue " string" , " app_name" , project. ext. react. appName
100110
101111 testInstrumentationRunner " androidx.test.runner.AndroidJUnitRunner"
112+
113+ if (project. ext. react. enableTurboModule) {
114+ externalNativeBuild {
115+ ndkBuild {
116+ arguments " APP_PLATFORM=android-${ minSdkVersion} " ,
117+ " APP_STL=c++_shared" ,
118+ " NDK_TOOLCHAIN_VERSION=clang" ,
119+ " GENERATED_SRC_DIR=${ buildDir} /generated/source" ,
120+ " NODE_MODULES_DIR=${ reactNativeDir} /.." ,
121+ " PROJECT_BUILD_DIR=${ buildDir} " ,
122+ " REACT_ANDROID_DIR=${ reactNativeDir} /ReactAndroid" ,
123+ " REACT_ANDROID_BUILD_DIR=${ reactNativeDir} /ReactAndroid/build"
124+ cFlags " -Wall" , " -Werror" , " -frtti" , " -fexceptions" , " -DWITH_INSPECTOR=1"
125+ cppFlags " -std=c++17"
126+ targets " reacttestapp_appmodules"
127+ }
128+ }
129+ }
130+ }
131+
132+ if (project. ext. react. enableTurboModule) {
133+ externalNativeBuild {
134+ ndkBuild {
135+ path " ${ projectDir} /src/main/jni/Android.mk"
136+ }
137+ }
138+
139+ def reactAndroidProjectDir = project(" :ReactAndroid" ). projectDir
140+ def packageReactNdkLibs = tasks. register(" packageReactNdkLibs" , Copy ) {
141+ dependsOn(" :ReactAndroid:packageReactNdkLibsForBuck" )
142+ dependsOn(" generateCodegenArtifactsFromSchema" )
143+ from(" ${ reactAndroidProjectDir} /src/main/jni/prebuilt/lib" )
144+ into(" ${ buildDir} /react-ndk/exported" )
145+ }
146+
147+ afterEvaluate {
148+ preBuild. dependsOn(packageReactNdkLibs)
149+ configureNdkBuildDebug. dependsOn(preBuild)
150+ configureNdkBuildRelease. dependsOn(preBuild)
151+ }
152+
153+ packagingOptions {
154+ pickFirst(" **/libhermes.so" )
155+ pickFirst(" **/libjsc.so" )
156+ }
102157 }
103158
104159 lintOptions {
@@ -211,3 +266,16 @@ dependencies {
211266 }
212267 }
213268}
269+
270+ if (project. ext. react. enableTurboModule) {
271+ configurations. all {
272+ resolutionStrategy. dependencySubstitution {
273+ substitute(module(" com.facebook.react:react-native" ))
274+ .using(project(" :ReactAndroid" ))
275+ .because(" On New Architecture we are building React Native from source" )
276+ substitute(module(" com.facebook.react:hermes-engine" ))
277+ .using(project(" :ReactAndroid:hermes-engine" ))
278+ .because(" On New Architecture we are building Hermes from source" )
279+ }
280+ }
281+ }
0 commit comments