flutter安装 android studio,windows

mac环境下几个注意点:
报错: CocoaPods installed but not initialized

#安装cocoapods
$ sudo gem install cocoapods -v 1.7.5  
$ pod setup 下载太慢了.切换国内下载源
$ cd ~/.cocoapods/repos
$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master

报错: Waiting for another flutter command to release the startup lock

$ rm -f ${flutterROOT}/bin/cache/lockfile
准备环境2:

windows环境

  1. 下载flutter

https://storage.googleapis.com/flutter_infra/releases/stable/windows/flutter_windows_v1.12.13+hotfix.9-stable.zip

  1. 下载android安装包,并完成安装工作
  2. 解压flutter安装包,

到相应目录,把当前目前添加系统环境变量path中,并且新建模拟器准备好

  1. 命令行 $flutter doctor
    显示一堆的叉叉,接下来开始解决叉叉

Q1: Some Android licenses not accepted
A:运行 $ flutter doctor --android-licenses 即可
Q2: 显示X Unable to locate Android SDK
A: android studio的环境变量 ANDROID_HOME 未配置(也就是安装studio时设置的SDK目录)
Q3: Flutter plugin not installed
A: Android studio安装flutter插件第一步:file ——》settings ——》Plugins ,搜索flutter;点击Install进行安装,安装过程中会有弹出窗口提示是否安装Dart,勾选安装Dart

最后再运行
$ flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 6.1.7601], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Android Studio (version 3.2)
[!] Connected device
    ! No devices available
  1. vscode 运行项目
    设置-> Command Palete -> $flutter -> new project
[first_app] flutter create --ios-language swift --android-language kotlin .
Waiting for another flutter command to release the startup lock...
Creating project .... androidx: true
  .gitignore (created)
  .idea\libraries\Dart_SDK.xml (created)
  .idea\libraries\Flutter_for_Android.xml (created)
  .idea\libraries\KotlinJavaRuntime.xml (created)
  .idea\modules.xml (created)
  .idea\runConfigurations\main_dart.xml (created)
  .idea\workspace.xml (created)
  .metadata (created)
  android\app\build.gradle (created)
  android\app\src\main\kotlin\com\example\first_app\MainActivity.kt (created)
  android\build.gradle (created)
  android\first_app_android.iml (created)
  android\.gitignore (created)
  android\app\src\debug\AndroidManifest.xml (created)
  android\app\src\main\AndroidManifest.xml (created)
  android\app\src\main\res\drawable\launch_background.xml (created)
  android\app\src\main\res\mipmap-hdpi\ic_launcher.png (created)
  android\app\src\main\res\mipmap-mdpi\ic_launcher.png (created)
  android\app\src\main\res\mipmap-xhdpi\ic_launcher.png (created)
  android\app\src\main\res\mipmap-xxhdpi\ic_launcher.png (created)
  android\app\src\main\res\mipmap-xxxhdpi\ic_launcher.png (created)
  android\app\src\main\res\values\styles.xml (created)
  android\app\src\profile\AndroidManifest.xml (created)
  android\gradle\wrapper\gradle-wrapper.properties (created)
  android\gradle.properties (created)
  android\settings.gradle (created)
  ios\Runner\AppDelegate.swift (created)
  ios\Runner\Runner-Bridging-Header.h (created)
  ios\Runner.xcodeproj\project.pbxproj (created)
  ios\Runner.xcodeproj\xcshareddata\xcschemes\Runner.xcscheme (created)
  ios\.gitignore (created)
  ios\Flutter\AppFrameworkInfo.plist (created)
  ios\Flutter\Debug.xcconfig (created)
  ios\Flutter\Release.xcconfig (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Contents.json (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-1024x1024@1x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-20x20@1x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-20x20@2x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-20x20@3x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-29x29@1x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-29x29@2x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-29x29@3x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-40x40@1x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-40x40@2x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-40x40@3x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-60x60@2x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-60x60@3x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-76x76@1x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-76x76@2x.png (created)
  ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-83.5x83.5@2x.png (created)
  ios\Runner\Assets.xcassets\LaunchImage.imageset\Contents.json (created)
  ios\Runner\Assets.xcassets\LaunchImage.imageset\LaunchImage.png (created)
  ios\Runner\Assets.xcassets\LaunchImage.imageset\LaunchImage@2x.png (created)
  ios\Runner\Assets.xcassets\LaunchImage.imageset\LaunchImage@3x.png (created)
  ios\Runner\Assets.xcassets\LaunchImage.imageset\README.md (created)
  ios\Runner\Base.lproj\LaunchScreen.storyboard (created)
  ios\Runner\Base.lproj\Main.storyboard (created)
  ios\Runner\Info.plist (created)
  ios\Runner.xcodeproj\project.xcworkspace\contents.xcworkspacedata (created)
  ios\Runner.xcworkspace\contents.xcworkspacedata (created)
  lib\main.dart (created)
  first_app.iml (created)
  pubspec.yaml (created)
  README.md (created)
  test\widget_test.dart (created)
Running "flutter pub get" in first_app...                          96.2s
Wrote 68 files.

All done!
[√] Flutter: is fully installed. (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 6.1.7601], locale zh-CN)
[√] Android toolchain - develop for Android devices: is fully installed. (Android SDK version 29.0.3)
[√] Android Studio: is fully installed. (version 3.2)
[!] Connected device: is not available.

Run "flutter doctor" for information about installing additional components.

In order to run your application, type:

  $ cd .
  $ flutter run

Your application code is in .\lib\main.dart.

exit code 0
  1. 设置国内镜像

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

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 6.1.7601], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Android Studio (version 3.2)
[√] Connected device (1 available)

• No issues found!
  1. 首次运行app,

等了将近二十分钟,才build成功,中间各种改gradle的镜像地址,好像没起作用

https://blog.csdn.net/weixin_38166686/article/details/102170136 gradle镜像地址

修正 :
运行如下命令,可以看到配置的gradle镜像地址生效了,慢还是慢了点,不过总归是正常了

$ flutter run -v 

PS: 请耐心等待
Launching lib\main.dart on AOSP on IA Emulator in debug mode…
Running Gradle task ‘assembleDebug’.

PS: 完成后显示如下,运行成功了

Launching lib\main.dart on AOSP on IA Emulator in debug mode...
√ Built build\app\outputs\apk\debug\app-debug.apk.
D/FlutterActivity( 6301): Using the launch theme as normal theme.
D/FlutterActivityAndFragmentDelegate( 6301): Setting up FlutterEngine.
D/FlutterActivityAndFragmentDelegate( 6301): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.
D/FlutterActivityAndFragmentDelegate( 6301): Attaching FlutterEngine to the Activity that owns this Fragment.
D/FlutterView( 6301): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@d3dd791
D/FlutterActivityAndFragmentDelegate( 6301): Executing Dart entrypoint: main, and sending initial route: /
I/OpenGLRenderer( 6301): Initialized EGL, version 1.4
D/OpenGLRenderer( 6301): Swap behavior 1
D/HostConnection( 6301): HostConnection::get() New Host Connection established 0xe9d27170, tid 6348
D/HostConnection( 6301): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
W/OpenGLRenderer( 6301): Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer( 6301): Swap behavior 0
D/eglCodecCommon( 6301): setVertexArrayObject: set vao to 0 (0) 0 0
D/EGL_emulation( 6301): eglCreateContext: 0xe8b64340: maj 3 min 0 rcv 3
D/EGL_emulation( 6301): eglMakeCurrent: 0xe8b64340: ver 3 0 (tinfo 0xe8b665b0)
D/HostConnection( 6301): HostConnection::get() New Host Connection established 0xeb53c140, tid 6335
D/HostConnection( 6301): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
D/eglCodecCommon( 6301): setVertexArrayObject: set vao to 0 (0) 0 0
D/EGL_emulation( 6301): eglCreateContext: 0xeb505420: maj 3 min 0 rcv 3
D/HostConnection( 6301): createUnique: call
D/HostConnection( 6301): createUnique: call
D/HostConnection( 6301): HostConnection::get() New Host Connection established 0xeb53c190, tid 6335
D/HostConnection( 6301): HostConnection::get() New Host Connection established 0xe9d293d0, tid 6348
D/HostConnection( 6301): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
E/eglCodecCommon( 6301): GoldfishAddressSpaceHostMemoryAllocator: ioctl_ping failed for device_type=5, ret=-1
D/HostConnection( 6301): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
D/EGL_emulation( 6301): eglMakeCurrent: 0xeb505420: ver 3 0 (tinfo 0xeb5033d0)
I/Choreographer( 6301): Skipped 73 frames!  The application may be doing too much work on its main thread.
D/EGL_emulation( 6301): eglMakeCurrent: 0xe8b64340: ver 3 0 (tinfo 0xe8b665b0)
D/eglCodecCommon( 6301): setVertexArrayObject: set vao to 0 (0) 1 2
I/OpenGLRenderer( 6301): Davey! duration=1721ms; Flags=1, IntendedVsync=2548965940924, Vsync=2550182607542, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=2550192064810, AnimationStart=2550192209170, PerformTraversalsStart=2550201986470, DrawStart=2550238378650, SyncQueued=2550239105390, SyncStart=2550241837040, IssueDrawCommandsStart=2550244801880, SwapBuffers=2550267366040, FrameCompleted=2550689735110, DequeueBufferDuration=314898000, QueueBufferDuration=82137000,
D/EGL_emulation( 6301): eglMakeCurrent: 0xeb505420: ver 3 0 (tinfo 0xeb5033d0)
D/eglCodecCommon( 6301): setVertexArrayObject: set vao to 0 (0) 1 0
  1. 导入已有的项目

$ flutter pub get
$ flutter run -v
问题一:
因为项目引入其它项目(plugins\xxx_xxx)
pubspec.lock文件里引了如下的一个外部项目,需要把这个项目拉下来到plugins/目录下

packages:
  xxx_xxx:
    dependency: "direct main"
    description:
      path: "plugins\\xxx_xxx"
      relative: true
    source: path
    version: "0.0.1"

问题二:
Error: ADB exited with exit code 1
Performing Streamed Install

贴人家的地址,就是模拟器的usb调试模式的问题

https://www.cnblogs.com/skygxk/p/12371215.html

问题三:

FAILURE: Build failed with an exception.
* Where:
Build file 'D:\flutter\.pub-cache\hosted\pub.flutter-io.cn\connectivity_macos-0.1.0+2\android\build.gradle' line: 22
* What went wrong:
A problem occurred evaluating root project 'connectivity'.
> Failed to apply plugin [id 'com.android.library']
    > Minimum supported Gradle version is 5.4.1. Current version is 4.10.2. If using the gradle wrapper, try editing the distributionUrl in
    D:\flutter\.pub-cache\hosted\pub.flutter-io.cn\connectivity_macos-0.1.0+2\android\gradle\wrapper\gradle-wrapper.properties to gradle-5.4.1-all.zip

切换到flutter目录下
${FLUTTER_ROOT}.pub-cache\hosted\pub.flutter-io.cn\connectivity_macos-0.1.0+2\android\build.gradle
修改gradle版本

问题四:

D:\flutter\.pub-cache\hosted\pub.flutter-io.cn\flutter_plugin_android_lifecycle-1.0.7\android\src\main\java\io\flutter\embedding\engine\plugins\lifecycle\FlutterLifecycleAdapter.java:8: 错误:
程序包androidx.lifecycle不存在
           import androidx.lifecycle.Lifecycle;
                                    ^
           D:\flutter\.pub-cache\hosted\pub.flutter-io.cn\flutter_plugin_android_lifecycle-1.0.7\android\src\main\java\io\flutter\embedding\engine\plugins\lifecycle\FlutterLifecycleAdapter.java:2
           2: 错误: 找不到符号
             public static Lifecycle getActivityLifecycle(
                           ^
             符号:   类 Lifecycle
             位置: 类 FlutterLifecycleAdapter
           2 个错误

切换到项目目录下
${PROJECT_ROOT}/android/app/build.gradle
添加如下内容

configurations.all {
    resolutionStrategy {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'androidx.core') {
                details.useVersion "1.0.2"
            }
            if (details.requested.group == 'androidx.lifecycle') {
                details.useVersion "2.0.0"
            }
            if (details.requested.group == 'androidx.versionedparcelable') {
                details.useVersion "1.0.0"
            }
            if (details.requested.group == 'androidx.fragment') {
                details.useVersion "1.0.0"
            }
            if (details.requested.group == 'androidx.appcompat') {
                details.useVersion "1.0.1"
            }
        }
    }
}

贴人家的地址

https://blog.csdn.net/luoboo525/article/details/104192243

最后运行结果:

$ flutter run
Launching lib\main.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...                             26.0s
√ Built build\app\outputs\apk\debug\app-debug.apk.
Syncing files to device sdk gphone x86...
I/n.meyoung.mytm( 7083): Background young concurrent copying GC freed 16508(1233KB) AllocSpace objects, 1(20KB) LOS objects, 95% free, 1149KB/25MB, paused 12.287ms total 56.092ms
D/EGL_emulation( 7083): eglMakeCurrent: 0xef467060: ver 3 0 (tinfo 0xef4fa5b0)
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
I/flutter ( 7083): null
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
I/flutter ( 7083): http post: http://127.0.0.1:8080/app, {type: 1, fromapp: 1}
I/flutter ( 7083): {code: 0, message: success, result: {version: 2.0.0, remark: APP

I/flutter ( 7083): , url: http://127.0.0.1:8081/file/apk/app-release.apk, created: 2019-11-12T06:21:27Z}}
Syncing files to device sdk gphone x86...                        8,123ms (!)

🔥  To hot reload changes while running, press "r". To hot restart (and rebuild state), press "R".
An Observatory debugger and profiler on sdk gphone x86 is available at: http://127.0.0.1:64689/ELA99duIvcQ=/
For a more detailed help message, press "h". To detach, press "d"; to quit, press "q".
PS: 按q退出

D/skia    ( 7083): Shader compilation error
D/skia    ( 7083): ------------------------
D/skia    ( 7083): Errors:
D/skia    ( 7083):
D/EGL_emulation( 7083): eglMakeCurrent: 0xef465620: ver 3 0 (tinfo 0xef4fe770)
W/System  ( 7083): A resource failed to call release.
I/chatty  ( 7083): uid=10148(cn.meyoung.mytms) FinalizerDaemon identical 2 lines
W/System  ( 7083): A resource failed to call release.

Application finished.

再推荐两篇文章
源码解读Flutter run机制
Flutter 内幕:Flutter 在内部是如何工作的?
最后还得感谢github,stackoverflow
https://github.com
https://stackoverflow.com

PS: flutter是个坑

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值