為您解碼網(wǎng)站建設(shè)的點(diǎn)點(diǎn)滴滴
發(fā)表日期:2018-12 文章編輯:小燈 瀏覽次數(shù):7342
[TOC]
寫(xiě)在最前面,想玩flutter最好有科學(xué)上網(wǎng)的梯子,否則被墻的整個(gè)人都暴躁了
在目標(biāo)目錄使用git拉取flutter的sdk
# 移動(dòng)到目標(biāo)目錄 cd ${HOME}/env # 拉取sdk git clone https://github.com/flutter/flutter.git
需要提前配置好安卓開(kāi)發(fā)環(huán)境,可以提前配置好jdk,android sdk等環(huán)境變量
需要配置flutter sdk的環(huán)境變量
需要配置flutter的鏡像地址
PUB_HOSTED_URL=https://pub.flutter-io.cn FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
# jdk begin JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home # jdk end # android sdk begin ANDROID_HOME=/Users/rexih/Library/Android/sdk ADB_HOME=/Users/rexih/Library/Android/sdk/platform-tools # android sdk end #android ndk begin NDK_HOME=/Users/rexih/Library/Android/sdk/ndk-bundle CMAKE_HOME=/Users/rexih/Library/Android/sdk/cmake/3.6.4111459 #android ndk end # flutter begin FLUTTER_HOME=/Users/rexih/env/flutter PUB_HOSTED_URL=https://pub.flutter-io.cn FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn # flutter end PATH=$FLUTTER_HOME/bin:$FLUTTER_HOME:$CMAKE_HOME/bin:$ANDROID_HOME/:$ANDROID_HOME/tools:$ADB_HOME:$NDK_HOME:$JAVA_HOME/bin:$PATH:. CLASSPATH=JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:. export JAVA_HOME export ANDROID_HOME export ADB_HOME export NDK_HOME export CMAKE_HOME export PATH export CLASSPATH export FLUTTER_HOME export PUB_HOSTED_URL export FLUTTER_STORAGE_BASE_URL
打開(kāi)as(本文使用的是3.2.1 stable)的plugin,下載插件Flutter
,會(huì)自動(dòng)下載插件Dart
,確保兩個(gè)插件勾選,重啟as
flutter提供doctor
指令幫助用戶診斷開(kāi)發(fā)環(huán)境是否可用,根據(jù)命令行里的診斷結(jié)果逐步修復(fù)即可
第一次運(yùn)行會(huì)自動(dòng)下載Dart SDK
Downloading Dart SDK from Flutter engine# ... Building flutter tool... # ... Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! # ... Doctor summary (to see all details, run flutter doctor -v): # ...
診斷結(jié)果會(huì)告知去設(shè)置Android SDK的環(huán)境變量
診斷結(jié)果會(huì)告知運(yùn)行flutter doctor --android-licenses
通過(guò)licenses以使用
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3) ! Some Android licenses not accepted.To resolve this, run: flutter doctor --android-licenses
診斷結(jié)果會(huì)告知安裝AS插
[!] Android Studio (version 3.2) ? Flutter plugin not installed; this adds Flutter specific functionality. ? Dart plugin not installed; this adds Dart specific functionality.
診斷結(jié)果會(huì)告知運(yùn)行設(shè)備情況
[!] Connected device ! No devices available
診斷結(jié)果會(huì)告知idea和iOS的開(kāi)發(fā)環(huán)境的可用性
國(guó)內(nèi)被墻的很嚴(yán)重。gradle下載太慢了。建議先下載好gradle的對(duì)應(yīng)版本,放置到本地gradle倉(cāng)庫(kù)里,以加快構(gòu)建速度。(移動(dòng)寬帶直接下載也挺慢的)
手動(dòng)下載gradle對(duì)應(yīng)版本。例如下載gradle 4.10.2 地址:https://downloads.gradle.org/distributions/gradle-4.10.2-all.zip,下載完成后放到${HOME}/.gradle/wrapper/dists/gradle-4.10.2-all/9fahxiiecdb76a5g3aw9oi8rv
,解壓,修改文件鎖gradle-4.10.2-all.zip.ok
使用鏡像替代flutter的腳本倉(cāng)庫(kù)。找到flutter sdk的根目錄,打開(kāi)packages/flutter_tools/gradle/flutter.gradle
,修改倉(cāng)庫(kù)地址
buildscript { repositories { 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" } // google() // jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' } }
?
配置好開(kāi)發(fā)環(huán)境后,AS新建項(xiàng)目時(shí)會(huì)增加新的創(chuàng)建選項(xiàng)Start a new Flutter project
設(shè)置項(xiàng)目名稱時(shí),必須遵守其命名規(guī)范,小寫(xiě)加_
下劃線,否則會(huì)提示
Invalid project name: 'T' - must be a valid Dart package name (lower_case_with_underscores)
點(diǎn)擊播放鍵編譯運(yùn)行項(xiàng)目
修改后,不點(diǎn)擊播放鍵,直接ctrl+s
保存一下源文件,發(fā)現(xiàn)設(shè)備上直接同步了修改
- 要查看您的更改, 只需調(diào)用 Save All (
cmd-s
/ctrl-s
), 或點(diǎn)擊 熱重載按鈕 (帶有閃電??圖標(biāo)的按鈕).
flutter devices1 connected device:Android SDK built for x86 ? emulator-5554 ? android-x86 ? Android 9 (API 28) (emulator)
# 查看可用版本 flutter channel # 切換到stable版本 flutter channel stable # 切換版本后再次調(diào)用flutter指令會(huì)重新配置開(kāi)發(fā)環(huán)境 flutter
9212-flutter
6351-dart
查看項(xiàng)目目錄下是否已經(jīng)生成項(xiàng)目文件,如果有,強(qiáng)制關(guān)閉as進(jìn)程,重啟后打開(kāi)此項(xiàng)目
Waiting for another flutter command to release the startup lock…
參見(jiàn)issues 7768
改android里build.gradle腳本的倉(cāng)庫(kù)源
buildscript { repositories { 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' } //google() //jcenter() }dependencies { classpath 'com.android.tools.build:gradle:3.2.1' } }allprojects { repositories { 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' } //google() //jcenter() } }
日期:2018-10 瀏覽次數(shù):7268
日期:2018-12 瀏覽次數(shù):4342
日期:2018-07 瀏覽次數(shù):4889
日期:2018-12 瀏覽次數(shù):4186
日期:2018-09 瀏覽次數(shù):5513
日期:2018-12 瀏覽次數(shù):9935
日期:2018-11 瀏覽次數(shù):4821
日期:2018-07 瀏覽次數(shù):4594
日期:2018-05 瀏覽次數(shù):4867
日期:2018-12 瀏覽次數(shù):4334
日期:2018-10 瀏覽次數(shù):5150
日期:2018-12 瀏覽次數(shù):6226
日期:2018-11 瀏覽次數(shù):4478
日期:2018-08 瀏覽次數(shù):4602
日期:2018-11 瀏覽次數(shù):12653
日期:2018-09 瀏覽次數(shù):5593
日期:2018-12 瀏覽次數(shù):4847
日期:2018-10 瀏覽次數(shù):4201
日期:2018-11 瀏覽次數(shù):4540
日期:2018-12 瀏覽次數(shù):6076
日期:2018-06 瀏覽次數(shù):4017
日期:2018-08 瀏覽次數(shù):5449
日期:2018-10 瀏覽次數(shù):4466
日期:2018-12 瀏覽次數(shù):4545
日期:2018-07 瀏覽次數(shù):4370
日期:2018-12 瀏覽次數(shù):4510
日期:2018-06 瀏覽次數(shù):4398
日期:2018-11 瀏覽次數(shù):4385
日期:2018-12 瀏覽次數(shù):4258
日期:2018-12 瀏覽次數(shù):5296
Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.