@@ -27,6 +27,31 @@ apply plugin: "com.android.library"
27
27
apply plugin : " kotlin-android"
28
28
< % } -% >
29
29
30
+ < % if (project. view && (project. arch === " new" || project. arch === " mixed" )) { -% >
31
+ import groovy.json.JsonSlurper
32
+
33
+ // https://github.com/callstack/react-native-builder-bob/discussions/359
34
+ def registrationCompat = {
35
+ def reactNativeManifest = file(" $projectDir /../node_modules/react-native/package.json" ). exists()
36
+ ? file(" $projectDir /../node_modules/react-native/package.json" ) // developer mode, to run example app
37
+ : file(" $projectDir /../../react-native/package.json" )
38
+ def reactNativeVersion = new JsonSlurper (). parseText(reactNativeManifest. text). version as String
39
+ // Fabric was introduced at [email protected] , full CMake support were introduced at [email protected]
40
+ // Use Android.mk for compatibility with [email protected] /0.69
41
+ reactNativeVersion. matches(' (0.68.*|0.69.*)' )
42
+ }()
43
+
44
+ def codegenViewLibraryName = " <%- project.name + 'View' -%>"
45
+ def codegenViewModuleName = {
46
+ // Autolink for Fabric uses codegenConfig.name in package.json since [email protected]
47
+ // Use codegenViewLibraryName for compatibility with [email protected] /0.69
48
+ def libraryManifestJson = new JsonSlurper (). parseText(file(" $projectDir /../package.json" ). text)
49
+ registrationCompat ? codegenViewLibraryName : libraryManifestJson. codegenConfig. name
50
+ }()
51
+ < % } -% >
52
+
53
+ def appProject = rootProject. allprojects. find { it. plugins. hasPlugin(' com.android.application' ) }
54
+
30
55
if (isNewArchitectureEnabled()) {
31
56
apply plugin : " com.facebook.react"
32
57
}
@@ -40,7 +65,7 @@ def getExtOrIntegerDefault(name) {
40
65
}
41
66
42
67
android {
43
- < % if (project. cpp) { -% >
68
+ < % if (project. cpp || (project . view && (project . arch === " new " || project . arch === " mixed " )) ) { -% >
44
69
ndkVersion getExtOrDefault(" ndkVersion" )
45
70
< % } -% >
46
71
compileSdkVersion getExtOrIntegerDefault(" compileSdkVersion" )
@@ -49,13 +74,35 @@ android {
49
74
minSdkVersion getExtOrIntegerDefault(" minSdkVersion" )
50
75
targetSdkVersion getExtOrIntegerDefault(" targetSdkVersion" )
51
76
buildConfigField " boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , isNewArchitectureEnabled(). toString()
77
+ < % if (project. view && (project. arch === " new" || project. arch === " mixed" )) { -% >
78
+ buildConfigField " String" , " CODEGEN_MODULE_REGISTRATION" , (isNewArchitectureEnabled() && registrationCompat ? " \" ${ codegenViewModuleName} _registration\" " : " null" )
79
+ < % } -% >
52
80
< % if (project. cpp) { -% >
53
81
externalNativeBuild {
54
82
cmake {
55
83
cppFlags " -O2 -frtti -fexceptions -Wall -fstack-protector-all"
56
84
abiFilters " x86" , " x86_64" , " armeabi-v7a" , " arm64-v8a"
57
85
}
58
86
}
87
+ < % } else if (project. view && (project. arch === " new" || project. arch === " mixed" )) { -% >
88
+ if (isNewArchitectureEnabled() && registrationCompat) {
89
+ def reactAndroidProject = project(' :ReactAndroid' )
90
+ externalNativeBuild {
91
+ ndkBuild {
92
+ arguments " APP_PLATFORM=android-21" ,
93
+ " APP_STL=c++_shared" ,
94
+ " NDK_TOOLCHAIN_VERSION=clang" ,
95
+ " GENERATED_SRC_DIR=$buildDir /generated/source" , // for react_codegen_* in this library's codegen/jni
96
+ " PROJECT_BUILD_DIR=${ appProject.buildDir} " , // for REACT_NDK_EXPORT_DIR in ReactAndroid's Android-prebuilt.mk
97
+ " REACT_ANDROID_DIR=${ reactAndroidProject.projectDir} " ,
98
+ " REACT_ANDROID_BUILD_DIR=${ reactAndroidProject.buildDir} " ,
99
+ " CODEGEN_MODULE_NAME=$codegenViewModuleName "
100
+ cFlags " -Wall" , " -Werror" , " -fexceptions" , " -frtti" , " -DWITH_INSPECTOR=1"
101
+ cppFlags " -std=c++17"
102
+ targets " ${ codegenViewModuleName} _registration"
103
+ }
104
+ }
105
+ }
59
106
< % } -% >
60
107
}
61
108
< % if (project. cpp) { -% >
@@ -64,6 +111,15 @@ android {
64
111
path " CMakeLists.txt"
65
112
}
66
113
}
114
+ < % } else if (project. view && (project. arch === " new" || project. arch === " mixed" )) { -% >
115
+ if (isNewArchitectureEnabled() && registrationCompat) {
116
+ // We configure the NDK build only if you decide to opt-in for the New Architecture.
117
+ externalNativeBuild {
118
+ ndkBuild {
119
+ path " Android.mk"
120
+ }
121
+ }
122
+ }
67
123
< % } -% >
68
124
buildTypes {
69
125
release {
@@ -130,7 +186,11 @@ dependencies {
130
186
if (isNewArchitectureEnabled()) {
131
187
react {
132
188
jsRootDir = file(" ../src/" )
189
+ < % if (project. view && (project. arch === " new" || project. arch === " mixed" )) { % >
190
+ libraryName = codegenViewLibraryName
191
+ < % } else { -% >
133
192
libraryName = " <%- project.view ? project.name + 'View' : project.name -%>"
193
+ < % } -% >
134
194
codegenJavaPackageName = " com.<%- project.package -%>"
135
195
}
136
196
}
0 commit comments