Skip to content

Commit

Permalink
Merge branch 'flavor-assets-generation-develop' into develop
Browse files Browse the repository at this point in the history
- Generate launcher icons during the build by invoking `icons_launcher` via gradle task
- Remove the previous custom gradle task for generating launcher icons
- Show flavor banner in the app
- Add flavor ribbons to the launcher icons on android
- Add flavor name to the app name
- Remove flavor name from version
- Show flavor name next to the version in the about page
  • Loading branch information
madadam committed Nov 14, 2024
2 parents 7455bca + e7095a7 commit ace58d2
Show file tree
Hide file tree
Showing 30 changed files with 171 additions and 331 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ android/app/src/main/res/mipmap-*dpi/ic_launcher.png
android/app/src/main/res/mipmap-*dpi/ic_launcher_background.png
android/app/src/main/res/mipmap-*dpi/ic_launcher_foreground.png
android/app/src/main/res/mipmap-*dpi/ic_launcher_round.png
android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
android/app/src/main/ic_launcher-playstore.png

ios/Runner/Assets.xcassets/AppIcon.appiconset

# Keystore secrets (we used to have it here, but then moved all the secrets to
# secrets/). Now it is a symbolic link to secrets/android/key.properties, but
Expand Down
162 changes: 58 additions & 104 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id "dev.flutter.flutter-gradle-plugin"
id "com.starter.easylauncher" version "6.4.0"
}

def localProperties = new Properties()
Expand All @@ -26,10 +27,6 @@ android {
disable 'InvalidPackage'
}

// Suffix to append to the application id, name and version. This allows installing multiple
// versions of the app on the same device (e.g., production and development).
def appSuffix = System.getenv("APP_SUFFIX") ?: localProperties.getProperty("app.suffix")

def keystoreProperties = loadKeystorePropertiesFile(System.getenv('STORE_FILE') ?: localProperties['STORE_FILE'])

defaultConfig {
Expand All @@ -44,12 +41,6 @@ android {
versionCode = flutter.versionCode
versionName = flutter.versionName
multiDexEnabled = true

if (appSuffix != null) {
applicationIdSuffix = ".$appSuffix"
versionNameSuffix = "-$appSuffix"
resValue "string", "app_name", "Ouisync $appSuffix"
}
}

signingConfigs {
Expand All @@ -65,24 +56,19 @@ android {
productFlavors {
production {
dimension "releaseType"
applicationIdSuffix applicationIdSuffix
}
nightly {
dimension "releaseType"
applicationIdSuffix appendUnlessNull(".nightly", applicationIdSuffix)
applicationIdSuffix ".nightly"
resValue "string", "app_name", "Ouisync nightly"
}
unofficial {
dimension "releaseType"
applicationIdSuffix appendUnlessNull(".unofficial", applicationIdSuffix)
applicationIdSuffix ".unofficial"
resValue "string", "app_name", "Ouisync unofficial"
}
}

// Flutter building will exit with an incomprehensive error if the flavor
// is not specified. So in this function we do our own check if the
// --flavor parameter was used and tell the user that it needs to be set if
// it's not.
checkFlavorParameter(getCurrentFlavor(), productFlavors)

buildTypes {
release {
if (keystoreProperties != null) {
Expand All @@ -98,70 +84,68 @@ android {
}
}

flutter {
source = "../.."
// Generate launcher icons by invoking [icons_launcher](https://pub.dev/packages/icons_launcher)
tasks.register("generateLauncherIcons", Exec) {
workingDir "${project.rootDir}/.."
// TODO: This generates icons for all platforms. Ideally we would restrict it to generate them
// only for android (and set it up separately in other platforms' respective build systems).
commandLine 'dart', 'run', 'icons_launcher:create'
}

// Generate images in `android/src/main/res/mipmap-*/` based on those in `assets/
task generateResourceImages() {
def images = [
"ic_launcher.png": [
"hdpi": "72x72",
"mdpi": "48x48",
"xhdpi": "96x96",
"xxhdpi": "144x144",
"xxxhdpi": "192x192",
],
"ic_launcher_background.png": [
"hdpi": "162x162",
"mdpi": "108x108",
"xhdpi": "216x216",
"xxhdpi": "324x324",
"xxxhdpi": "432x432",
],
"ic_launcher_foreground.png": [
"hdpi": "162x162",
"mdpi": "108x108",
"xhdpi": "216x216",
"xxhdpi": "324x324",
"xxxhdpi": "432x432",
],
"ic_launcher_round.png": [
"hdpi": "72x72",
"mdpi": "48x48",
"xhdpi": "96x96",
"xxhdpi": "144x144",
"xxxhdpi": "192x192",
],
]

def imagemagick

def Os = org.apache.tools.ant.taskdefs.condition.Os

if (Os.isFamily(Os.FAMILY_WINDOWS)) {
imagemagick = 'magick'
} else {
imagemagick = 'convert'
afterEvaluate {
android.applicationVariants.each { variant ->
tasks.named("generate${variant.name.capitalize()}Assets") {
dependsOn "generateLauncherIcons"
}
}

images.each { file, resolutions ->
resolutions.each { resName, dimensions ->
exec {
// TODO: With these `{in,out}put.file` lines I'd like gradle to not re-generate the output files
// if input files did not change, but changing the paths don't result in an error, so I'm not sure
// the lines do anything useful.
inputs.file "../../assets/$file"
outputs.file "src/main/res/mipmap-$resName/$file"
// PWD is `ouisync-app/android/app/`
commandLine imagemagick, "../../assets/$file", "-resize", dimensions, "src/main/res/mipmap-$resName/$file"
// Flutter building will exit with an incomprehensive error if the flavor is not specified. So
// we do our own check if the --flavor parameter was used and tell the user that it needs to be
// set if it's not.
//
// NOTE: We are injecting this check into the `preBuild` task which is (one of) the first tasks
// run during a build so that this check happens as soon as possible. Also this way it doesn't
// interfere with any non-build tasks (e.g. `clean` or `tasks`, ...).
tasks.named("preBuild") {
doFirst {
android.buildTypes.each { buildType ->
def unflavoredTaskName = "assemble${buildType.name.capitalize()}"

gradle.startParameter.taskNames.each { taskName ->
if (taskName == unflavoredTaskName) {
def flavors = android.productFlavors.collect { it.name }
throw new GradleException("Missing '--flavor=${flavors.join('|')}' argument.")
}
}
}
}
}
}

gradle.projectsEvaluated {
preBuild.dependsOn('generateResourceImages')
flutter {
source = "../.."
}

easylauncher {
defaultFlavorNaming true

productFlavors {
production {
enable false
}

nightly {
filters = [
customRibbon(position: "topRight", ribbonColor: "#FFE65100")
]
}

unofficial {
filters = [
customRibbon(position: "topRight", ribbonColor: "#FF0D47A1")
]
}
}
}

class SigningConfig {
Expand Down Expand Up @@ -195,36 +179,6 @@ def loadKeystorePropertiesFile(String keystorePropertiesPath) {
return config
}

// Check if the user provided the `--flavor=` argument.
def checkFlavorParameter(String currentFlavor, availableFlavors) {
def availableFlavorNames = availableFlavors.collect { it.name }

if (currentFlavor == null) {
if (availableFlavors.empty) {
return
}
throw new GradleException("Missing '--flavor=${availableFlavorNames}' argument.")
}

if (!availableFlavorNames.contains(currentFlavor)) {
throw new GradleException("Unrecognized flavor '${currentFlavor}'. Use one from ${availableFlavorNames}.")
}
}

// Return the current flavor or null.
def getCurrentFlavor() {
String taskRequests = gradle.startParameter.taskRequests.toString()

Pattern pattern = Pattern.compile("(assemble|bundle)(\\w+)(Release|Debug)")
Matcher matcher = pattern.matcher(taskRequests)

if (matcher.find()) {
return matcher.group(2).toLowerCase()
} else {
return null
}
}

def appendUnlessNull(String s1, String s2) {
if (s2 == null) {
return s1
Expand Down
Binary file removed android/app/src/main/ic_launcher-playstore.png
Binary file not shown.
6 changes: 2 additions & 4 deletions icons_launcher.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ icons_launcher:
enable: true
image_path: 'assets/Ouisync_v1_1560x1553.png'
windows:
enable: true
image_path: 'assets/Ouisync_v1_1560x1553.png'
enable: false
linux:
enable: true
image_path: 'assets/Ouisync_v1_1560x1553.png'
enable: false
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
122 changes: 0 additions & 122 deletions ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json

This file was deleted.

Loading

0 comments on commit ace58d2

Please sign in to comment.