@@ -127,25 +127,77 @@ dependencies {
127
127
implementation " com.facebook.react:react-native:+"
128
128
129
129
// Tensorflow Lite .aar (includes C API via prefabs)
130
- implementation " com.google.ai.edge.litert:litert:1.0.1 "
131
- extractSO(" com.google.ai.edge.litert:litert:1.0.1 " )
132
- extractHeaders(" com.google.ai.edge.litert:litert:1.0.1 " )
130
+ implementation " com.google.ai.edge.litert:litert:1.4.0 "
131
+ extractSO(" com.google.ai.edge.litert:litert:1.4.0 " )
132
+ extractHeaders(" com.google.ai.edge.litert:litert:1.4.0 " )
133
133
134
134
// Tensorflow Lite GPU delegate
135
- implementation " com.google.ai.edge.litert:litert-gpu:1.0.1 "
136
- extractSO(" com.google.ai.edge.litert:litert-gpu:1.0.1 " )
137
- extractHeaders(" com.google.ai.edge.litert:litert-gpu:1.0.1 " )
135
+ implementation " com.google.ai.edge.litert:litert-gpu:1.4.0 "
136
+ extractSO(" com.google.ai.edge.litert:litert-gpu:1.4.0 " )
137
+ extractHeaders(" com.google.ai.edge.litert:litert-gpu:1.4.0 " )
138
138
}
139
139
140
+ /**
141
+ * Custom task to delete the 'src/main/cpp/lib/headers' directory.
142
+ */
143
+ task cleanEmptyDirectories (type : Delete ) {
144
+ // Specify the directory to be deleted.
145
+ delete ' src/main/cpp/lib/headers'
146
+ delete ' src/main/cpp/lib/res'
147
+ }
148
+
149
+ /**
150
+ * Custom task to copy C++ header files (.h) from AAR packages.
151
+ * This task iterates through each AAR file in the 'extractHeaders' configuration.
152
+ * For each AAR, it extracts and copies header files to specific destinations:
153
+ * - Headers found under 'external/org_tensorflow/tensorflow/' inside the AAR
154
+ * are copied to 'src/main/cpp/lib/tensorflow/'.
155
+ * - All other headers are copied to 'src/main/cpp/lib/{packageName}/', where
156
+ * '{packageName}' is derived from the AAR's filename.
157
+ */
140
158
task extractAARHeaders {
159
+
160
+ finalizedBy cleanEmptyDirectories
161
+
141
162
doLast {
142
- configurations. extractHeaders. files. each {
143
- def file = it. absoluteFile
144
- def packageName = file. name. tokenize(' -' )[0 ]
163
+ // Iterate over each AAR file defined in the 'extractHeaders' configuration
164
+ configurations. extractHeaders. files. each { aarFile ->
165
+ // Extract the package name from the AAR filename (e.g., 'my-lib-1.0.aar' -> 'my-lib')
166
+ def packageName = aarFile. name. tokenize(' -' )[0 ]
167
+
168
+ // Create a copy operation for the current AAR
145
169
copy {
146
- from zipTree(file)
147
- into " src/main/cpp/lib/$packageName /"
148
- include " **/*.h"
170
+ // Source: the contents of the AAR treated as a zip archive
171
+ from zipTree(aarFile)
172
+ // Base destination directory for all copied files from this AAR.
173
+ // The 'eachFile' closure will then modify the relative path within this base.
174
+ into " src/main/cpp/lib/"
175
+ include " **/*.h" // Ensure only header files are included
176
+
177
+ // Process each file found within the AAR's zipTree
178
+ eachFile { fileCopyDetails ->
179
+ // Check if the current file is a C++ header file (.h)
180
+ if (fileCopyDetails. name. endsWith(" .h" )) {
181
+ // Get the original relative path of the file within the AAR
182
+ def originalRelativePath = fileCopyDetails. relativePath. toString()
183
+
184
+ // Check if the header belongs to the special TensorFlow path
185
+ if (originalRelativePath. startsWith(" headers/external/org_tensorflow/tensorflow/" )) {
186
+ // For TensorFlow headers, set the new relative path to start with 'tensorflow/'
187
+ // and remove the 'external/org_tensorflow/' prefix.
188
+ def newRelativePath = packageName + " /headers/" + originalRelativePath. substring(" headers/external/org_tensorflow/" . length())
189
+ fileCopyDetails. relativePath = new RelativePath (true , newRelativePath. split(' /' ))
190
+ } else {
191
+ // For all other headers, set the new relative path to include the 'packageName'
192
+ // derived from the AAR filename, followed by its original path.
193
+ def newRelativePath = packageName + " /" + originalRelativePath
194
+ fileCopyDetails. relativePath = new RelativePath (true , newRelativePath. split(' /' ))
195
+ }
196
+ } else {
197
+ // If the file is not a .h file, exclude it from the copy operation
198
+ fileCopyDetails. exclude()
199
+ }
200
+ }
149
201
}
150
202
}
151
203
}
0 commit comments