1
+ import java.nio.file.Paths
2
+
1
3
buildscript {
2
4
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
3
5
def kotlin_version = rootProject. ext. has(" kotlinVersion" ) ? rootProject. ext. get(" kotlinVersion" ) : project. properties[" FastOpencv_kotlinVersion" ]
@@ -47,6 +49,23 @@ def supportsNamespace() {
47
49
return (major == 7 && minor >= 3 ) || major >= 8
48
50
}
49
51
52
+ static def findNodeModules (baseDir ) {
53
+ def basePath = baseDir. toPath(). normalize()
54
+ // Node's module resolution algorithm searches up to the root directory,
55
+ // after which the base path will be null
56
+ while (basePath) {
57
+ def nodeModulesPath = Paths . get(basePath. toString(), " node_modules" )
58
+ def reactNativePath = Paths . get(nodeModulesPath. toString(), " react-native" )
59
+ if (nodeModulesPath. toFile(). exists() && reactNativePath. toFile(). exists()) {
60
+ return nodeModulesPath. toString()
61
+ }
62
+ basePath = basePath. getParent()
63
+ }
64
+ throw new GradleException (" react-native-fast-tflite: Failed to find node_modules/ path!" )
65
+ }
66
+
67
+ def nodeModules = findNodeModules(projectDir)
68
+
50
69
android {
51
70
if (supportsNamespace()) {
52
71
namespace " com.fastopencv"
@@ -66,13 +85,33 @@ android {
66
85
targetSdkVersion getExtOrIntegerDefault(" targetSdkVersion" )
67
86
buildConfigField " boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , isNewArchitectureEnabled(). toString()
68
87
88
+ buildFeatures {
89
+ prefab= true
90
+ }
91
+
69
92
externalNativeBuild {
70
93
cmake {
94
+ arguments " -DANDROID_STL=c++_shared" ,
95
+ " -DNODE_MODULES_DIR=${ nodeModules} "
71
96
cppFlags " -O2 -frtti -fexceptions -Wall -fstack-protector-all"
72
97
abiFilters (* reactNativeArchitectures())
73
98
}
74
99
}
75
100
}
101
+ packagingOptions {
102
+ excludes = [
103
+ " META-INF" ,
104
+ " META-INF/**" ,
105
+ " **/libc++_shared.so" ,
106
+ " **/libfbjni.so" ,
107
+ " **/libjsi.so" ,
108
+ " **/libreactnativejni.so" ,
109
+ " **/libturbomodulejsijni.so" ,
110
+ " **/libreact_nativemodule_core.so" ,
111
+ " **/libfolly_runtime.so" ,
112
+ " **/libglog.so"
113
+ ]
114
+ }
76
115
77
116
externalNativeBuild {
78
117
cmake {
@@ -127,6 +166,7 @@ dependencies {
127
166
// noinspection GradleDynamicVersion
128
167
implementation " com.facebook.react:react-native:+"
129
168
implementation " org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version "
169
+ implementation ' org.opencv:opencv:4.9.0'
130
170
}
131
171
132
172
if (isNewArchitectureEnabled()) {
0 commit comments