@@ -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 : isTurboModuleEnabled(rootDir),
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,57 @@ 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-${ project.ext.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 packageReactNdkDebugLibs = tasks. register(" packageReactNdkDebugLibs" , Copy ) {
141+ dependsOn(" :ReactAndroid:packageReactNdkDebugLibsForBuck" )
142+ from(" ${ reactAndroidProjectDir} /src/main/jni/prebuilt/lib" )
143+ into(" ${ buildDir} /react-ndk/exported" )
144+ }
145+ def packageReactNdkReleaseLibs = tasks. register(" packageReactNdkReleaseLibs" , Copy ) {
146+ dependsOn(" :ReactAndroid:packageReactNdkReleaseLibsForBuck" )
147+ from(" ${ reactAndroidProjectDir} /src/main/jni/prebuilt/lib" )
148+ into(" ${ buildDir} /react-ndk/exported" )
149+ }
150+
151+ afterEvaluate {
152+ preBuild. dependsOn(" generateCodegenArtifactsFromSchema" )
153+ preDebugBuild. dependsOn(packageReactNdkDebugLibs)
154+ preReleaseBuild. dependsOn(packageReactNdkReleaseLibs)
155+
156+ // Due to a bug in AGP, we have to explicitly set a dependency
157+ // between configureNdkBuild* tasks and the preBuild tasks. This can
158+ // be removed once this issue is resolved:
159+ // https://issuetracker.google.com/issues/207403732
160+ configureNdkBuildRelease. dependsOn(preReleaseBuild)
161+ configureNdkBuildDebug. dependsOn(preDebugBuild)
162+ }
102163 }
103164
104165 lintOptions {
@@ -211,3 +272,16 @@ dependencies {
211272 }
212273 }
213274}
275+
276+ if (project. ext. react. enableTurboModule) {
277+ configurations. all {
278+ resolutionStrategy. dependencySubstitution {
279+ substitute(module(" com.facebook.react:react-native" ))
280+ .using(project(" :ReactAndroid" ))
281+ .because(" On New Architecture we are building React Native from source" )
282+ substitute(module(" com.facebook.react:hermes-engine" ))
283+ .using(project(" :ReactAndroid:hermes-engine" ))
284+ .because(" On New Architecture we are building Hermes from source" )
285+ }
286+ }
287+ }
0 commit comments