diff --git a/.gitmodules b/.gitmodules index 15ff55f..16031d9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "firka/lib/l10n"] path = firka/lib/l10n url = https://github.com/QwIT-Development/firka-localization -[submodule "firka/android/app/src/main/java/org/brotli"] - path = firka/android/app/src/main/java/org/brotli - url = https://git.firka.app/firka/org_brotli [submodule "firka_wear/lib/l10n"] path = firka_wear/lib/l10n url = https://github.com/qwit-development/firka-localization diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..78ce466 --- /dev/null +++ b/build.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Build firka and/or firka_wear with version from pubspec + short git SHA. +# Usage: ./build.sh [firka|firka_wear|all] +# Default (no args) builds both. + +ROOT="$(cd "$(dirname "$0")" && pwd)" +SHA=$(git -C "$ROOT" rev-parse --short HEAD) + +build_app() { + local APP="$1" + local PUBSPEC="$ROOT/$APP/pubspec.yaml" + if [[ ! -f "$PUBSPEC" ]]; then + echo "Not found: $PUBSPEC" >&2 + return 1 + fi + + local VERSION_LINE BUILD_NUMBER BASE_VERSION BUILD_NAME + VERSION_LINE=$(grep -E '^\s*version:\s*' "$PUBSPEC" | head -1) + BASE_VERSION=$(echo "$VERSION_LINE" | sed -E 's/^[[:space:]]*version:[[:space:]]*([^+]+).*/\1/' | tr -d ' ') + BUILD_NUMBER="" + if [[ "$VERSION_LINE" == *+* ]]; then + BUILD_NUMBER=$(echo "$VERSION_LINE" | sed -E 's/^[[:space:]]*version:[[:space:]]*[^+]+\+([0-9]+).*/\1/') + fi + BUILD_NAME="${BASE_VERSION}-${SHA}" + + echo "Building $APP: version $BUILD_NAME (build number: ${BUILD_NUMBER:-none})" + cd "$ROOT/$APP" + + local FLUTTER_ARGS=(build appbundle --build-name="$BUILD_NAME" --verbose) + [[ -n "${BUILD_NUMBER:-}" ]] && FLUTTER_ARGS+=(--build-number="$BUILD_NUMBER") + + flutter "${FLUTTER_ARGS[@]}" +} + +case "${1:-all}" in + firka) build_app firka ;; + firka_wear) build_app firka_wear ;; + all) build_app firka && build_app firka_wear ;; + *) + echo "Usage: $0 [firka|firka_wear|all]" >&2 + exit 1 + ;; +esac diff --git a/firka/android/app/proguard-rules.pro b/firka/android/app/proguard-rules.pro index 5c66160..e780808 100644 --- a/firka/android/app/proguard-rules.pro +++ b/firka/android/app/proguard-rules.pro @@ -1,2 +1 @@ --keep class org.brotli.** { *; } -keep class app.firka.naplo.glance.** { *; } \ No newline at end of file diff --git a/firka/android/app/src/main/java/org/brotli b/firka/android/app/src/main/java/org/brotli deleted file mode 160000 index da8f329..0000000 --- a/firka/android/app/src/main/java/org/brotli +++ /dev/null @@ -1 +0,0 @@ -Subproject commit da8f329432ff3e7deaedb4a60026138db2920a3a diff --git a/firka/codegen-lock.yaml b/firka/codegen-lock.yaml index 780d1b3..7d8399a 100644 --- a/firka/codegen-lock.yaml +++ b/firka/codegen-lock.yaml @@ -7,9 +7,9 @@ icons: "assets/images/logos/colored_logo_only_mustache.png": "bad6220c11bdfb1dfe04e5173bd2ebedd3999689d4b3a68fc63dc520c96dd33b" l10n: "l10n.yml": "a57bc304cac4a2b0235593586f17f400a5165d67fc9aadeaa11893cfa36ee082" - "lib/l10n/app_hu.arb": "a7f61bf4452a639d61c350f6674fdb5fd424f9ab31a195a200d446763fa8b396" "lib/l10n/app_de.arb": "55f030b312cc07ff05cdc3d6ee10ef9bdec3243b507225e9a47196444518d955" - "lib/l10n/app_en.arb": "efac3f14d8ecc3e278f80a3e5aff599a88e408d2e30ff9e30f889978f465823a" + "lib/l10n/app_en.arb": "cbad6dd2485a983e399cce97371c19089b9110d30536488c14a7ea709c7b6ead" + "lib/l10n/app_hu.arb": "17077ec76b68ed03796a264b99e4dba9e6ddd532e27a92d8fb237ea6f211f757" isar: "lib/data/models/app_settings_model.dart": "5eb5af345f1347f104257f0999763650fe2673f9da1754bd12d3f756fe5c9723" "lib/data/models/generic_cache_model.dart": "79151d0467fb5d40c532eaaa08ad7c7e24a34304199280fbf49cf6e5adcce6bc" diff --git a/firka/lib/core/firka_bundle.dart b/firka/lib/core/firka_bundle.dart index cfb96b4..df57e1a 100644 --- a/firka/lib/core/firka_bundle.dart +++ b/firka/lib/core/firka_bundle.dart @@ -1,62 +1,12 @@ -import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; - -import 'package:brotli/brotli.dart'; import 'package:firka/app/app_state.dart'; import 'package:flutter/services.dart'; class FirkaBundle extends CachingAssetBundle { - // final bool _compressedBundle = !kDebugMode && Platform.isAndroid; - final bool _compressedBundle = false; - - Map? index; - - Future> loadIndex() async { - var indexBrotli = await rootBundle.load("assets/firka.i"); - var indexStr = brotli.decodeToString(indexBrotli.buffer.asInt8List()); - - return Future.value(jsonDecode(indexStr)); - } - - ByteData decode(Codec, List> codec, ByteData data) { - var dec = codec.decode(data.buffer.asInt8List()); - var b = ByteData(dec.length); - var l = b.buffer.asInt8List(); - - for (var i = 0; i < dec.length; i++) { - l[i] = dec[i]; - } - - return b; - } - @override Future load(String key) async { - if (!_compressedBundle) { - logger.finest( - "Loading asset from root bundle: assets/flutter_assets/$key", - ); - return rootBundle.load(key); - } else { - index ??= await loadIndex(); - - final gzip = GZipCodec(); - - logger.finest( - "Loading asset from firka bundle: assets/flutter_assets/$key", - ); - switch (index!["assets/flutter_assets/$key"]!) { - case "b": // brotli - return decode(brotli, await rootBundle.load(key)); - case "g": // gzip - return decode(gzip, await rootBundle.load(key)); - case "r": // raw - return rootBundle.load(key); - default: - logger.shout("Unknown file format: ${index![key]!}"); - throw "Unknown file format: ${index![key]!}"; - } - } + logger.finest( + "Loading asset from root bundle: assets/flutter_assets/$key", + ); + return rootBundle.load(key); } } diff --git a/firka/lib/ui/phone/pages/home/home_timetable.dart b/firka/lib/ui/phone/pages/home/home_timetable.dart index e306136..0062cfc 100644 --- a/firka/lib/ui/phone/pages/home/home_timetable.dart +++ b/firka/lib/ui/phone/pages/home/home_timetable.dart @@ -608,7 +608,6 @@ class _HomeTimetableScreen extends FirkaState "dropdownLeft", size: 24, color: appStyle.colors.accent, - package: 'firka', ), ), onTap: () async { @@ -673,7 +672,6 @@ class _HomeTimetableScreen extends FirkaState "dropdownRight", size: 24, color: appStyle.colors.accent, - package: 'firka', ), ), onTap: () async { diff --git a/firka/lib/ui/phone/pages/home/home_timetable_mo.dart b/firka/lib/ui/phone/pages/home/home_timetable_mo.dart index f451096..e438f2f 100644 --- a/firka/lib/ui/phone/pages/home/home_timetable_mo.dart +++ b/firka/lib/ui/phone/pages/home/home_timetable_mo.dart @@ -438,7 +438,6 @@ class _HomeTimetableMonthlyScreen "dropdownLeft", size: 24, color: appStyle.colors.accent, - package: 'firka', ), ), onTap: () async { @@ -468,7 +467,6 @@ class _HomeTimetableMonthlyScreen "dropdownRight", size: 24, color: appStyle.colors.accent, - package: 'firka', ), onTap: () async { var newNow = DateTime(now!.year, now!.month + 1); diff --git a/firka/lib/ui/phone/screens/settings/settings_screen.dart b/firka/lib/ui/phone/screens/settings/settings_screen.dart index 4418afd..3db953f 100644 --- a/firka/lib/ui/phone/screens/settings/settings_screen.dart +++ b/firka/lib/ui/phone/screens/settings/settings_screen.dart @@ -948,7 +948,6 @@ class _SettingsScreenState extends FirkaState { FirkaIconType.icons, "group", color: appStyle.colors.accent, - package: 'firka', ), SizedBox(width: 8), Text( diff --git a/firka/lib/ui/phone/widgets/home_main_welcome.dart b/firka/lib/ui/phone/widgets/home_main_welcome.dart index 4b90323..cdc2170 100644 --- a/firka/lib/ui/phone/widgets/home_main_welcome.dart +++ b/firka/lib/ui/phone/widgets/home_main_welcome.dart @@ -56,14 +56,12 @@ class _WelcomeWidgetState extends State { FirkaIconType.majesticonsLocal, "sunSolid", color: appStyle.colors.accent, - package: 'firka', ); case Cycle.day: return FirkaIconWidget( FirkaIconType.majesticonsLocal, "parkSolidSchool", color: appStyle.colors.accent, - package: 'firka', ); case Cycle.afternoon: return FirkaIconWidget( diff --git a/firka/lib/ui/phone/widgets/homework.dart b/firka/lib/ui/phone/widgets/homework.dart index 956b650..18634d8 100644 --- a/firka/lib/ui/phone/widgets/homework.dart +++ b/firka/lib/ui/phone/widgets/homework.dart @@ -34,7 +34,6 @@ class HomeworkWidget extends StatelessWidget { "homeWithMark", color: appStyle.colors.accent, size: 24, - package: 'firka', ) : FirkaIconWidget( FirkaIconType.majesticons, diff --git a/firka/lib/ui/phone/widgets/lesson.dart b/firka/lib/ui/phone/widgets/lesson.dart index b9a795f..a7a04fc 100644 --- a/firka/lib/ui/phone/widgets/lesson.dart +++ b/firka/lib/ui/phone/widgets/lesson.dart @@ -370,7 +370,6 @@ class LessonWidget extends StatelessWidget { 'cupFilled', color: appStyle.colors.accent, size: 24, - package: 'firka', ), ), ), diff --git a/firka/lib/ui/phone/widgets/lesson_big.dart b/firka/lib/ui/phone/widgets/lesson_big.dart index 28acf96..d3c5654 100644 --- a/firka/lib/ui/phone/widgets/lesson_big.dart +++ b/firka/lib/ui/phone/widgets/lesson_big.dart @@ -245,7 +245,6 @@ class LessonBigWidget extends StatelessWidget { 'cupFilled', color: appStyle.colors.accent, size: 24, - package: 'firka', ), ), ), @@ -488,7 +487,6 @@ class LessonBigWidget extends StatelessWidget { 'cupFilled', color: appStyle.colors.accent, size: 24, - package: 'firka', ), ), ), diff --git a/firka/pubspec.yaml b/firka/pubspec.yaml index 2e74080..7aaf4be 100644 --- a/firka/pubspec.yaml +++ b/firka/pubspec.yaml @@ -2,7 +2,7 @@ name: firka description: "Firka, Alternatív e-Kréta kliens." publish_to: 'none' -version: 1.1.0+1040 +version: 1.1.0+2001 environment: sdk: ^3.11.0 @@ -38,7 +38,6 @@ dependencies: flutter_arc_text: ^0.6.0 flutter_svg: ^1.1.6 home_widget: ^0.8.0 - brotli: ^0.6.0 crypto: ^3.0.6 transparent_pointer: ^1.0.1 flutter_staggered_grid_view: ^0.7.0 @@ -90,7 +89,6 @@ flutter: - assets/images/bubble.svg - assets/icons/ - assets/majesticons/ - - assets/firka.i - assets/swears/DirtyWords.xml - assets/images/cactus_error_screen.png - assets/images/logos/dave_error.png diff --git a/firka_wear/android/app/build.gradle.kts b/firka_wear/android/app/build.gradle.kts index ca8c9b1..dd9dec9 100644 --- a/firka_wear/android/app/build.gradle.kts +++ b/firka_wear/android/app/build.gradle.kts @@ -1,15 +1,5 @@ -import org.apache.commons.io.FileUtils import java.io.FileInputStream -import java.security.MessageDigest import java.util.Properties -import java.util.concurrent.Executors -import java.util.concurrent.Future -import java.util.concurrent.locks.ReentrantReadWriteLock -import java.util.zip.ZipEntry -import java.util.zip.ZipFile -import java.util.zip.ZipOutputStream -import java.util.zip.ZipOutputStream.DEFLATED -import java.util.zip.ZipOutputStream.STORED plugins { id("com.android.application") @@ -114,724 +104,3 @@ fun checkReleaseKey() { throw Exception("Release keystore not found!") } } - -fun transformApks(debug: Boolean, i : Int = 0) { - try { - _transformApks(debug) - } catch (e: Exception) { - if (i < 5) { - e.printStackTrace() - - println("Retrying: ${i + 1}") - transformApks(debug, i + 1) - } else { - throw e - } - } -} - -fun _transformApks(debug: Boolean) { - println("Starting APK transformation process...") - - val buildDir = project.buildDir - val apkDir = File(buildDir, "outputs/flutter-apk") - val apks = getApks(debug) - var c = 0 - apks - .forEach { c++; transformAndSignApk(apkDir, it.nameWithoutExtension, debug) } - - println("Transformed: $c apks") -} - -fun transformAndSignApk(apkDir: File, name: String, debug: Boolean) { - val originalApk = File(apkDir, "$name.apk") - val transformedApk = File(apkDir, "$name-transformed.apk") - val finalApk = File(apkDir, "$name-resigned.apk") - val finalIdsig = File(apkDir, "$name-resigned.apk.idsig") - - if (!originalApk.exists()) { - throw GradleException("Original APK not found at: ${originalApk.absolutePath}") - } - - if (transformedApk.exists()) transformedApk.delete() - if (finalApk.exists()) finalApk.delete() - - println("Original APK: ${originalApk.absolutePath}") - - try { - println("Transforming APK...") - transformApk(originalApk, transformedApk, if (debug) { "6" } else {"Z"}) - - if (debug) { - println("Signing with debug key...") - signWithDebugKey(transformedApk, finalApk) - } else { - println("Signing with release key...") - signWithReleaseKey(transformedApk, finalApk) - } - - if (finalApk.exists()) { - originalApk.delete() - finalIdsig.delete() - finalApk.renameTo(originalApk) - println("APK successfully transformed") - println("Final APK: ${originalApk.absolutePath}") - } - - transformedApk.delete() - } catch (e: Exception) { - throw GradleException("Failed to transform and resign APK: ${e.message}", e) - } -} - -fun transformApk(input: File, output: File, compressionLevel: String = "Z") { - val tempDir = File(project.buildDir, "tmp/apk-transform") - val cacheDir = File(project.buildDir, "cache") - val optipngCacheDir = File(cacheDir, "optipng") - val assetCompressionDir = File(cacheDir, "assets") - tempDir.deleteRecursively() - tempDir.mkdirs() - if (!optipngCacheDir.exists()) optipngCacheDir.mkdirs() - if (!assetCompressionDir.exists()) assetCompressionDir.mkdirs() - - val brotli = findToolInPath("brotli") - ?: throw Exception("Brotli not found in path") - val optipng = findToolInPath("optipng") - - if (optipng == null || optipng.isEmpty()) { - println("Optipng was not found in PATH, optimizing images will be skipped.") - } - - copy { - from(zipTree(input)) - into(tempDir) - } - - val metaInf = File(tempDir, "META-INF") - val metaInfFiles = metaInf.listFiles() - for (file in metaInfFiles!!) { - if (file.name.endsWith("MF") || file.name.endsWith("SF") - || file.name.endsWith("RSA")) { - file.delete() - } - } - - val arches = File(tempDir, "lib").listFiles() - val compressedLibs = mutableMapOf() - for (arch in arches!!) { - val libFlutter = File(arch, "libflutter.so") - - if (!libFlutter.exists()) continue - - val compressedFlutter = File(arch, "libflutter-br.so") - - compressedLibs["libflutter.so"] = libFlutter.sha256() - - println("Compressing ${arch.name}/libflutter.so with brotli") - exec { - commandLine( - brotli, - "-$compressionLevel", - libFlutter.absolutePath, - "-o", compressedFlutter.absolutePath - ) - } - libFlutter.delete() - - val json = groovy.json.JsonBuilder(compressedLibs) - File(arch, "index.so").writeText(json.toString()) - } - - val topDirL = tempDir.absolutePath.length + 1 - val zos = ZipOutputStream(output.outputStream()) - - val coreCount = Runtime.getRuntime().availableProcessors() - val flutterResources = tempDir.walkTopDown().filter{f -> f.absolutePath.contains("flutter_assets")} - val pngFiles = tempDir.walkTopDown().filter{f -> f.name.endsWith(".png")} - - val assetIndex = mutableMapOf() - val indexReadWriteLock = ReentrantReadWriteLock() - - if (compressionLevel == "Z") { - if (optipng != null) { - val executor = Executors.newFixedThreadPool(coreCount) - val futures = mutableListOf>() - - pngFiles.forEach { pngFile -> - val cacheFile = File(optipngCacheDir, pngFile.sha256()) - - if (cacheFile.exists()) { - cacheFile.copyTo(pngFile, true) - } else { - val future = executor.submit { - exec { - commandLine( - optipng, - "-zm", "9", - "-zw", "32k", - "-o9", - pngFile.absolutePath - ) - } - - pngFile.copyTo(cacheFile, true) - } - - futures.add(future) - } - } - - futures.forEach { it.get() } - executor.shutdown() - } - - val executor = Executors.newFixedThreadPool(coreCount) - val futures = mutableListOf>() - - val blacklist = listOf( - // "AssetManifest.bin", - "AssetManifest.json", - "FontManifest.json", - "isolate_snapshot_data", - "kernel_blob.bin", - "NativeAssetsManifest.json", - "NOTICES.Z", - "vm_snapshot_data", - "fonts", - "shaders" - ) - - flutterResources.forEach { f -> - val relName = f.absolutePath.substring(topDirL).replace("\\", "/") - if (f.isDirectory) return@forEach - - val cacheFileRaw = File(assetCompressionDir, f.sha256()+".r") - val cacheFileGz = File(assetCompressionDir, f.sha256()+".gz") - val cacheFileBr = File(assetCompressionDir, f.sha256()+".br") - - if (cacheFileRaw.exists() || cacheFileGz.exists() || cacheFileBr.exists()) { - if (cacheFileRaw.exists()) { - cacheFileRaw.copyTo(f, true) - - indexReadWriteLock.writeLock().lock() - assetIndex[relName] = "r" - indexReadWriteLock.writeLock().unlock() - } else if (cacheFileGz.exists()) { - cacheFileGz.copyTo(f, true) - - indexReadWriteLock.writeLock().lock() - assetIndex[relName] = "g" - indexReadWriteLock.writeLock().unlock() - } else { - cacheFileBr.copyTo(f, true) - - indexReadWriteLock.writeLock().lock() - assetIndex[relName] = "b" - indexReadWriteLock.writeLock().unlock() - } - } else { - val future = executor.submit { - val brTmp = File(f.absolutePath + ".br.tmp") - val gzTmp = File(f.absolutePath + ".gz.tmp") - - var blacklisted = false - for (f in blacklist) { - if (relName.contains(f)) { - blacklisted = true - - break - } - } - - if (!blacklisted) { - println("$relName: Testing with brotli") - exec { - commandLine( - brotli, - "-$compressionLevel", - f.absolutePath, - "-o", brTmp.absolutePath - ) - } - - println("$relName: Testing with gzip") - ant.invokeMethod( - "gzip", mapOf( - "src" to f.absolutePath, - "destfile" to gzTmp.absolutePath, - ) - ) - - println("$brTmp: ${brTmp.length()}") - println("$gzTmp: ${gzTmp.length()}") - if (f.length() < gzTmp.length() && f.length() < brTmp.length()) { - println("$relName: Raw file wins") - - f.copyTo(cacheFileRaw, true) - - indexReadWriteLock.writeLock().lock() - assetIndex[relName] = "r" - indexReadWriteLock.writeLock().unlock() - } else { - if (brTmp.length() < gzTmp.length()) { - println("$relName: Brotli wins") - - f.delete() - brTmp.copyTo(f, true) - brTmp.copyTo(cacheFileBr, true) - - indexReadWriteLock.writeLock().lock() - assetIndex[relName] = "b" - indexReadWriteLock.writeLock().unlock() - } else { - println("$relName: Gzip wins") - - f.delete() - gzTmp.copyTo(f, true) - gzTmp.copyTo(cacheFileGz, true) - - indexReadWriteLock.writeLock().lock() - assetIndex[relName] = "g" - indexReadWriteLock.writeLock().unlock() - } - } - - brTmp.delete() - gzTmp.delete() - } - } - - futures.add(future) - } - } - - futures.forEach { it.get() } - executor.shutdown() - } - - tempDir.walkTopDown().forEach { f -> - if (f.absolutePath == tempDir.absolutePath) return@forEach - - var relName = f.absolutePath.substring(topDirL).replace("\\", "/") - if (f.isDirectory && !relName.endsWith("/")) relName += "/" - - if (compressionLevel == "Z") { - if (relName == "assets/flutter_assets/assets/firka.i") return@forEach - } - - println(relName) - - val compress = !relName.endsWith(".so") && !relName.endsWith(".arsc") - zos.setMethod(if (compress) { DEFLATED } else { STORED }) - val entry = ZipEntry(relName) - if (!compress) { - entry.size = f.length() - entry.crc = FileUtils.checksumCRC32(f) - } - zos.putNextEntry(entry) - if (f.isFile) { - zos.write(f.readBytes()) - } - zos.closeEntry() - } - if (compressionLevel == "Z") { - zos.setMethod(DEFLATED) - zos.putNextEntry(ZipEntry("assets/flutter_assets/assets/firka.i")) - - val indexUncompressed = File(tempDir, "index.json") - indexReadWriteLock.readLock().lock() - val json = groovy.json.JsonBuilder(assetIndex) - indexReadWriteLock.readLock().unlock() - indexUncompressed.writeText(json.toString()) - - val indexCompressed = File(tempDir, "index.json.br") - - exec { - commandLine( - brotli, - "-$compressionLevel", - indexUncompressed.absolutePath, - "-o", indexCompressed.absolutePath - ) - } - - zos.write(indexCompressed.readBytes()) - indexUncompressed.delete() - indexCompressed.delete() - - zos.closeEntry() - } - zos.close() - - tempDir.deleteRecursively() - println("APK transformed successfully") -} - -fun transformAppBundle() { - val buildDir = project.buildDir - val bundle = File(buildDir, "outputs/bundle/release/app-release.aab") - val bundleTmp = File(buildDir, "outputs/bundle/release/tmp.zip") - - val apks = getApks(false) - val apkCount = apks.count { it.name.startsWith("app-") && it.name.endsWith("-release.apk") } - - if (!bundle.exists()) { - throw Exception("Bundle not found at: $bundle") - } - - if (apkCount < 3) { - throw Exception("Excepected 3 apks per abi but only found $apkCount") - } - - val aabTempDir = File(project.buildDir, "tmp/aab-transform") - aabTempDir.deleteRecursively() - aabTempDir.mkdirs() - - val apksUnzipped = File(project.buildDir, "tmp/apks-unzipped") - apksUnzipped.deleteRecursively() - - val arm32TempDir = File(apksUnzipped, "armeabi-v7a") - arm32TempDir.mkdirs() - val arm64TempDir = File(apksUnzipped, "arm64-v8a") - arm64TempDir.mkdirs() - val x86TempDir = File(apksUnzipped, "x86_64") - x86TempDir.mkdirs() - - copy { - from(zipTree(bundle)) - into(aabTempDir) - } - copy { - from(zipTree(apks.first { it.name.contains("armeabi-v7a") })) - into(arm32TempDir) - } - copy { - from(zipTree(apks.first { it.name.contains("arm64-v8a") })) - into(arm64TempDir) - } - copy { - from(zipTree(apks.first { it.name.contains("x86_64") })) - into(x86TempDir) - } - - val libs = File(aabTempDir, "base/lib").listFiles()!! - - for (dstLibs in libs) { - println("Copying lib: ${dstLibs.name}") - val srcDir = File(apksUnzipped, dstLibs.name) - if (!srcDir.exists()) { - continue - } - val srcLibs = File(srcDir, "lib/${dstLibs.name}/") - - dstLibs.listFiles()!!.forEach { it.delete() } - srcLibs.listFiles()!!.forEach { it.copyTo(File(dstLibs, it.name)) } - } - - val zos = ZipOutputStream(bundleTmp.outputStream()) - val bundleZip = ZipFile(bundle) - val bundleEntries = bundleZip.entries() - - val brotli = findToolInPath("brotli") - ?: throw Exception("Brotli not found in path") - val optipng = findToolInPath("optipng") - ?: throw Exception("Optipng not found in path") - - val indexReadWriteLock = ReentrantReadWriteLock() - val assetIndex = mutableMapOf() - - while (bundleEntries.hasMoreElements()) { - val entry = bundleEntries.nextElement() - - /* -if (entry.name == "base/assets/flutter_assets/assets/firka.i") { - println("Patching: ${entry.name}") - zos.putNextEntry(ZipEntry("assets/flutter_assets/assets/firka.i")) - - val indexUncompressed = File(aabTempDir, "index.json") - indexReadWriteLock.readLock().lock() - val json = groovy.json.JsonBuilder(assetIndex) - indexReadWriteLock.readLock().unlock() - indexUncompressed.writeText(json.toString()) - - val indexCompressed = File(aabTempDir, "index.json.br") - - exec { - commandLine( - brotli, - "-Z", - indexUncompressed.absolutePath, - "-o", indexCompressed.absolutePath - ) - } - - zos.write(indexCompressed.readBytes()) - indexUncompressed.delete() - indexCompressed.delete() - - zos.closeEntry() - continue -} -if (entry.name.startsWith("base/lib")) { - println("Patching: ${entry.name}") - zos.putNextEntry(ZipEntry(entry.name)) - - - - zos.closeEntry() - continue -} -*/ - - println("Adding: ${entry.name}") - - zos.putNextEntry(ZipEntry(entry.name)) - - if (!entry.isDirectory) { - val data = bundleZip.getInputStream(entry).readAllBytes() - zos.write(data) - } - zos.closeEntry() - } - bundleZip.close() - zos.close() - - bundle.delete() - signBundle(bundleTmp, bundle) - bundleTmp.delete() - - aabTempDir.deleteRecursively() - println("AAB transformed successfully") - -} - -fun File.sha256(): String { - val md = MessageDigest.getInstance("SHA-256") - val digest = md.digest(this.readBytes()) - return digest.fold("") { str, it -> str + "%02x".format(it) } -} - -fun getApks(debug: Boolean): List { - val buildDir = project.buildDir - val apkDir = File(buildDir, "outputs/flutter-apk") - val apks = apkDir.listFiles()!! - val flavor = if (debug) { "debug" } else { "release" } - - return apks - .filter { apk -> apk.name.startsWith("app-") && apk.name.endsWith("-$flavor.apk") } - .toList() -} - -fun getDebugKeystorePath(): String { - val userHome = System.getProperty("user.home") - val debugKeystore = File(userHome, ".android/debug.keystore") - - if (!debugKeystore.exists()) { - throw GradleException("Debug keystore not found at: ${debugKeystore.absolutePath}") - } - - return debugKeystore.absolutePath -} - -fun getDefaultAndroidSdkPath(): String? { - val os = System.getProperty("os.name").lowercase() - val userHome = System.getProperty("user.home") - - return when { - os.contains("win") -> - "$userHome\\AppData\\Local\\Android\\Sdk" - os.contains("mac") -> - "$userHome/Library/Android/sdk" - os.contains("linux") -> - "$userHome/Android/Sdk" - else -> null - } -} - -fun findToolInPath(toolName: String): String? { - val pathEnvironment = System.getenv("PATH") - val pathDirs = pathEnvironment.split(File.pathSeparator) - - val executableNames = when { - System.getProperty("os.name").lowercase().contains("win") -> - listOf("$toolName.exe", toolName) - else -> - listOf(toolName) - } - - for (pathDir in pathDirs) { - for (execName in executableNames) { - val possibleTool = File(pathDir, execName) - if (possibleTool.exists() && possibleTool.canExecute()) { - return possibleTool.absolutePath - } - } - } - - return null -} - -fun findToolInSdkPath(toolName: String): String? { - var androidHome : String? = System.getenv("ANDROID_HOME") - ?: System.getenv("ANDROID_SDK_ROOT") - - if (androidHome == null) androidHome = getDefaultAndroidSdkPath() - - if (androidHome != null) { - val buildTools = File(androidHome, "build-tools") - if (buildTools.exists()) { - val latestVersion = buildTools.listFiles() - ?.filter { it.isDirectory } - ?.filter { it.name != "debian" } - ?.maxByOrNull { it.name } - - if (latestVersion != null) { - val toolExec = File(latestVersion, toolName) - if (toolExec.exists()) { - return toolExec.absolutePath - } - } - } - } - - if (!toolName.contains(".exe")) { - val exeTool = findToolInSdkPath("$toolName.exe") - if (exeTool != null) return exeTool - } - if (!toolName.contains(".sh")) { - val shTool = findToolInSdkPath("$toolName.sh") - if (shTool != null) return shTool - } - if (!toolName.contains(".bat")) { - val batTool = findToolInSdkPath("$toolName.bat") - if (batTool != null) return batTool - } - - return null -} - -fun signWithDebugKey(input: File, output: File) { - val debugKeystore = getDebugKeystorePath() - val debugKeystorePassword = "android" - val debugKeyAlias = "androiddebugkey" - val debugKeyPassword = "android" - - val zipAlign: String = findToolInSdkPath("zipalign") - ?: throw Exception("Could not find zipalign in ANDROID_SDK") - val apksigner: String = findToolInSdkPath("apksigner") - ?: throw Exception("Could not find zipalign in ANDROID_SDK") - - exec { - commandLine( - zipAlign, - "-v", "4", - input.absolutePath, - output.absolutePath - ) - } - - exec { - commandLine( - apksigner, "sign", - "--ks", debugKeystore, - "--ks-pass", "pass:$debugKeystorePassword", - "--ks-key-alias", debugKeyAlias, - "--key-pass", "pass:$debugKeyPassword", - output.absolutePath - ) - } - - println("APK signed and aligned successfully") -} - -fun signWithReleaseKey(input: File, output: File) { - val secretsDir = File(projectDir.absolutePath, "../../../secrets/") - val propsFile = File(secretsDir, "keystore.properties") - - if (!propsFile.exists()) { - throw Exception("Release keystore not found!") - } - - val props = loadProperties(propsFile) - - val releaseKeystore = File(secretsDir, props["storeFile"].toString()) - val releaseKeystorePassword = props["storePassword"] as String - val releaseKeyAlias = props["keyAlias"] as String - val releaseKeyPassword = props["keyPassword"] as String - - val zipAlign: String = findToolInSdkPath("zipalign") - ?: throw Exception("Could not find zipalign either in ANDROID_SDK") - val apksigner: String = findToolInSdkPath("apksigner") - ?: throw Exception("Could not find zipalign either in ANDROID_SDK") - - exec { - commandLine( - zipAlign, - "-v", "4", - input.absolutePath, - output.absolutePath - ) - } - - exec { - commandLine( - apksigner, "sign", - "--ks", releaseKeystore, - "--ks-pass", "pass:$releaseKeystorePassword", - "--ks-key-alias", releaseKeyAlias, - "--key-pass", "pass:$releaseKeyPassword", - output.absolutePath - ) - } - - println("APK signed and aligned successfully") -} - -fun signBundle(input: File, output: File) { - val secretsDir = File(projectDir.absolutePath, "../../../secrets/") - val propsFile = File(secretsDir, "keystore.properties") - - if (!propsFile.exists()) { - throw Exception("Release keystore not found!") - } - - val props = loadProperties(propsFile) - - val releaseKeystore = File(secretsDir, props["storeFile"].toString()) - val releaseKeystorePassword = props["storePassword"] as String - val releaseKeyAlias = props["keyAlias"] as String - val releaseKeyPassword = props["keyPassword"] as String - - // val zipAlign: String = findToolInSdkPath("zipalign") - // ?: throw Exception("Could not find zipalign in ANDROID_SDK") - val jarsigner: String = findToolInPath("jarsigner") - ?: throw Exception("Could not find jarsigner in PATH") - - /* - exec { - commandLine( - zipAlign, - "-v", "4", - input.absolutePath, - output.absolutePath - ) - } - */ - input.copyTo(output, true) - - exec { - // -keystore $KEYSTORE -storetype $STORETYPE -storepass $STOREPASS -digestalg SHA1 -sigalg SHA256withRSA application.zip $KEYALIAS - commandLine( - jarsigner, - "-verbose", - "-sigalg", "SHA256withRSA", - "-digestalg", "SHA-256", - "-keystore", releaseKeystore, - "-storepass", releaseKeystorePassword, - output.absolutePath, - releaseKeyAlias - ) - } - - println("AAB signed and aligned successfully") -} \ No newline at end of file diff --git a/firka_wear/pubspec.yaml b/firka_wear/pubspec.yaml index f7bd217..46fc034 100644 --- a/firka_wear/pubspec.yaml +++ b/firka_wear/pubspec.yaml @@ -18,7 +18,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+1011 +version: 1.1.0+2000 environment: sdk: ^3.11.0