修改 android/app/build.gradle 文件,如下所示
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 flutter.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
// print(${flutterVersionName});
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "YourPackageName"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
applicationVariants.all { variant ->
variant.outputs.all {
def appName = 'YourCustomAppName' // 替换为实际自定义应用名
def buildType = variant.buildType.name
def versionName = variant.versionName
// 输入结果如:YourCustomAppName-1.0.0-release.apk
outputFileName = "${appName}-${versionName}-${buildType}.apk"
println(" L Terminal Run : cd "+ rootProject.buildDir + "/app/outputs/apk/${buildType}/" + " file: ${outputFileName}")
}
}
}
flutter {
source '../..'
}
将applicationId 修改成你的包名,将appName 修改成你的应用名。