@@ -54,6 +54,30 @@ if(shouldUseNameSpace){
54
54
manifestContent. replaceAll(" " , " " )
55
55
manifestOutFile. write(manifestContent)
56
56
57
+ import groovy.json.JsonSlurper
58
+
59
+ // https://github.com/callstack/react-native-builder-bob/discussions/359
60
+ def registrationCompat = {
61
+ def reactAndroidProject = rootProject. allprojects. find { it. name == ' ReactAndroid' }
62
+ if (reactAndroidProject == null ) return false
63
+
64
+ def reactNativeManifest = file(" ${ reactAndroidProject.projectDir} /../package.json" )
65
+ def reactNativeVersion = new JsonSlurper (). parseText(reactNativeManifest. text). version as String
66
+ // Fabric was introduced at [email protected] , full CMake support were introduced at [email protected]
67
+ // Use Android.mk for compatibility with [email protected] /0.69
68
+ reactNativeVersion. matches(' (0.68.*|0.69.*)' )
69
+ }()
70
+
71
+ def codegenViewLibraryName = " RNCViewPager"
72
+ def codegenViewModuleName = {
73
+ // Autolink for Fabric uses codegenConfig.name in package.json since [email protected]
74
+ // Use codegenViewLibraryName for compatibility with [email protected] /0.69
75
+ def libraryManifestJson = new JsonSlurper (). parseText(file(" $projectDir /../package.json" ). text)
76
+ registrationCompat ? codegenViewLibraryName : libraryManifestJson. codegenConfig. name
77
+ }()
78
+
79
+ def appProject = rootProject. allprojects. find { it. plugins. hasPlugin(' com.android.application' ) }
80
+
57
81
android {
58
82
compileSdkVersion getExtOrIntegerDefault(' compileSdkVersion' )
59
83
if (shouldUseNameSpace){
@@ -63,7 +87,38 @@ android {
63
87
minSdkVersion getExtOrIntegerDefault(' minSdkVersion' )
64
88
targetSdkVersion getExtOrIntegerDefault(' targetSdkVersion' )
65
89
buildConfigField " boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , isNewArchitectureEnabled(). toString()
90
+
91
+ buildConfigField " String" , " CODEGEN_MODULE_REGISTRATION" , (isNewArchitectureEnabled() && registrationCompat ? " \" ${ codegenViewModuleName} _registration\" " : " null" )
92
+
93
+ if (isNewArchitectureEnabled() && registrationCompat) {
94
+ def reactAndroidProject = project(' :ReactAndroid' )
95
+ externalNativeBuild {
96
+ ndkBuild {
97
+ arguments " APP_PLATFORM=android-21" ,
98
+ " APP_STL=c++_shared" ,
99
+ " NDK_TOOLCHAIN_VERSION=clang" ,
100
+ " GENERATED_SRC_DIR=$buildDir /generated/source" , // for react_codegen_* in this library's codegen/jni
101
+ " PROJECT_BUILD_DIR=${ appProject.buildDir} " , // for REACT_NDK_EXPORT_DIR in ReactAndroid's Android-prebuilt.mk
102
+ " REACT_ANDROID_DIR=${ reactAndroidProject.projectDir} " ,
103
+ " REACT_ANDROID_BUILD_DIR=${ reactAndroidProject.buildDir} " ,
104
+ " CODEGEN_MODULE_NAME=$codegenViewModuleName "
105
+ cFlags " -Wall" , " -Werror" , " -fexceptions" , " -frtti" , " -DWITH_INSPECTOR=1"
106
+ cppFlags " -std=c++17"
107
+ targets " ${ codegenViewModuleName} _registration"
108
+ }
109
+ }
110
+ }
66
111
}
112
+
113
+ if (isNewArchitectureEnabled() && registrationCompat) {
114
+ // We configure the NDK build only if you decide to opt-in for the New Architecture.
115
+ externalNativeBuild {
116
+ ndkBuild {
117
+ path " Android.mk"
118
+ }
119
+ }
120
+ }
121
+
67
122
buildTypes {
68
123
release {
69
124
minifyEnabled false
@@ -174,7 +229,7 @@ dependencies {
174
229
if (isNewArchitectureEnabled()) {
175
230
react {
176
231
jsRootDir = file(" ../src" )
177
- libraryName = " RNCViewPager "
232
+ libraryName = codegenViewLibraryName
178
233
codegenJavaPackageName = " com.reactnativepagerview"
179
234
}
180
235
}
0 commit comments