Added support for SDK 34.

* Upgraded the gradle to support the Android 14.
* Made the changes in code to adapt the new gradle.
* Rectify the deprecated code that are not working in new version of gradle.
This commit is contained in:
MohitMaliFtechiz 2024-05-13 15:59:00 +05:30
parent 40f17fd0e6
commit ab98924400
6 changed files with 37 additions and 38 deletions

View File

@ -15,11 +15,11 @@ jobs:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up JDK 11 - name: Set up JDK 17
uses: actions/setup-java@v4 uses: actions/setup-java@v4
with: with:
distribution: adopt distribution: adopt
java-version: 11 java-version: 17
- name: Install dependencies - name: Install dependencies
run: bash ./install_deps.sh run: bash ./install_deps.sh

View File

@ -6,8 +6,8 @@ buildscript {
maven { url 'https://plugins.gradle.org/m2/' } maven { url 'https://plugins.gradle.org/m2/' }
} }
dependencies { dependencies {
classpath "com.android.tools.build:gradle:7.0.1" classpath "com.android.tools.build:gradle:8.1.0-alpha10"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20"
classpath 'io.github.gradle-nexus:publish-plugin:1.1.0' classpath 'io.github.gradle-nexus:publish-plugin:1.1.0'
classpath 'de.undercouch:gradle-download-task:5.3.0' classpath 'de.undercouch:gradle-download-task:5.3.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
@ -17,7 +17,7 @@ buildscript {
apply plugin: 'io.github.gradle-nexus.publish-plugin' apply plugin: 'io.github.gradle-nexus.publish-plugin'
task clean(type: Delete) { tasks.register('clean', Delete) {
delete rootProject.buildDir delete rootProject.buildDir
} }

View File

@ -1,6 +1,6 @@
#Fri Aug 12 19:44:15 IST 2022 #Fri Aug 12 19:44:15 IST 2022
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME

View File

@ -28,12 +28,12 @@ ext.libzim_version = "9.2.1"
apply from: 'publish.gradle' apply from: 'publish.gradle'
android { android {
compileSdk 32 compileSdk 34
namespace = "kiwix.org.kiwixlib"
defaultConfig { defaultConfig {
minSdk 21 minSdk 25
targetSdk 32 targetSdk 34
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
@ -79,7 +79,7 @@ dependencies {
ext.libkiwix_base_url = 'https://download.kiwix.org/release/libkiwix/' ext.libkiwix_base_url = 'https://download.kiwix.org/release/libkiwix/'
ext.libzim_base_url = 'https://download.openzim.org/release/libzim/' ext.libzim_base_url = 'https://download.openzim.org/release/libzim/'
task downloadLibzimSoAndHeaderFiles(type: Download) { tasks.register('downloadLibzimSoAndHeaderFiles', Download) {
src([ src([
libzim_base_url + 'libzim_android-arm-' + libzim_version + '.tar.gz', libzim_base_url + 'libzim_android-arm-' + libzim_version + '.tar.gz',
libzim_base_url + 'libzim_android-arm64-' + libzim_version + '.tar.gz', libzim_base_url + 'libzim_android-arm64-' + libzim_version + '.tar.gz',
@ -91,7 +91,8 @@ task downloadLibzimSoAndHeaderFiles(type: Download) {
overwrite true overwrite true
} }
task unzipLibzim(type: Copy) { tasks.register('unzipLibzim', Copy) {
mustRunAfter downloadLibzimSoAndHeaderFiles
// unzip android arm // unzip android arm
from tarTree(buildDir.path + "/libzim_android-arm-" + libzim_version + ".tar.gz") from tarTree(buildDir.path + "/libzim_android-arm-" + libzim_version + ".tar.gz")
into buildDir into buildDir
@ -109,11 +110,11 @@ task unzipLibzim(type: Copy) {
into buildDir into buildDir
} }
task renameLibzimFolders() { tasks.register('renameLibzimFolders') {
removeVersionFromFolderName(buildDir.path, "libzim_", libzim_version) removeVersionFromFolderName(buildDir.path, "libzim_", libzim_version)
} }
task copyLibzimHeaderAndSoFiles(type: Copy) { tasks.register('copyLibzimHeaderAndSoFiles', Copy) {
copy { copy {
// copying header file // copying header file
from buildDir.path + "/libzim_android-arm/include/" from buildDir.path + "/libzim_android-arm/include/"
@ -151,7 +152,7 @@ task copyLibzimHeaderAndSoFiles(type: Copy) {
} }
} }
task renameLibzimSoFile(type: Copy) { tasks.register('renameLibzimSoFile', Copy) {
if (libzim_version != null) { if (libzim_version != null) {
def finalLibzimVersion = getActualLibraryVersion(libzim_version) def finalLibzimVersion = getActualLibraryVersion(libzim_version)
@ -167,7 +168,7 @@ task renameLibzimSoFile(type: Copy) {
} }
} }
task downloadLibkiwixSoAndHeaderFiles(type: Download) { tasks.register('downloadLibkiwixSoAndHeaderFiles', Download) {
src([ src([
libkiwix_base_url + 'libkiwix_android-arm-' + libkiwix_version + '.tar.gz', libkiwix_base_url + 'libkiwix_android-arm-' + libkiwix_version + '.tar.gz',
libkiwix_base_url + 'libkiwix_android-arm64-' + libkiwix_version + '.tar.gz', libkiwix_base_url + 'libkiwix_android-arm64-' + libkiwix_version + '.tar.gz',
@ -179,7 +180,7 @@ task downloadLibkiwixSoAndHeaderFiles(type: Download) {
overwrite true overwrite true
} }
task renameLibkiwixFolders() { tasks.register('renameLibkiwixFolders') {
removeVersionFromFolderName(buildDir.path, "libkiwix_", libkiwix_version) removeVersionFromFolderName(buildDir.path, "libkiwix_", libkiwix_version)
} }
@ -196,7 +197,8 @@ static void removeVersionFromFolderName(String path, String startWith, String ve
} }
} }
task unzipLibkiwix(type: Copy) { tasks.register('unzipLibkiwix', Copy) {
mustRunAfter downloadLibkiwixSoAndHeaderFiles
// unzip android arm // unzip android arm
from tarTree(buildDir.path + "/libkiwix_android-arm-" + libkiwix_version + ".tar.gz") from tarTree(buildDir.path + "/libkiwix_android-arm-" + libkiwix_version + ".tar.gz")
into buildDir into buildDir
@ -214,7 +216,7 @@ task unzipLibkiwix(type: Copy) {
into buildDir into buildDir
} }
task copyLibkiwixHeaderAndSoFiles(type: Copy) { tasks.register('copyLibkiwixHeaderAndSoFiles', Copy) {
copy { copy {
// copying header file // copying header file
from buildDir.path + "/libkiwix_android-arm/include/kiwix/" from buildDir.path + "/libkiwix_android-arm/include/kiwix/"
@ -252,7 +254,7 @@ task copyLibkiwixHeaderAndSoFiles(type: Copy) {
} }
} }
task renameLibkiwixSoFile(type: Copy) { tasks.register('renameLibkiwixSoFile', Copy) {
if (libkiwix_version != null) { if (libkiwix_version != null) {
def finalLibkiwixVersion = getActualLibraryVersion(libkiwix_version) def finalLibkiwixVersion = getActualLibraryVersion(libkiwix_version)
def sourceFile = file(buildDir.path + "/libkiwix.so." + finalLibkiwixVersion) def sourceFile = file(buildDir.path + "/libkiwix.so." + finalLibkiwixVersion)
@ -277,23 +279,23 @@ static String getActualLibraryVersion(String libraryVersion) {
return dashIndex != -1 ? libraryVersion.substring(0, dashIndex) : libraryVersion return dashIndex != -1 ? libraryVersion.substring(0, dashIndex) : libraryVersion
} }
task testSourceJar(type: Jar) { tasks.register('testSourceJar', Jar) {
from android.sourceSets.test.java.srcDirs from android.sourceSets.test.java.srcDirs
archiveName = 'test-sources.jar' archiveBaseName = 'test-sources'
} }
task compileTestFile(type: JavaCompile) { tasks.register('compileTestFile', JavaCompile) {
dependsOn testSourceJar dependsOn testSourceJar
source = file('src/test') source = file('src/test')
destinationDirectory = file("$buildDir") destinationDirectory = file("$buildDir")
classpath = files("src/test/junit-4.13.jar" , "src/test/hamcrest-core-1.4.jar", "build/libs/test-sources.jar") classpath = files("src/test/junit-4.13.jar", "src/test/hamcrest-core-1.4.jar", "build/libs/test-sources-${VERSION}.jar")
} }
task runTests(type: JavaExec) { tasks.register('runTests', JavaExec) {
workingDir("$projectDir/src/test/") workingDir("$projectDir/src/test/")
dependsOn compileTestFile dependsOn compileTestFile
classpath = files("$buildDir", 'src/test/java/', 'src/test/junit-4.13.jar', 'src/test/hamcrest-core-1.3.jar') classpath = files("$buildDir", 'src/test/java/', 'src/test/junit-4.13.jar', 'src/test/hamcrest-core-1.3.jar')
main = 'org.junit.runner.JUnitCore' mainClass = 'org.junit.runner.JUnitCore'
args = ['test'] args = ['test']
jvmArgs = [ jvmArgs = [
'-Djava.library.path=' + buildDir.path, '-Djava.library.path=' + buildDir.path,
@ -301,11 +303,11 @@ task runTests(type: JavaExec) {
] ]
} }
task createCodeCoverageReport(type: JavaExec) { tasks.register('createCodeCoverageReport', JavaExec) {
workingDir "${projectDir}/src/test/" workingDir "${projectDir}/src/test/"
dependsOn runTests dependsOn runTests
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/*') 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/*')
main = 'org.jacoco.cli.internal.Main' mainClass = 'org.jacoco.cli.internal.Main'
args = [ args = [
'report', '../../build/jacoco/jacoco.exec', 'report', '../../build/jacoco/jacoco.exec',
'--classfiles', 'java/org/kiwix', '--classfiles', '../../build/org/kiwix', '--classfiles', 'java/org/kiwix', '--classfiles', '../../build/org/kiwix',
@ -313,14 +315,14 @@ task createCodeCoverageReport(type: JavaExec) {
] ]
} }
task checkCurrentJavaVersion() { tasks.register('checkCurrentJavaVersion') {
if (JavaVersion.current() != JavaVersion.VERSION_11) { if (JavaVersion.current() != JavaVersion.VERSION_17) {
throw new RuntimeException("This build must be run with java 11. your current java version is ${JavaVersion.current()}") throw new RuntimeException("This build must be run with java 17. your current java version is ${JavaVersion.current()}")
} }
} }
task buildHeaders(type: Exec) { tasks.register('buildHeaders', Exec) {
workingDir "${projectDir}/src/main/java/org/kiwix/" workingDir "${projectDir}/src/main/java/org/kiwix/"
commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${projectDir}/src/test/java/ ${getLibzimFiles()} ${getLibkiwixFiles()}" commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${projectDir}/src/test/java/ ${getLibzimFiles()} ${getLibkiwixFiles()}"
} }
@ -358,7 +360,7 @@ String getLibzimFiles() {
"${projectDir}/src/main/java/org/kiwix/libzim/FdInput.java" "${projectDir}/src/main/java/org/kiwix/libzim/FdInput.java"
} }
task buildLinuxBinding(type: Exec) { tasks.register('buildLinuxBinding', Exec) {
workingDir "${projectDir}/src/main/cpp/" workingDir "${projectDir}/src/main/cpp/"
commandLine 'bash', '-c', "cmake . -B ${buildDir} && make -C ${buildDir}" commandLine 'bash', '-c', "cmake . -B ${buildDir} && make -C ${buildDir}"
} }

View File

@ -1,7 +1,7 @@
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
apply plugin: 'signing' apply plugin: 'signing'
task androidSourcesJar(type: Jar) { tasks.register('androidSourcesJar', Jar) {
archiveClassifier.set('sources') archiveClassifier.set('sources')
if (project.plugins.findPlugin("com.android.library")) { if (project.plugins.findPlugin("com.android.library")) {
// For Android libraries // For Android libraries

View File

@ -1,7 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android">
package="kiwix.org.kiwixlib"
>
<application android:allowBackup="true" <application android:allowBackup="true"
android:label="@string/app_name" android:label="@string/app_name"