【问题标题】:Error when running the command "flutter run"运行命令“flutter run”时出错
【发布时间】:2021-05-04 14:01:38
【问题描述】:

我已经在我的电脑上安装了 android studio,我还安装了 Flutter 和 Dart 插件,但是当我运行“flutter run”时出现这个错误,请帮助我

这是错误

PS C:\Users\Ebenezer Essoun\Desktop\Srrc\workApp> 颤振运行 使用设备 sdk gphone x86 arm 的硬件渲染。如果您注意到图形伪影,请考虑启用软件渲染 “--启用软件渲染”。 以调试模式在 sdk gphone x86 arm 上启动 lib\main.dart... 正在运行 Gradle 任务“assembleDebug”... 运行 Gradle 任务“assembleDebug”...完成 28.0 秒 √ 内置 build\app\outputs\flutter-apk\app-debug.apk。 cmd:找不到服务:活动 安装 build\app\outputs\flutter-apk\app.apk... 1.8s 错误:ADB 以退出代码 1 退出 执行流式安装

adb: 安装失败 C:\Users\Ebenezer Essoun\Desktop\Srrc\workApp\build\app\outputs\flutter-apk\app.apk: cmd: 找不到服务: 包 在 sdk gphone x86 arm 上启动应用程序时出错。

Windows 10 操作系统

【问题讨论】:

    标签: android flutter dart


    【解决方案1】:

    运行命令:

    flutter doctor -v
    

    如果一切正常,则表示这是配置问题。检查您的 android 清单,并确保您已使用正确的意图过滤器设置 MainActivity。它需要一个 ma​​in 意图过滤器,才能启动应用程序。

    还请确保您已遵循 Flutter 文档中的所有要点,并在 Windows 机器上设置 Flutter:

    https://flutter.dev/docs/get-started/install/windows

    然后检查您的 build.gradle 文件(在 app 模块上)并确保它看起来像这样:

    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 = '2'
    }
    
    def flutterVersionName = localProperties.getProperty('flutter.versionName')
    if (flutterVersionName == null) {
        flutterVersionName = '1.1'
    }
    
     def keystoreProperties = new Properties()
       def keystorePropertiesFile = rootProject.file('local.properties')
       if (keystorePropertiesFile.exists()) {
           keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
       }
    
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
    
    android {
    
        compileSdkVersion 30
    
        sourceSets {
            main.java.srcDirs += 'src/main/kotlin'
        }
    
        compileOptions {
          sourceCompatibility 1.8
          targetCompatibility 1.8
        }
    
        defaultConfig {
            applicationId “[YOUR PACKAGE]”
            minSdkVersion 21
            targetSdkVersion 30
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName       
            multiDexEnabled true
        }
    
         signingConfigs {
           release {
               keyAlias keystoreProperties['keyAlias']
               keyPassword keystoreProperties['keyPassword']
               storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
               storePassword keystoreProperties['storePassword']
           }
       }
    
        buildTypes {
            debug {
                signingConfig signingConfigs.debug
            }  
            release {
               signingConfig signingConfigs.release
           }
        }
    
        lintOptions { 
            checkReleaseBuilds false    
        }
    
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    flutter {
        source '../..'
    }
    
    dependencies {
        implementation 'androidx.appcompat:appcompat:1.1.0'
        implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    }
    

    如果您在调试模式下运行,那么您不必担心发布配置,但它会在任何人需要时提供。

    确保您已接受所有 android 许可证。如果有任何问题,颤振医生会告诉你的。

    【讨论】:

    • app 模块上的 build.gradle 文件看起来不像你有的。
    • 然后把你的改成我的样子
    • 请确保遵循 Flutter 文档中的以下几点:
    • 我还假设你的 android 项目是一个基于 kotlin 的项目
    猜你喜欢
    • 1970-01-01
    • 2021-08-29
    • 2018-09-06
    • 2017-12-28
    • 1970-01-01
    • 2020-08-26
    • 1970-01-01
    • 2021-06-11
    • 1970-01-01
    相关资源
    最近更新 更多