简体   繁体   English

运行命令“flutter run”时出错

[英]Error when running the command “flutter run”

I have installed android studio on my pc and I have also installed flutter and Dart plugin but when I run "flutter run" I get this error, please help me out我已经在我的电脑上安装了 android studio,我还安装了 flutter 和 Dart 插件,但是当我运行“flutter run”时出现此错误,请帮帮我

This is the error这是错误

PS C:\Users\Ebenezer Essoun\Desktop\Srrc\workApp> flutter run Using hardware rendering with device sdk gphone x86 arm. PS C:\Users\Ebenezer Essoun\Desktop\Srrc\workApp> flutter run Using hardware rendering with device sdk gphone x86 arm. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering".如果您注意到图形伪影,请考虑使用“--enable-software-rendering”启用软件渲染。 Launching lib\main.dart on sdk gphone x86 arm in debug mode... Running Gradle task 'assembleDebug'... Running Gradle task 'assembleDebug'... Done 28.0s √ Built build\app\outputs\flutter-apk\app-debug.apk. Launching lib\main.dart on sdk gphone x86 arm in debug mode... Running Gradle task 'assembleDebug'... Running Gradle task 'assembleDebug'... Done 28.0s √ Built build\app\outputs\flutter-apk\应用程序调试.apk。 cmd: Can't find service: activity Installing build\app\outputs\flutter-apk\app.apk... 1.8s Error: ADB exited with exit code 1 Performing Streamed Install cmd:找不到服务:活动正在安装 build\app\outputs\flutter-apk\app.apk... 1.8s 错误:ADB exited with exit code 1 Performing Streamed Install

adb: failed to install C:\Users\Ebenezer Essoun\Desktop\Srrc\workApp\build\app\outputs\flutter-apk\app.apk: cmd: Can't find service: package Error launching application on sdk gphone x86 arm. adb: failed to install C:\Users\Ebenezer Essoun\Desktop\Srrc\workApp\build\app\outputs\flutter-apk\app.apk: cmd: Can't find service: package Error launching application on sdk gphone x86 arm .

windows 10 Operating system windows 10 操作系统

Run the command:运行命令:

flutter doctor -v

If everything looks good, then it means that it's a configuration issue.如果一切看起来都很好,那么这意味着这是一个配置问题。 Check your android manifest, and make sure that you have set your MainActivity with the proper intent filters.检查您的 android 清单,并确保您已使用正确的意图过滤器设置 MainActivity。 It needs a main intent filter, in order to launch the app.它需要一个主要的意图过滤器才能启动应用程序。

Please also make sure that you have followed all the points in the flutter documentation, and setting up flutter on a windows machine:另请确保您已遵循 flutter 文档中的所有要点,并在 windows 机器上设置 flutter:

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

Then check your build.gradle file (on the app module) and make sure that it looks like this:然后检查您的 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 = '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"
}

If you are running in debug mode, then you should not worry about release configurations, but it's there in case anyone needs it.如果您在调试模式下运行,那么您不应该担心发布配置,但它存在以防万一有人需要它。

Make sure that you have accepted all android licences.确保您已接受所有 android 许可证。 If there are any issues, then the flutter doctor will tell you about it.如果有任何问题,那么 flutter 医生会告诉你的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM