如何从发布模式切换到调试模式

时间:2021-05-24 09:42:14

标签: flutter android-studio

我最近构建了一个发布版本以在 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

如何从发布模式切换回调试模式?

1 个答案:

答案 0 :(得分:0)

在 android studio 中,垂直侧窗格上有一个“构建变体”选项卡,您可以在那里更改正在构建的当前配置。

首先确保 build.gradle 包含构建配置。否则,通过引用 gradle 文档添加新配置或由您自己编写(如果您知道),或者从包含 'debug' build config 的项目中提取。

请参阅所附图片。enter image description here