vscode创建flutter项目

记录flutter创建运行过程的问题及解决方法

创建flutter项目

1. C + S + p,输入 "flutter", 然后选择 "Flutter: New Project"操作
2. 输入一个项目名称,例如"flutter_myapp", 然后按回车键
3. 创建或者选择一个父文件夹
4. 等待项目创建完成

运行flutter项目

1. 打开安卓模拟器,vscode右下角 `no device` 点击,选择一个模拟器(android studio创建)
2. 命令行输入:flutter run

报错信息及解决

1.Running Gradle task 'assembleDebug'...
  Running Gradle task 'assembleDebug'... Done
在这里卡住了,提示下载要很长时间。
解决:项目文件夹`android`下`build.gradle`文件内容修改如下:
--------------------------------------------------------------------------------------------------------------
buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        // google()     //注释
        // jcenter()     //注释
        // 新增
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        // google()    //注释
        // jcenter()    //注释
        // 新增
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
    }
}

2. A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
   > Your project path contains non-ASCII characters. This will most likely cause the build to fail on Windows. Please move your project to a different directory. See http://b.android.com/95744 for details. This warning can be disabled by adding the line 'android.overridePathCheck=true' 
to gradle.properties file in the project directory.
原因:项目所在路径含有中文或其他`包含非ASCII字符`的字符

3.如果没打开模拟器,就先启动flutter项目,会报一个找不到设备的错误。

启动成功

r Hot reload.
R Hot restart.
h Repeat this help message.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
An Observatory debugger and profiler on Android SDK built for x86 is available at: http://127.0.0.1:55908/xOX9KJhsdt8=/

你可能感兴趣的:(vscode创建flutter项目)