【发布时间】:2021-05-24 09:42:14
【问题描述】:
我最近构建了一个发布版本以在 Android Play 商店上进行测试。问题是我无法让它回到调试模式。当我尝试在调试模式下启动时,这是我在控制台上收到的消息:
Launching lib\main.dart on SM P585 in release mode...
Running Gradle task 'assembleRelease'..
这是我的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 FileNotFoundException("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 29
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.example.my_app"
minSdkVersion 18
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
dependencies {
implementation 'com.android.support:multidex:1.0.3' //enter the latest version
}
android {
defaultConfig {
multiDexEnabled true
}
}
但是,local.properties 告诉我 Flutter 仍处于发布模式:
sdk.dir=C:/Users/USER/AppData/Local/Android/Sdk
flutter.sdk=C:\\flutter
flutter.buildMode=release
flutter.versionName=1.0.0
flutter.versionCode=1
如何从发布模式切换回调试模式?
【问题讨论】:
-
在 android studio 中,在垂直侧窗格中有一个“构建变体”选项卡,您可以在那里更改当前正在构建的配置。
-
@mahee96 当我选择它时,它显示“Nothing to Show”。
-
看到这个,buildTypes { release { // TODO:为发布构建添加你自己的签名配置。 // 现在使用调试密钥签名,所以
flutter run --release有效。 signingConfig signingConfigs.debug } 这也应该包含调试配置 -
尝试在目录中使用flutter clean命令。
-
@mahee96 我已经在上面的代码中为
build.gradle尝试过。但它不起作用。