搭建開發(fā)環(huán)境
學(xué)完dart語言的基礎(chǔ),接著就是開發(fā)環(huán)境啦:
1.下載SDK
2.下載好了解壓到xxx目錄下
3.配置環(huán)境變量
$vim ~/.bash_profile
添加下面幾行
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=xxx/flutter/bin:$PATH
export PATH=${PATH}:xxx/flutter/bin/cache/dart-sdk
更新一下配置
source ~/.bash_profile
4.經(jīng)過上面幾步,flutter已經(jīng)在mac安家了,flutter相關(guān)命令也可以使用了,如
flutter doctor
flutter -h (查看flutter命令的一下幫助)
flutter --version(注意是 --version 查看flutter版本)
flutter upgrade (flutter升級)
5.編譯器
作為iOS開發(fā)者,xcode就無需擔(dān)心了,需要安裝Android Studio、VS Code、Chrome以方便寫代碼和調(diào)試、打包。
開發(fā)我推薦VSCode,開始開發(fā)之前在插件市場安裝好flutter同名插件。
6.啟動與調(diào)試
6.1 新建一個flutter項目:VSCode中cmd+shift+p選擇Flutter: New Application Project即可新建一個flutter應(yīng)用。
6.2 作為iOScoder順序第一的肯定先啟動iOS端,vc底部選擇你連接好的iPhone,選擇運行->啟動調(diào)試(在ios項目中配置配置好了bundle ID和證書),很順利的手機上已經(jīng)打開了demo

6.3 運行安卓程序
android studio運行項目會進行下載相關(guān)支持,然后卡在kotlin-compiler-embeddable-1.6.10.jar上,這里可以使用阿里的鏡像,具體的,在目錄
/Users/xx用戶/.gradle
中新建一個init.gradle文件,里面內(nèi)容
allprojects{
repositories {
def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/central/'
def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/public/'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
url 'https://maven.aliyun.com/repository/google/'
url 'https://maven.aliyun.com/repository/gradle-plugin/'
}
}
buildscript{
repositories {
def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/central/'
def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/public/'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
url 'https://maven.aliyun.com/repository/google/'
url 'https://maven.aliyun.com/repository/gradle-plugin/'
}
}
}
}
等下載完成再運行又出現(xiàn)
FAILURE: Build failed with an exception. * What went wrong: A problem was found with the configuration of task ':app:processDebugResources' (type 'LinkApplicationAndroidResourcesTask'). - In plugin 'com.android.internal.version-check' type 'com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask' property 'androidJarInput.androidJar' specifies file '/Users/xxx/Library/Android/sdk/platforms/android-31/android.jar' which doesn't exist.
打開as的SDK Manager,選擇安裝andriud-31。
再次執(zhí)行flutter run又出現(xiàn)adb: failed to install apk,原因是安卓模擬器安裝了其他APP,內(nèi)存不夠,我卸載了再運行就好了。
6.4 運行在Chrome上,很順利
Launching lib/main.dart on Chrome in debug mode...
lib/main.dart:1
This app is linked to the debug service: ws://127.0.0.1:51257/utBPASg7syU=/ws
Debug service listening on ws://127.0.0.1:51257/utBPASg7syU=/ws
?? Running with sound null safety ??
Connecting to VM Service at ws://127.0.0.1:51257/utBPASg7syU=/ws
Flutter Web Bootstrap: Programmatic
接下來就可以真正進行服啦特實戰(zhàn)了!本文over!