Skip to content

Commit 3b4ca8a

Browse files
committed
Get build scripts from Issue#19
1 parent a3a7fa5 commit 3b4ca8a

File tree

4 files changed

+429
-0
lines changed

4 files changed

+429
-0
lines changed

build.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
Green='\e[32m'
4+
NC='\033[0m' # No Color
5+
6+
cd android-libkiwixbuild/
7+
8+
printf "${Green}Check Current Java version${NC}\n"
9+
./gradlew checkCurrentJavaVersion
10+
printf "\n${Green}Done! ${NC}\n"
11+
12+
printf "${Green}Downloading libzim ${NC}\n"
13+
./gradlew downloadLibzimSoAndHeaderFiles unzipLibzim
14+
printf "\n${Green}Done! ${NC}\n"
15+
16+
hash -r
17+
18+
printf "${Green}Coping libzim header and so files ${NC}\n"
19+
./gradlew checkCurrentLibzimDate copyLibzimHeaderFiles copyLibzimAndroidArm copyLibzimAndroidArm64 copyLibzimAndroidx86 copyLibzimAndroidx86_64 copyLibzimLinux_x86_64 renameLibzimSoFile
20+
printf "\n${Green}Down! ${NC}\n"
21+
22+
printf "${Green}Downloading libkiwix ${NC}\n"
23+
./gradlew downloadLibkiwixSoAndHeaderFiles unzipLibkiwix
24+
printf "\n${Green}Done! ${NC}\n"
25+
26+
hash -r
27+
28+
printf "${Green}Coping libkiwix header and so files ${NC}\n"
29+
./gradlew checkCurrentLibkiwixDate copyLibkiwixHeaderFiles copyLibkiwixAndroidArm copyLibkiwixAndroidArm64 copyLibkiwixAndroidx86 copyLibkiwixAndroidx86_64 copyLibkiwixLinux_x86_64 renameLibkiwixSoFile
30+
printf "\n${Green}Done! ${NC}\n"
31+
32+
printf "${Green}Generating header files from java wrapper files ${NC}\n"
33+
./gradlew generateHeaderFilesFromJavaWrapper
34+
printf "\n${Green}Done! ${NC}\n"
35+
36+
hash -r

lib/src/main/build.gradle

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
import java.util.stream.Collectors
2+
3+
plugins {
4+
id 'com.android.library'
5+
id 'org.jetbrains.kotlin.android'
6+
id "de.undercouch.download"
7+
}
8+
9+
Properties properties = new Properties()
10+
if (rootProject.file("local.properties").exists()) {
11+
properties.load(rootProject.file("local.properties").newDataInputStream())
12+
}
13+
14+
ext["keyId"] = properties.getProperty("signing.keyId", System.getenv('SIGNING_KEY_ID'))
15+
ext["password"] = properties.getProperty("signing.password", System.getenv('SIGNING_PASSWORD'))
16+
ext["key"] = properties.getProperty("signing.key", System.getenv('SIGNING_KEY'))
17+
ext["ossrhUsername"] = properties.getProperty("ossrhUsername", System.getenv('OSSRH_USERNAME'))
18+
ext["ossrhPassword"] = properties.getProperty("ossrhPassword", System.getenv('OSSRH_PASSWORD'))
19+
ext["sonatypeStagingProfileId"] = properties.getProperty("sonatypeStagingProfileId", System.getenv('SONATYPE_STAGING_PROFILE_ID'))
20+
21+
ext {
22+
set("GROUP_ID", "org.kiwix.kiwixlib")
23+
set("ARTIFACT_ID", "kiwixlib")
24+
set("VERSION", "11.0.0")
25+
}
26+
27+
apply from: 'publish.gradle'
28+
android {
29+
compileSdk 32
30+
31+
defaultConfig {
32+
33+
minSdk 21
34+
targetSdk 32
35+
versionCode 1
36+
versionName "1.0"
37+
38+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
39+
externalNativeBuild {
40+
cmake {
41+
cppFlags ''
42+
arguments "-DANDROID_STL=c++_shared"
43+
}
44+
}
45+
}
46+
47+
buildTypes {
48+
release {
49+
minifyEnabled false
50+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
51+
}
52+
}
53+
compileOptions {
54+
sourceCompatibility JavaVersion.VERSION_1_8
55+
targetCompatibility JavaVersion.VERSION_1_8
56+
}
57+
kotlinOptions {
58+
jvmTarget = '1.8'
59+
}
60+
externalNativeBuild {
61+
cmake {
62+
path file('src/main/cpp/CMakeLists.txt')
63+
version '3.18.1'
64+
}
65+
}
66+
buildFeatures {
67+
viewBinding true
68+
}
69+
ndkVersion '21.4.7075529'
70+
71+
}
72+
73+
dependencies {
74+
implementation 'com.getkeepsafe.relinker:relinker:1.4.5'
75+
implementation 'androidx.core:core-ktx:1.7.0'
76+
}
77+
78+
ext.libkiwix_base_url = 'https://download.kiwix.org/nightly'
79+
ext.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_libzim = project.properties["nightly_date_for_libzim"] ?: ""
83+
84+
ext.libkiwix_version = project.properties["libkiwix_version"] ?: ""
85+
ext.libzim_version = project.properties["libzim_version"] ?: ""
86+
87+
task downloadLibzimSoAndHeaderFiles(type: Download) {
88+
src([
89+
libzim_base_url + '/libzim_android-arm.tar.gz',
90+
libzim_base_url + '/libzim_android-arm64.tar.gz',
91+
libzim_base_url + '/libzim_android-x86.tar.gz',
92+
libzim_base_url + '/libzim_android-x86_64.tar.gz',
93+
libzim_base_url + '/libzim_linux-x86_64.tar.gz'
94+
])
95+
dest buildDir
96+
overwrite true
97+
}
98+
99+
task checkCurrentLibzimDate() {
100+
project.ext.set("nightly_date_for_libzim", getDateFromPath(buildDir.path, "libzim_android-arm64-"))
101+
}
102+
103+
task unzipLibzim(type: Copy) {
104+
// unzip android arm
105+
from tarTree(buildDir.path + "/libzim_android-arm.tar.gz")
106+
into buildDir
107+
// unzip android arm64
108+
from tarTree(buildDir.path + "/libzim_android-arm64.tar.gz")
109+
into buildDir
110+
// unzip android x86
111+
from tarTree(buildDir.path + "/libzim_android-x86.tar.gz")
112+
into buildDir
113+
// unzip android x86_64
114+
from tarTree(buildDir.path + "/libzim_android-x86_64.tar.gz")
115+
into buildDir
116+
// unzip linux x86_64
117+
from tarTree(buildDir.path + "/libzim_linux-x86_64.tar.gz")
118+
into buildDir
119+
}
120+
121+
task copyLibzimHeaderFiles(type: Copy) {
122+
// copying header file
123+
from buildDir.path + "/libzim_android-arm-" + nightly_date_for_libzim + '/include/'
124+
into projectDir.path + "/src/main/cpp/include/libzim/"
125+
}
126+
127+
task copyLibzimAndroidArm(type: Copy) {
128+
// copying android_arm so file
129+
from buildDir.path + "/libzim_android-arm-" + nightly_date_for_libzim + '/lib/arm-linux-androideabi/'
130+
into projectDir.path + "/src/main/jniLibs/armeabi-v7a/libzim/"
131+
}
132+
133+
task copyLibzimAndroidArm64(type: Copy) {
134+
// copying android_arm64 so file
135+
from buildDir.path + "/libzim_android-arm64-" + nightly_date_for_libzim + '/lib/aarch64-linux-android/'
136+
into projectDir.path + "/src/main/jniLibs/arm64-v8a/libzim/"
137+
}
138+
139+
task copyLibzimAndroidx86(type: Copy) {
140+
// copying android_x86 so file
141+
from buildDir.path + "/libzim_android-x86-" + nightly_date_for_libzim + '/lib/i686-linux-android/'
142+
into projectDir.path + "/src/main/jniLibs/x86/libzim/"
143+
}
144+
145+
task copyLibzimAndroidx86_64(type: Copy) {
146+
// copying android_x86_64 so file
147+
from buildDir.path + "/libzim_android-x86_64-" + nightly_date_for_libzim + '/lib/x86_64-linux-android/'
148+
into projectDir.path + "/src/main/jniLibs/x86_64/libzim/"
149+
}
150+
151+
task copyLibzimLinux_x86_64(type: Copy) {
152+
// copying linux_x86_64 so file
153+
project.ext.set("libzim_version", getFileFromFolder(buildDir.path + "/libzim_linux-x86_64-" + nightly_date_for_libzim + "/lib/x86_64-linux-gnu/"))
154+
from buildDir.path + "/libzim_linux-x86_64-" + nightly_date_for_libzim + "/lib/x86_64-linux-gnu/" + libzim_version
155+
into buildDir.path
156+
}
157+
158+
task renameLibzimSoFile(type: Copy) {
159+
if (libzim_version != null) {
160+
from(buildDir.path)
161+
include libzim_version
162+
destinationDir file(buildDir.path)
163+
rename libzim_version, "libzim.so"
164+
}
165+
}
166+
167+
task downloadLibkiwixSoAndHeaderFiles(type: Download) {
168+
src([
169+
libkiwix_base_url + '/libkiwix_android-arm.tar.gz',
170+
libkiwix_base_url + '/libkiwix_android-arm64.tar.gz',
171+
libkiwix_base_url + '/libkiwix_android-x86.tar.gz',
172+
libkiwix_base_url + '/libkiwix_android-x86_64.tar.gz',
173+
libkiwix_base_url + '/libkiwix_linux-x86_64.tar.gz'
174+
])
175+
dest buildDir
176+
overwrite true
177+
}
178+
179+
task checkCurrentLibkiwixDate() {
180+
project.ext.set("nightly_date_for_libkiwix", getDateFromPath(buildDir.path, "libkiwix_android-arm64-"))
181+
}
182+
183+
static String getDateFromPath(String path, String matchesString) {
184+
File folder = new File(path)
185+
if (folder.exists()) {
186+
return folder.listFiles()
187+
.stream()
188+
.filter(f -> f.name.startsWith(matchesString))
189+
.map(s -> s.name.replace(matchesString, ""))
190+
.collect(Collectors.toList())[0]
191+
}
192+
}
193+
194+
task unzipLibkiwix(type: Copy) {
195+
// unzip android arm
196+
from tarTree(buildDir.path + "/libkiwix_android-arm.tar.gz")
197+
into buildDir
198+
// unzip android arm64
199+
from tarTree(buildDir.path + "/libkiwix_android-arm64.tar.gz")
200+
into buildDir
201+
// unzip android x86
202+
from tarTree(buildDir.path + "/libkiwix_android-x86.tar.gz")
203+
into buildDir
204+
// unzip android x86_64
205+
from tarTree(buildDir.path + "/libkiwix_android-x86_64.tar.gz")
206+
into buildDir
207+
// unzip linux x86_64
208+
from tarTree(buildDir.path + "/libkiwix_linux-x86_64.tar.gz")
209+
into buildDir
210+
}
211+
212+
task copyLibkiwixHeaderFiles(type: Copy) {
213+
// copying header file
214+
from buildDir.path + "/libkiwix_android-arm-" + nightly_date_for_libkiwix + '/include/kiwix/'
215+
into projectDir.path + "/src/main/cpp/include/libkiwix/"
216+
}
217+
218+
task copyLibkiwixAndroidArm(type: Copy) {
219+
// copying android_arm so file
220+
from buildDir.path + "/libkiwix_android-arm-" + nightly_date_for_libkiwix + '/lib/arm-linux-androideabi/'
221+
into projectDir.path + "/src/main/jniLibs/armeabi-v7a/libkiwix/"
222+
}
223+
224+
task copyLibkiwixAndroidArm64(type: Copy) {
225+
// copying android_arm64 so file
226+
from buildDir.path + "/libkiwix_android-arm64-" + nightly_date_for_libkiwix + '/lib/aarch64-linux-android/'
227+
into projectDir.path + "/src/main/jniLibs/arm64-v8a/libkiwix/"
228+
}
229+
230+
task copyLibkiwixAndroidx86(type: Copy) {
231+
// copying android_x86 so file
232+
from buildDir.path + "/libkiwix_android-x86-" + nightly_date_for_libkiwix + '/lib/i686-linux-android/'
233+
into projectDir.path + "/src/main/jniLibs/x86/libkiwix/"
234+
}
235+
236+
task copyLibkiwixAndroidx86_64(type: Copy) {
237+
// copying android_x86_64 so file
238+
from buildDir.path + "/libkiwix_android-x86_64-" + nightly_date_for_libkiwix + '/lib/x86_64-linux-android/'
239+
into projectDir.path + "/src/main/jniLibs/x86_64/libkiwix/"
240+
}
241+
242+
task copyLibkiwixLinux_x86_64(type: Copy) {
243+
// copying linux_x86_64 so file
244+
project.ext.set("libkiwix_version", getFileFromFolder(buildDir.path + "/libkiwix_linux-x86_64-" + nightly_date_for_libkiwix + "/lib/x86_64-linux-gnu/"))
245+
from buildDir.path + "/libkiwix_linux-x86_64-" + nightly_date_for_libkiwix + "/lib/x86_64-linux-gnu/" + libkiwix_version
246+
into buildDir.path
247+
}
248+
249+
static String getFileFromFolder(String path) {
250+
File folderFile = new File(path)
251+
if (folderFile.exists()) {
252+
return folderFile.listFiles()
253+
.stream()
254+
.filter(f -> f.length() > 0)
255+
.collect(Collectors.toList())[0].name
256+
}
257+
}
258+
259+
task renameLibkiwixSoFile(type: Copy) {
260+
if (libkiwix_version != null) {
261+
from(buildDir.path)
262+
include libkiwix_version
263+
destinationDir file(buildDir.path)
264+
rename libkiwix_version, "libkiwix.so"
265+
}
266+
}
267+
268+
task copyBuildKiwixSoFile(type: Copy) {
269+
// copying linux_x86_64 so file
270+
from projectDir.path + "/src/androidTests/java/org/kiwix/kiwixlib/libbuildkiwix.so"
271+
into buildDir.path
272+
}
273+
274+
task createCodeCoverageReport(type: Exec) {
275+
workingDir "${projectDir}/src/androidTests/java/org/kiwix/kiwixlib/"
276+
commandLine 'sh', '-c', "bash 'compile_and_run_test.sh' ${buildDir}/libs/*app*.jar $buildDir"
277+
}
278+
279+
task checkCurrentJavaVersion() {
280+
if (JavaVersion.current() != JavaVersion.VERSION_11) {
281+
throw new RuntimeException("This build must be run with java 11. your current java version is ${JavaVersion.current()}")
282+
}
283+
}
284+
285+
286+
task generateHeaderFilesFromJavaWrapper(type: Exec) {
287+
workingDir "${projectDir}/src/main/java/org/kiwix/"
288+
commandLine 'bash', '-c', "javac -h ${projectDir}/src/main/cpp/include/javah_generated/ -d ${projectDir}/src/androidTests/java/org/kiwix/kiwixlib/ kiwixlib/Book.java kiwixlib/DirectAccessInfo.java kiwixlib/Filter.java kiwixlib/JNIICU.java kiwixlib/JNIKiwixBool.java kiwixlib/JNIKiwixException.java kiwixlib/JNIKiwixInt.java kiwixlib/JNIKiwixReader.java kiwixlib/JNIKiwixSearcher.java kiwixlib/JNIKiwixServer.java kiwixlib/JNIKiwixString.java kiwixlib/Library.java kiwixlib/Manager.java"
289+
}

lib/src/main/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

0 commit comments

Comments
 (0)