From d87a59bcb0020aa651b10108c700ed2437a0b8a7 Mon Sep 17 00:00:00 2001 From: saoq Date: Fri, 25 Nov 2022 08:56:52 +0300 Subject: [PATCH] Refactor build scripts --- app/build.gradle | 41 +++++++++++++++++++++++++++++++++++++++-- scripts/build.sh | 35 ----------------------------------- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a72e5cf39..6596da7e7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,8 @@ import java.util.zip.ZipEntry import java.util.zip.ZipFile import java.util.zip.ZipInputStream +import org.apache.tools.ant.taskdefs.condition.Os + plugins { id 'com.android.application' @@ -8,8 +10,7 @@ plugins { } versionFile { - File moduleDir = projectDir - file = new File(moduleDir.getAbsolutePath() + "/src/main/assets/version.properties") + file = projectDir.toPath().resolve("src/main/assets/version.properties").toFile() } task exportDex { @@ -94,3 +95,39 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.aar']) compileOnly fileTree(dir: 'libs', include: ['*.jar']) } + + +task cleanVersionFile { + projectDir.toPath().resolve("src/main/assets/version.properties").toFile().delete() +} + +task buildVTL(type: Exec) { + dependsOn 'assembleRelease' + dependsOn 'exportDex' + workingDir(projectDir.toPath().resolve("../scripts").normalize().toString()) + if (Os.isFamily("unix") || Os.isFamily("mac")) { + commandLine './build.sh' + } else { + throw RuntimeException("Not supported") + // FIXME not tested + commandLine 'cmd', '/C', 'start', 'build.bat' + } +} + +task buildAndInstallVTL(type: Exec) { + dependsOn('buildVTL') + workingDir(projectDir.toPath().resolve("../smali").normalize().toString()) + ignoreExitValue true + if (Os.isFamily("unix") || Os.isFamily("mac")) { + commandLine 'bash', '-c', 'adb install VTLite.apk' + } else { + throw RuntimeException("Not supported") + // FIXME not tested + commandLine 'adb', 'install', 'VTLite.apk' + } +} + +exportDex.dependsOn('assembleRelease') +clean.dependsOn('cleanVersionFile') +versionFile.dependsOn('cleanVersionFile') +preBuild.dependsOn('versionFile') diff --git a/scripts/build.sh b/scripts/build.sh index 805e92509..f3be78988 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -5,31 +5,7 @@ NC='\033[0m' BOLD='\033[1m' UNDERLINE='\033[4m' -parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) - -cd "$parent_path" - -echo -e "${BOLD}${UNDERLINE}Сборка dex..${NC}\n" cd ../ -rm ../smali/assets/version.properties -rm ../lite/app/src/main/assets/version.properties -./gradlew versionFile -./gradlew assembleRelease -if [ $? -eq 0 ]; then - echo -e "${GREEN}Успех!${NC}\n" -else - echo -e "${RED}Провал.${NC}\n" - exit 1 -fi - -echo -e "${BOLD}${UNDERLINE}Экспорт dex..${NC}" -./gradlew exportDex -if [ $? -eq 0 ]; then - echo -e "${GREEN}Успех!${NC}\n" -else - echo -e "${RED}Провал.${NC}\n" - exit 1 -fi echo -e "${BOLD}${UNDERLINE}Перенос dex6 в папку с исходным кодом..${NC}" mv app/classes6.dex smali/ @@ -80,14 +56,3 @@ echo -e "${BOLD}VTosters Lite успешно собран! APK находитс cd ../smali rm classes6.dex rm classes7.dex - -echo -n "Желаете установить VTosters через adb? (y/n) " -read -n 1 prompt -if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]] -then - echo -e "\n" - adb install VTLite.apk -else - exit 0 -fi -