@@ -67,7 +67,6 @@ android {
6767 viewBinding true
6868 }
6969 ndkVersion ' 21.4.7075529'
70-
7170}
7271
7372dependencies {
@@ -77,11 +76,6 @@ dependencies {
7776
7877ext. libkiwix_base_url = ' https://download.kiwix.org/nightly'
7978ext. libzim_base_url = ' https://download.openzim.org/nightly'
80- // change this date to get latest libzim .so and header files
81- ext. nightly_date_for_libkiwix = project. properties[" nightly_date_for_libkiwix" ] ?: " "
82- ext. nightly_date_for_libkiwix_linux = project. properties[" nightly_date_for_libkiwix_linux" ] ?: " "
83- ext. nightly_date_for_libzim = project. properties[" nightly_date_for_libzim" ] ?: " "
84- ext. nightly_date_for_libzim_linux = project. properties[" nightly_date_for_libzim_linux" ] ?: " "
8579
8680ext. libkiwix_version = project. properties[" libkiwix_version" ] ?: " "
8781ext. libzim_version = project. properties[" libzim_version" ] ?: " "
@@ -98,14 +92,6 @@ task downloadLibzimSoAndHeaderFiles(type: Download) {
9892 overwrite true
9993}
10094
101- task checkCurrentLibzimDate () {
102- project. ext. set(" nightly_date_for_libzim" , getDateFromPath(buildDir. path, " libzim_android-arm64-" ))
103- }
104-
105- task checkCurrentLinuxLibzimDate () {
106- project. ext. set(" nightly_date_for_libzim_linux" , getDateFromPath(buildDir. path, " libzim_linux-x86_64-" ))
107- }
108-
10995task unzipLibzim (type : Copy ) {
11096 // unzip android arm
11197 from tarTree(buildDir. path + " /libzim_android-arm.tar.gz" )
@@ -124,41 +110,47 @@ task unzipLibzim(type: Copy) {
124110 into buildDir
125111}
126112
127- task copyLibzimHeaderFiles (type : Copy ) {
128- // copying header file
129- from buildDir. path + " /libzim_android-arm-" + nightly_date_for_libzim + ' /include/'
130- into buildDir. path + " /include/libzim/"
113+ task renameLibzimFolders () {
114+ renameFolders(buildDir. path," libzim_" )
131115}
132116
133- task copyLibzimAndroidArm (type : Copy ) {
134- // copying android_arm so file
135- from buildDir. path + " /libzim_android-arm-" + nightly_date_for_libzim + ' /lib/arm-linux-androideabi/'
136- into buildDir. path + " /jniLibs/armeabi-v7a/libzim/"
137- }
117+ task copyLibzimHeaderAndSoFiles (type : Copy ) {
118+ copy {
119+ // copying header file
120+ from buildDir. path + " /libzim_android-arm/include/"
121+ into buildDir. path + " /include/libzim/"
122+ }
138123
139- task copyLibzimAndroidArm64 ( type : Copy ) {
140- // copying android_arm64 so file
141- from buildDir. path + " /libzim_android-arm64- " + nightly_date_for_libzim + ' /lib/aarch64 -linux-android/ '
142- into buildDir. path + " /jniLibs/arm64-v8a /libzim/"
143- }
124+ copy {
125+ // copying android_arm so file
126+ from buildDir. path + " /libzim_android-arm /lib/arm -linux-androideabi/ "
127+ into buildDir. path + " /jniLibs/armeabi-v7a /libzim/"
128+ }
144129
145- task copyLibzimAndroidx86 ( type : Copy ) {
146- // copying android_x86 so file
147- from buildDir. path + " /libzim_android-x86- " + nightly_date_for_libzim + ' /lib/i686 -linux-android/'
148- into buildDir. path + " /jniLibs/x86 /libzim/"
149- }
130+ copy {
131+ // copying android_arm64 so file
132+ from buildDir. path + " /libzim_android-arm64 /lib/aarch64 -linux-android/"
133+ into buildDir. path + " /jniLibs/arm64-v8a /libzim/"
134+ }
150135
151- task copyLibzimAndroidx86_64 (type : Copy ) {
152- // copying android_x86_64 so file
153- from buildDir. path + " /libzim_android-x86_64-" + nightly_date_for_libzim + ' /lib/x86_64-linux-android/'
154- into buildDir. path + " /jniLibs/x86_64/libzim/"
155- }
136+ copy {
137+ // copying android_x86 so file
138+ from buildDir. path + " /libzim_android-x86/lib/i686-linux-android/"
139+ into buildDir. path + " /jniLibs/x86/libzim/"
140+ }
141+
142+ copy {
143+ // copying android_x86_64 so file
144+ from buildDir. path + " /libzim_android-x86_64/lib/x86_64-linux-android/"
145+ into buildDir. path + " /jniLibs/x86_64/libzim/"
146+ }
156147
157- task copyLibzimLinux_x86_64 (type : Copy ) {
158- // copying linux_x86_64 so file
159- project. ext. set(" libzim_version" , getFileFromFolder(buildDir. path + " /libzim_linux-x86_64-" + nightly_date_for_libzim_linux + " /lib/x86_64-linux-gnu/" ))
160- from buildDir. path + " /libzim_linux-x86_64-" + nightly_date_for_libzim_linux + " /lib/x86_64-linux-gnu/" + libzim_version
161- into buildDir. path
148+ copy {
149+ // copying linux_x86_64 so file
150+ project. ext. set(" libzim_version" , getFileFromFolder(buildDir. path + " /libzim_linux-x86_64/lib/x86_64-linux-gnu/" ))
151+ from buildDir. path + " /libzim_linux-x86_64/lib/x86_64-linux-gnu/" + libzim_version
152+ into buildDir. path
153+ }
162154}
163155
164156task renameLibzimSoFile (type : Copy ) {
@@ -182,22 +174,20 @@ task downloadLibkiwixSoAndHeaderFiles(type: Download) {
182174 overwrite true
183175}
184176
185- task checkCurrentLibkiwixDate () {
186- project. ext. set(" nightly_date_for_libkiwix" , getDateFromPath(buildDir. path, " libkiwix_android-arm64-" ))
187- }
188-
189- task checkCurrentLinuxLibkiwixDate () {
190- project. ext. set(" nightly_date_for_libkiwix_linux" , getDateFromPath(buildDir. path, " libkiwix_linux-x86_64-" ))
177+ task renameLibkiwixFolders () {
178+ renameFolders(buildDir. path," libkiwix_" )
191179}
192180
193- static String getDateFromPath (String path , String matchesString ) {
194- File folder = new File (path)
195- if (folder. exists()) {
196- return folder. listFiles()
197- .stream()
198- .filter(f -> f. name. startsWith(matchesString))
199- .map(s -> s. name. replace(matchesString, " " ))
200- .collect(Collectors . toList())[0 ]
181+ static void renameFolders (String path , String startWith ) {
182+ File directory = new File (path)
183+ if (directory. exists() && directory. isDirectory()) {
184+ Arrays . stream(directory. listFiles())
185+ .filter(folder -> folder. isDirectory() && folder. getName(). startsWith(startWith))
186+ .forEach(file -> {
187+ String newName = file. getName(). replaceAll(" -\\ d{4}-\\ d{2}-\\ d{2}" , " " )
188+ File newFile = new File (directory, newName)
189+ file. renameTo(newFile)
190+ })
201191 }
202192}
203193
@@ -219,41 +209,43 @@ task unzipLibkiwix(type: Copy) {
219209 into buildDir
220210}
221211
222- task copyLibkiwixHeaderFiles (type : Copy ) {
223- // copying header file
224- from buildDir. path + " /libkiwix_android-arm-" + nightly_date_for_libkiwix + ' /include/kiwix/'
225- into buildDir. path + " /include/libkiwix/"
226- }
212+ task copyLibkiwixHeaderAndSoFiles (type : Copy ) {
213+ copy {
214+ // copying header file
215+ from buildDir. path + " /libkiwix_android-arm/include/kiwix/"
216+ into buildDir. path + " /include/libkiwix/"
217+ }
227218
228- task copyLibkiwixAndroidArm ( type : Copy ) {
229- // copying android_arm so file
230- from buildDir. path + " /libkiwix_android-arm- " + nightly_date_for_libkiwix + ' /lib/arm-linux-androideabi/'
231- into buildDir. path + " /jniLibs/armeabi-v7a/libkiwix/"
232- }
219+ copy {
220+ // copying android_arm so file
221+ from buildDir. path + " /libkiwix_android-arm/lib/arm-linux-androideabi/"
222+ into buildDir. path + " /jniLibs/armeabi-v7a/libkiwix/"
223+ }
233224
234- task copyLibkiwixAndroidArm64 ( type : Copy ) {
235- // copying android_arm64 so file
236- from buildDir. path + " /libkiwix_android-arm64- " + nightly_date_for_libkiwix + ' /lib/aarch64-linux-android/'
237- into buildDir. path + " /jniLibs/arm64-v8a/libkiwix/"
238- }
225+ copy {
226+ // copying android_arm64 so file
227+ from buildDir. path + " /libkiwix_android-arm64/lib/aarch64-linux-android/"
228+ into buildDir. path + " /jniLibs/arm64-v8a/libkiwix/"
229+ }
239230
240- task copyLibkiwixAndroidx86 ( type : Copy ) {
241- // copying android_x86 so file
242- from buildDir. path + " /libkiwix_android-x86- " + nightly_date_for_libkiwix + ' /lib/i686-linux-android/'
243- into buildDir. path + " /jniLibs/x86/libkiwix/"
244- }
231+ copy {
232+ // copying android_x86 so file
233+ from buildDir. path + " /libkiwix_android-x86/lib/i686-linux-android/"
234+ into buildDir. path + " /jniLibs/x86/libkiwix/"
235+ }
245236
246- task copyLibkiwixAndroidx86_64 ( type : Copy ) {
247- // copying android_x86_64 so file
248- from buildDir. path + " /libkiwix_android-x86_64- " + nightly_date_for_libkiwix + ' /lib/x86_64-linux-android/'
249- into buildDir. path + " /jniLibs/x86_64/libkiwix/"
250- }
237+ copy {
238+ // copying android_x86_64 so file
239+ from buildDir. path + " /libkiwix_android-x86_64/lib/x86_64-linux-android/"
240+ into buildDir. path + " /jniLibs/x86_64/libkiwix/"
241+ }
251242
252- task copyLibkiwixLinux_x86_64 (type : Copy ) {
253- // copying linux_x86_64 so file
254- project. ext. set(" libkiwix_version" , getFileFromFolder(buildDir. path + " /libkiwix_linux-x86_64-" + nightly_date_for_libkiwix_linux + " /lib/x86_64-linux-gnu/" ))
255- from buildDir. path + " /libkiwix_linux-x86_64-" + nightly_date_for_libkiwix_linux + " /lib/x86_64-linux-gnu/" + libkiwix_version
256- into buildDir. path
243+ copy {
244+ // copying linux_x86_64 so file
245+ project. ext. set(" libkiwix_version" , getFileFromFolder(buildDir. path + " /libkiwix_linux-x86_64/lib/x86_64-linux-gnu/" ))
246+ from buildDir. path + " /libkiwix_linux-x86_64/lib/x86_64-linux-gnu/" + libkiwix_version
247+ into buildDir. path
248+ }
257249}
258250
259251static String getFileFromFolder (String path ) {
@@ -275,15 +267,40 @@ task renameLibkiwixSoFile(type: Copy) {
275267 }
276268}
277269
278- task copyBuildKiwixSoFile (type : Copy ) {
279- // copying linux_x86_64 so file
280- from projectDir. path + " /src/test/libbuildkiwix.so"
281- into buildDir. path
270+ task testSourceJar (type : Jar ) {
271+ from android. sourceSets. test. java. srcDirs
272+ archiveName = ' test-sources.jar'
282273}
283274
284- task createCodeCoverageReport (type : Exec ) {
275+ task compileTestFile (type : JavaCompile ) {
276+ dependsOn testSourceJar
277+ source = file(' src/test/test.java' )
278+ destinationDirectory = file(' src/test/' )
279+ classpath = files(" src/test/junit-4.13.jar" , " src/test/hamcrest-core-1.4.jar" , " build/libs/test-sources.jar" )
280+ }
281+
282+ task runTests (type : JavaExec ) {
283+ workingDir(" $projectDir /src/test/" )
284+ dependsOn compileTestFile
285+ classpath = files(' src/test/' , ' src/test/java/' , ' src/test/junit-4.13.jar' , ' src/test/hamcrest-core-1.3.jar' )
286+ main = ' org.junit.runner.JUnitCore'
287+ args = [' test' ]
288+ jvmArgs = [
289+ ' -Djava.library.path=' + buildDir. path,
290+ ' -javaagent:jacoco-0.8.7/lib/jacocoagent.jar'
291+ ]
292+ }
293+
294+ task createCodeCoverageReport (type : JavaExec ) {
285295 workingDir " ${ projectDir} /src/test/"
286- commandLine ' sh' , ' -c' , " bash 'compile_and_run_test.sh' ${ buildDir} /libs/*lib*.jar $buildDir "
296+ dependsOn runTests
297+ classpath = files(' src/test/' , ' src/test/java/' , ' src/test/junit-4.13.jar' , ' src/test/hamcrest-core-1.3.jar' , ' src/test/jacoco-0.8.7/lib/*' )
298+ main = ' org.jacoco.cli.internal.Main'
299+ args = [
300+ ' report' , ' jacoco.exec' ,
301+ ' --classfiles' , ' java/org/kiwix/libkiwix/' , ' --classfiles' , ' java/org/kiwix/libzim/' ,
302+ ' --html' , ' ../../build/coverage-report' , ' --xml' , ' coverage.xml'
303+ ]
287304}
288305
289306task checkCurrentJavaVersion () {
@@ -293,9 +310,9 @@ task checkCurrentJavaVersion() {
293310}
294311
295312
296- task generateHeaderFilesFromJavaWrapper (type : Exec ) {
313+ task buildHeaders (type : Exec ) {
297314 workingDir " ${ projectDir} /src/main/java/org/kiwix/"
298- commandLine ' bash' , ' -c' , " javac -h ${ buildDir} /include/javah_generated/ -d ${ projectDir} /src/test/ ${ getLibzimFiles()} ${ getLibkiwixFiles()} "
315+ commandLine ' bash' , ' -c' , " javac -h ${ buildDir} /include/javah_generated/ -d ${ projectDir} /src/test/java/ ${ getLibzimFiles()} ${ getLibkiwixFiles()} "
299316}
300317
301318String getLibkiwixFiles () {
@@ -327,3 +344,10 @@ String getLibzimFiles() {
327344 " ${ projectDir} /src/main/java/org/kiwix/libzim/SuggestionSearch.java " +
328345 " ${ projectDir} /src/main/java/org/kiwix/libzim/ZimFileFormatException.java"
329346}
347+
348+ task buildLinuxBinding (type : Exec ) {
349+ workingDir " ${ projectDir} /src/main/cpp/"
350+ commandLine ' bash' , ' -c' , " cmake . -B ${ buildDir} && make -C ${ buildDir} "
351+ }
352+
353+ build. dependsOn buildLinuxBinding
0 commit comments