Android Studio中创建第一个Flutter项目

一、Flutter环境验证

创建Flutter项目之前需要验证是否有Flutter环境,如没有Flutter 环境,请参考配置Flutter开发环境

1.1、flutter doctor

验证通过会有以下提示

复制代码
[√] Flutter (Channel stable, 3.29.3, on Microsoft Windows [版本 10.0.19045.5737], locale zh-CN)
[√] Windows Version (10 专业版 64 位, 22H2, 2009)
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[√] Chrome - develop for the web
[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2023.3)
[√] Android Studio (version 2024.3)
[√] Android Studio (version 4.2)
[√] IntelliJ IDEA Community Edition (version 2024.2)
[√] Connected device (3 available)
[√] Network resources

如没有Flutter 环境,请参考配置Flutter开发环境

1.2、Android Studio中配置Dart和Flutter插件

在Android Studio →Setting→Plugins中查看是否有Dart和Flutter插件

如没有,请先安装Dart和Flutter插件,安装完成后重启Android Studio

二、Android Studio中创建第一个Flutter项目

File → New → New Flutter Project...

设置Flutter SDK Path

输入项目名称和包名,支持的平台选择Android和iOS

创建完成

运行项目

提示报错信息如下:

复制代码
Exception in thread "main" java.util.zip.ZipException: zip END header not found
	at java.base/java.util.zip.ZipFile$Source.findEND(Unknown Source)
	at java.base/java.util.zip.ZipFile$Source.initCEN(Unknown Source)
	at java.base/java.util.zip.ZipFile$Source.<init>(Unknown Source)
	at java.base/java.util.zip.ZipFile$Source.get(Unknown Source)
	at java.base/java.util.zip.ZipFile$CleanableResource.<init>(Unknown Source)
	at java.base/java.util.zip.ZipFile.<init>(Unknown Source)
	at java.base/java.util.zip.ZipFile.<init>(Unknown Source)
	at java.base/java.util.zip.ZipFile.<init>(Unknown Source)
	at org.gradle.wrapper.Install.unzip(Install.java:214)
	at org.gradle.wrapper.Install.access$600(Install.java:27)
	at org.gradle.wrapper.Install$1.call(Install.java:74)
	at org.gradle.wrapper.Install$1.call(Install.java:48)
	at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
	at org.gradle.wrapper.Install.createDist(Install.java:48)
	at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
	at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Error: Gradle task assembleDebug failed with exit code 1

在android文件夹中修改gradle镜像地址

复制代码
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.9-all.zip

修改java sdk ,选择jdk17

提示NDK错误

A problem occurred configuring project ':app'.

NDK not configured. Download it with SDK manager. Preferred NDK version is '27.0.12077973'.

在android →build.gradle.kts中注释ndkVersion

复制代码
//    ndkVersion = flutter.ndkVersion

重新运行,安装到手机里,就可以看到首页了

相关推荐
HH思️️无邪6 小时前
Flutter 开发技巧 AI 快速构建 json_annotation model 的提示词
flutter·json
雨白10 小时前
Drawable 与 Bitmap 的区别、互转与自定义
android
程序员江同学10 小时前
Kotlin 技术月报 | 2025 年 8 月
android·kotlin
nju永远得不到的男人11 小时前
关于virtual camera
android
笔沫拾光11 小时前
hooks_riverpod框架解析
flutter·hooks·hooks_riverpod
雨白13 小时前
Android 自定义 View:属性动画和硬件加速
android
problc14 小时前
Flutter桌面应用实战:Windows系统代理切换工具开发
windows·flutter
hellokai14 小时前
React Native新架构源码分析
android·前端·react native
真西西14 小时前
Koin:Kotlin轻量级依赖注入框架
android·kotlin
程序员老刘15 小时前
Cursor vs Claude Code vs AS+AI助手:谁才是客户端的编程神器?
flutter·ai编程·客户端