From 042ac06b9e19b24a9a8aefc66252ee3183140cee Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Fri, 15 Apr 2022 18:47:36 +0300 Subject: [PATCH] android: use gradle to build data archive this fixes #1161 separates the android application build system from automake and simplifies building an application on windows. --- Makefile.am | 15 +-------------- android/build.gradle | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/Makefile.am b/Makefile.am index 5dca80f4..f8f1f910 100644 --- a/Makefile.am +++ b/Makefile.am @@ -388,20 +388,7 @@ apk-debug: espeakdata apk-check: espeakdata cd android && $(GRADLE) connectedCheck -android/res/raw/espeakdata.zip: espeak-ng-data/phontab dictionaries - mkdir -pv android/res/raw - rm -f $@ - find espeak-ng-data/{intonations,phondata,phonindex,phontab} | zip -@ $@ - find espeak-ng-data/*_dict | zip -@ $@ - find espeak-ng-data/lang -type f | zip -@ $@ - find espeak-ng-data/voices -type f | grep -vF "/mb/" | zip -@ $@ - -android/res/raw/espeakdata_version: android/res/raw/espeakdata.zip - sha1sum $< | awk '{ print $$1 }' > $@ - -espeakdata: \ - android/res/raw/espeakdata.zip \ - android/res/raw/espeakdata_version +espeakdata: espeak-ng-data/phontab dictionaries ##### dictionaries: diff --git a/android/build.gradle b/android/build.gradle index ccfa0bdb..13e09910 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -7,7 +7,11 @@ buildscript { classpath 'com.android.tools.build:gradle:7.1.2' } } +plugins { + id 'org.gradle.crypto.checksum' version '1.4.0' +} +import org.gradle.crypto.checksum.Checksum apply plugin: 'com.android.application' repositories { @@ -15,11 +19,51 @@ repositories { mavenCentral() } + dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'org.hamcrest:hamcrest-all:1.3' } +tasks.register('checkData') { + doFirst { + assert file("../espeak-ng-data/en_dict").exists() + assert file("../espeak-ng-data/intonations").exists() + assert file("../espeak-ng-data/phondata").exists() + assert file("../espeak-ng-data/phondata-manifest").exists() + assert file("../espeak-ng-data/phonindex").exists() + assert file("../espeak-ng-data/phontab").exists() + } +} + +tasks.register('createDataArchive', Zip) { + dependsOn tasks.checkData + preserveFileTimestamps = false + reproducibleFileOrder = true + archiveFileName = "espeakdata.zip" + destinationDirectory = file("res/raw") + + from("../espeak-ng-data/") { + into "espeak-ng-data" + } +} + +tasks.register('createDataHash', Checksum) { + dependsOn tasks.createDataArchive + checksumAlgorithm.set(Checksum.Algorithm.SHA256) + inputFiles.setFrom(file("./res/raw/espeakdata.zip")) + outputDirectory.set(layout.buildDirectory.dir('intermediates/datahash')) +} + +tasks.register('createDataVersion', Copy) { + dependsOn tasks.createDataHash + from layout.buildDirectory.file('intermediates/datahash/espeakdata.zip.sha256') + rename { return 'espeakdata_version' } + into file("./res/raw") +} +preBuild.dependsOn createDataVersion + + android { compileSdkVersion 26