Windows平台下Flutter开发环境搭建

flutterchina:https://flutterchina.club/get-started/
flutter-io:https://flutter-io.cn

环境变量

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

export PATH=$PATH:$FLUTTER_HOME/bin

Android Studio安装flutter插件

Flutter基本命令

双击运行:E:\Flutter\flutter_windows_v1.0.0-stable\flutter\flutter_console.bat

E:\Flutter\flutter_windows_v1.0.0-stable\flutter>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.0.0, on Microsoft Windows [Version 10.0.15063], locale zh-CN)
[!] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[√] Android Studio (version 3.2)
[!] IntelliJ IDEA Ultimate Edition (version 2017.3)
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
[√] Connected device (1 available)

! Doctor found issues in 2 categories.

E:\Flutter\flutter_windows_v1.0.0-stable\flutter>flutter devices
1 connected device:

Redmi Note 4X • 2045550d0304 • android-arm64 • Android 7.0 (API 24)

E:\Flutter\flutter_windows_v1.0.0-stable\flutter>

创建项目

创建项目:File -> New Flutter Project -> Flutter Application -> 在Flutter SDK path中选择SDK安装路径(指向到顶层Flutter目录即可,不需要到bin目录),不要点击Install SDK...

卡在Creating Flutter Project

如果等了5分钟还是卡在Creating Flutter Project,打开项目目录,其实项目已经创建好了,AS只是假死。

解决:直接强杀AS,然后重新打开,open项目,注意直接选择open,而不是import!!直接open项目顶层目录,而不是内部子android目录。

卡在Initializing gradle...

(1)flutter.gradle

修改:$FLUTTER_HOME/flutter/packages/flutter_tools/gradle/flutter.gradle

点评:切换阿里云镜像,不翻墙可以使用此方法,但仍需等待下载时间

buildscript {
    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.2.1'
    }
}

(2)gradle-wrapper.properties

修改:android/gradle/wrapper/gradle-wrapper.properties

点评:使用Android Studio自带gradle版本,无需下载

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

(3)手动下载指定gradle版本

手动下载Flutter指定的gradle版本,如gradle-4.10.2-all.zip

下载地址:https://services.gradle.org/distributions/

首先编译运行项目,执行Initializing gradle...,生成gradle下载目录,如$FLUTTER_HOME/.gradle/wrapper/dists/gradle-4.10.2-all/9fahxiiecdb76a5g3aw9oi8rv

然后首先停止编译项目,手动下载gradle-4.10.2-all.zip,并放置于该目录下,同时创建两个空文件gradle-4.10.2-all.zip.lckgradle-4.10.2-all.zip.ok

最后重新编译运行项目,即可看到自动解压手动下载的gradle-4.10.2-all.zip

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/16/build-flutter-development-environment-on-windows-platform/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Windows平台下Flutter开发环境搭建
flutterchina:https://flutterchina.club/get-started/ flutter-io:https://flutter-io.cn 环境变量 export PUB_HOSTED_URL=https://pub.flutter-io.cn exp……
<<上一篇
下一篇>>
文章目录
关闭
目 录