2021年4月9日星期五

why change default app name did not work in android productFlavors build with flutter

Now I am using android productFlavors to package app in flutter, this is my command:

~/apps/flutter/bin/flutter build apk --release --flavor prod -t lib/main_pro.dart --no-sound-null-safety  

but the output name is always app-prod-release.apk:

$ ~/apps/flutter/bin/flutter build apk --release --flavor prod -t lib/main_pro.dart --no-sound-null-safety                                                                                             ‹ruby-2.7.2›  Changing current working directory to: /Users/dolphin/source/cruise-open    Building without sound null safety  For more information see https://dart.dev/null-safety/unsound-null-safety    Running Gradle task 'assembleProdRelease'...  Running Gradle task 'assembleProdRelease'... Done                   7.1s  ✓ Built build/app/outputs/flutter-apk/app-prod-release.apk (23.7MB).  (base)  

this is my android/app/build.gradle gradle config:

flavorDimensions 'app'            productFlavors {                prod {                  dimension 'app'                  resValue "string", "app_name", "Cruise"                  manifestPlaceholders = [                          "APP_NAME"    : "cruise-production"                  ]              }          }  

now I want the package name likecruise-prouction-release.apk, not app-prod-release.apk. what should I do to change the defualt package name? I have tries this to change the output package name to releaseApkName.apk:

buildTypes {          release {              signingConfig signingConfigs.debug                android.applicationVariants.all { variant ->                  variant.outputs.all { output ->                      println("releaseApkName")                      output.outputFileName = "releaseApkName.apk"                  }              }          }  }  

but it seems not worked. This is my full config now:

def localProperties = new Properties()  def localPropertiesFile = rootProject.file('local.properties')  if (localPropertiesFile.exists()) {      localPropertiesFile.withReader('UTF-8') { reader ->          localProperties.load(reader)      }  }    def flutterRoot = localProperties.getProperty('flutter.sdk')  if (flutterRoot == null) {      throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")  }    def flutterVersionCode = localProperties.getProperty('flutter.versionCode')  if (flutterVersionCode == null) {      flutterVersionCode = '1'  }    def flutterVersionName = localProperties.getProperty('flutter.versionName')  if (flutterVersionName == null) {      flutterVersionName = '1.0'  }    apply plugin: 'com.android.application'  apply plugin: 'kotlin-android'  apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"    android {      compileSdkVersion 28        sourceSets {          main.java.srcDirs += 'src/main/kotlin'      }        lintOptions {          disable 'InvalidPackage'      }        defaultConfig {          // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).          applicationId "com.earth.dolphin"          minSdkVersion 18          targetSdkVersion 28          versionCode flutterVersionCode.toInteger()          versionName flutterVersionName      }        buildTypes {          release {              signingConfig signingConfigs.debug                android.applicationVariants.all { variant ->                  variant.outputs.all { output ->                      outputFileName = "a.apk"                  }              }          }      }        flavorDimensions 'app'        productFlavors {          dev {              dimension 'app'              resValue "string", "app_name", "Cruise-dev"              applicationIdSuffix '.dev'          }            stage {              dimension 'app'              resValue "string", "app_name", "Cruise-stage"              applicationIdSuffix '.stage'          }            prod {              dimension 'app'              resValue "string", "app_name", "Cruise"          }      }  }    flutter {      source '../..'  }    dependencies {      implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"  }  

the gradle version is 5.6.2. This is the output still using default name:

enter image description here

https://stackoverflow.com/questions/67022346/why-change-default-app-name-did-not-work-in-android-productflavors-build-with-fl April 09, 2021 at 09:49PM

没有评论:

发表评论