|
| 1 | +import java.util.Properties |
| 2 | +import com.android.build.api.variant.FilterConfiguration.FilterType.* |
| 3 | +import org.jetbrains.kotlin.gradle.dsl.JvmTarget |
| 4 | + |
| 5 | +plugins { |
| 6 | + id("com.android.application") |
| 7 | + id("kotlin-android") |
| 8 | + id("dev.flutter.flutter-gradle-plugin") |
| 9 | +} |
| 10 | + |
| 11 | +val localPropertiesFile = rootProject.file("local.properties") |
| 12 | +val localProperties = Properties() |
| 13 | +if (localPropertiesFile.exists()) { |
| 14 | + localProperties.load(localPropertiesFile.inputStream()) |
| 15 | +} |
| 16 | + |
| 17 | +val keystorePropertiesFile = rootProject.file("key.properties") |
| 18 | +val keystoreProperties = Properties() |
| 19 | +if (keystorePropertiesFile.exists()) { |
| 20 | + keystoreProperties.load(keystorePropertiesFile.inputStream()) |
| 21 | +} |
| 22 | + |
| 23 | +kotlin { |
| 24 | + jvmToolchain(21) |
| 25 | + compilerOptions { |
| 26 | + jvmTarget = JvmTarget.JVM_21 |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +android { |
| 31 | + namespace = "com.mateusrodcosta.apps.vidyamusic" |
| 32 | + compileSdk = 35 |
| 33 | + |
| 34 | + defaultConfig { |
| 35 | + applicationId = "com.mateusrodcosta.apps.vidyamusic" |
| 36 | + minSdk = 26 |
| 37 | + //noinspection OldTargetApi |
| 38 | + targetSdk = 34 |
| 39 | + versionCode = flutter.versionCode |
| 40 | + versionName = flutter.versionName |
| 41 | + } |
| 42 | + |
| 43 | + signingConfigs { |
| 44 | + create("release") { |
| 45 | + keyAlias = keystoreProperties["keyAlias"] as String |
| 46 | + keyPassword = keystoreProperties["keyPassword"] as String |
| 47 | + storeFile = file(keystoreProperties["storeFile"] as String) |
| 48 | + storePassword = keystoreProperties["storePassword"] as String |
| 49 | + |
| 50 | + // Always enable v2 and v3 signing schemes, which will be used on modern Android OSes |
| 51 | + enableV2Signing = true |
| 52 | + enableV3Signing = true |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + buildTypes { |
| 57 | + getByName("release") { |
| 58 | + isMinifyEnabled = true |
| 59 | + isShrinkResources = true |
| 60 | + proguardFiles( |
| 61 | + getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" |
| 62 | + ) |
| 63 | + signingConfig = signingConfigs.getByName("release") |
| 64 | + manifestPlaceholders["appName"] = "Vidya Music" |
| 65 | + } |
| 66 | + getByName("debug") { |
| 67 | + applicationIdSuffix = ".debug" |
| 68 | + versionNameSuffix = "-debug" |
| 69 | + manifestPlaceholders["appName"] = "Vidya Music (Debug)" |
| 70 | + } |
| 71 | + getByName("profile") { |
| 72 | + applicationIdSuffix = ".profile" |
| 73 | + versionNameSuffix = "-profile" |
| 74 | + manifestPlaceholders["appName"] = "Vidya Music (Profile)" |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + splits { |
| 79 | + abi { |
| 80 | + isEnable = true |
| 81 | + |
| 82 | + reset() |
| 83 | + //noinspection ChromeOsAbiSupport |
| 84 | + include("armeabi-v7a", "arm64-v8a", "x86_64") |
| 85 | + |
| 86 | + isUniversalApk = true |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + compileOptions { |
| 91 | + sourceCompatibility = JavaVersion.VERSION_21 |
| 92 | + targetCompatibility = JavaVersion.VERSION_21 |
| 93 | + } |
| 94 | + |
| 95 | + packaging { |
| 96 | + // This is set to false starting with minSdk >= 28, but I want uncompressed DEX files with minSdk 26 |
| 97 | + // According to https://developer.android.com/build/releases/past-releases/agp-4-2-0-release-notes#dex-files-uncompressed-in-apks-when-minsdk-=-28-or-higher: |
| 98 | + // |
| 99 | + // > This causes an increase in APK size, but it results in a smaller installation size on the device, and the download size is roughly the same. |
| 100 | + // |
| 101 | + // Currently this makes the APK ~1.4MB heavier |
| 102 | + // |
| 103 | + dex.useLegacyPackaging = false |
| 104 | + resources { |
| 105 | + excludes += "/META-INF/{AL2.0,LGPL2.1}" |
| 106 | + } |
| 107 | + dependenciesInfo { |
| 108 | + // Disables dependency metadata when building APKs, for F-Droid. |
| 109 | + // As instructed in https://github.com/MateusRodCosta/Share2Storage/issues/44 |
| 110 | + includeInApk = false |
| 111 | + } |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +flutter { |
| 116 | + source = "../.." |
| 117 | +} |
| 118 | + |
| 119 | +dependencies { |
| 120 | + implementation("androidx.core:core-splashscreen:1.0.1") |
| 121 | +} |
| 122 | + |
| 123 | +val abiCodes = mapOf("armeabi-v7a" to 1, "arm64-v8a" to 2, "x86_64" to 4) |
| 124 | + |
| 125 | +androidComponents { |
| 126 | + onVariants { variant -> |
| 127 | + |
| 128 | + variant.outputs.forEach { output -> |
| 129 | + val name = output.filters.find { it.filterType == ABI }?.identifier |
| 130 | + |
| 131 | + val baseAbiCode = abiCodes[name] |
| 132 | + |
| 133 | + if (baseAbiCode != null) { |
| 134 | + output.versionCode.set( |
| 135 | + // As required by F-Droid, version code at beginning and abi code at the end |
| 136 | + // If wanting to build a universal APK with similar naming scheme, do so manually |
| 137 | + // via `--build-number` argument from `flutter build apk` |
| 138 | + baseAbiCode * 100 + output.versionCode.get() |
| 139 | + // Default split apk version code, api code at beginning and version code at the end |
| 140 | + //baseAbiVersionCode * 1000 + variant.versionCode |
| 141 | + ) |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | +} |
0 commit comments