Skip to content

Commit

Permalink
Gradle fixes
Browse files Browse the repository at this point in the history
- bump gradle and plugin versions
- add proguard-rules.pro
- fix build of debug apk
- copy apk to dist/ in gradle instead of doit
  • Loading branch information
gavv committed Oct 11, 2024
1 parent b19e73d commit fdecf5a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
33 changes: 26 additions & 7 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.yaml.snakeyaml.Yaml
plugins {
id "com.android.application"
id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
// flutter gradle plugin must be applied after android and kotlin plugins
id "dev.flutter.flutter-gradle-plugin"
}

Expand Down Expand Up @@ -44,10 +44,6 @@ def validateVersion = { ->
def pubspecVersion = readPubspecVersion()
def manifestVersion = readManifestVersion()

project.logger.lifecycle("Checking version name and code...")
project.logger.lifecycle("pubspecVersion = $pubspecVersion")
project.logger.lifecycle("manifestVersion = $manifestVersion")

if (pubspecVersion != manifestVersion) {
throw new GradleException(
"Mismatched versions in pubspec.yaml and AndroidManifest.xml:"+
Expand All @@ -63,7 +59,7 @@ android {
namespace = "org.rocstreaming.rocdroid"

compileSdk = project.compileSdkVersion.toInteger()
ndkVersion = flutter.ndkVersion
ndkVersion = project.ndkVersion

defaultConfig {
applicationId = "org.rocstreaming.rocdroid"
Expand Down Expand Up @@ -107,10 +103,14 @@ android {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt")

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro'

if (System.getenv("SIGNING_STORE_FILE") != null) {
signingConfig signingConfigs.release
} else {
signingConfig = signingConfigs.debug
}
}
}
Expand Down Expand Up @@ -153,3 +153,22 @@ task validateVersionTask {
tasks.matching { it.name.startsWith("assemble") }.configureEach {
dependsOn validateVersionTask
}

// copy apk into dist/android/<variant>/roc-droid-<version>.apk
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
def buildDir = project.layout.buildDirectory.get().asFile.absolutePath
def apk = output.outputFile
if (apk.name == "app-${variant.name}.apk") {
def task = tasks.register("copy${variant.name.capitalize()}Apk", Copy) {
from apk.parent
into "$buildDir/../../dist/android/${variant.name}"
include apk.name
rename { "roc-droid-${readManifestVersion()}.apk" }
}
variant.assembleProvider.configure {
finalizedBy(task)
}
}
}
}
2 changes: 2 additions & 0 deletions android/app/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ compileSdkVersion=34
targetSdkVersion=29
# android 10
minSdkVersion=29
# ndk
ndkVersion=26.1.10909125
1 change: 1 addition & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-dontwarn lombok.Generated
4 changes: 3 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import com.github.jk1.license.render.*

buildscript {
ext {
// must be in-sync with settings.gradle
gradle_plugin_version = "8.4.0"
kotlin_version = "1.8.0"
}

Expand All @@ -11,7 +13,7 @@ buildscript {
}

dependencies {
classpath "com.android.tools.build:gradle:8.0.0"
classpath "com.android.tools.build:gradle:$gradle_plugin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.yaml:snakeyaml:2.2"
}
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
4 changes: 3 additions & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.4.2" apply false
// same as com.android.tools.build:gradle
id "com.android.application" version "8.4.0" apply false
// same as org.jetbrains.kotlin:kotlin-gradle-plugin
id "org.jetbrains.kotlin.android" version "1.8.0" apply false
}

Expand Down
9 changes: 2 additions & 7 deletions dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,7 @@ def task_build_apk():
"""build android apk"""
return {
'basename': 'build:apk',
'actions': [
f'flutter build apk --{VARIANT}',
_copy_file(
f'build/app/outputs/flutter-apk/app-{VARIANT}.apk',
f'dist/android/{VARIANT}/roc-droid-{_android_version()}.apk'
),
],
'actions': [f'flutter build apk --{VARIANT}'],
'title': title_with_actions,
}

Expand All @@ -145,6 +139,7 @@ def task_wipe():
'flutter clean',
_delete_files('android/.gradle'),
_delete_files('android/build'),
_delete_files('dist'),
],
'title': title_with_actions,
}
Expand Down

0 comments on commit fdecf5a

Please sign in to comment.