1.Could not download kotlin-reflect.jar / Could not download kotlin-reflect.jar
對於不能下載jar的問題,最主要是切換到穩定版本,然後配置阿里雲映象
關注flutter 版本
切換到stable版本,beta版本會存在一些不穩定問題 flutter channel stable && flutter upgrade flutter clean flutter run
修改兩個地方:
- 專案下android/build.gradle
buildscript {
ext.kotlin_version = '1.3.72'
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' }
maven {
url 'http://download.flutter.io'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
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' }
maven {
url 'http://download.flutter.io'
}
}
}
複製程式碼
2.flutter安裝包下 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' }
maven {
url 'http://download.flutter.io'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}
複製程式碼
2.Flutter Waiting for another flutter command to release the startup lock...
- 解決方法:開啟 flutter/bin/cache/,刪除lockfile。
- 原因:強行關閉AndroidStudio後,再次進入專案,出現。
- 如果出現AndroidStudio 手機模擬器連線狀態 一直顯示Loading,也可以嘗試這種方法解決。
3.The current Dart SDK version is 2.4.0.
升級dio到3.0+時,dart版本過低了,報瞭如下錯誤: The current Dart SDK version is 2.4.0.
Because estate_app depends on dio >=3.0.0-dev.1 which requires SDK version >2.4.0 <3.0.0, version solving failed. pub get failed (1)
解決方法:
- fluttersdk中自帶來dart,位置:/Library/flutter/bin/cache/dart-sdk
- 命令列 cd flutter\bin\cache\dart-sdk
4.Flutter使用HttpClient發起請求時,報錯Failed host lookup: 'www.abc.com' (OS Error: No address associated w...
我用的是android模擬器,api使用的是HttpClient,填寫好各種url、header、body:
- 首先,檢查手機、模擬器所在的電腦是否真的聯網了。
- 發出請求後,什麼反應都沒有,很有可能是沒有在Android的manifest中配置網路許可權
android/app/src/main/AndroidManifest.xml
- 發出請求後,出現Failed host lookup: 'www.abc.com' (OS Error: No address associated with hostname, errno = 7)
解除安裝app,殺掉模擬器,重新啟動模擬器,重新安裝app。我的就可以了。
5.AndroidStudio下載慢
build.gradle裡的buildscript和allprojects新增阿里映象,非是app裡的build.gradle。同時把Google和Jcenter給註釋
repositories { maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} }
6.No material widget found textfield widgets require a material widget
使用TextField時遇到的問題,只需要在TextField或其父祖widget上包一層Material即可。 如:
Material(
borderRadius: BorderRadius.circular(15),
child:
Container(
margin: EdgeInsets.symmetric(horizontal: 20,vertical: 20),
height: 60,
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: Colors.grey)
),
counterText: '',
prefixIcon: Icon(Icons.phone),
hintText: "使用者名稱",
hintStyle: TextStyle(
color: Colors.black45, fontSize: 18)),
autofocus: true,
maxLength: 15,
keyboardType: TextInputType.phone,
),
),
],
),
)
複製程式碼
7.軟鍵盤彈出後,把整塊內容頂到上面去了
return Scaffold(
resizeToAvoidBottomPadding: false, // 新增上這個,軟鍵盤彈出,背景頁面不動
......
}
複製程式碼
8.Column內有Listview報錯問題
這是尺寸計算問題,在Listview外面巢狀
- Expanded,Listview有多大就有多大
- 或Container,Container多大Listview就有多大,可以滾動
9.執行Flutter專案時Your app isn't using AndroidX.
報瞭如下錯誤:
Launching lib/main.dart on sdk gphone x86 in debug mode... [!] Your app isn't using AndroidX. To avoid potential build failures, you can quickly migrate your app by following the steps on goo.gl/CP92wY. Running Gradle task 'assembleDebug'... 注: 某些輸入檔案使用或覆蓋了已過時的 API。 注: 有關詳細資訊, 請使用 -Xlint:deprecation 重新編譯。
FAILURE: Build failed with an exception.
- What went wrong:
Execution failed for task ':app:javaPreCompileDebug'.
Could not resolve all files for configuration ':app:debugCompileClasspath'. Could not download x86_debug.jar (io.flutter:x86_debug:1.0.0-5aff3119480996ca014ec0f8d26d74db617b5852)
> Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-5aff3119480996ca014ec0f8d26d74db617b5852/x86_debug-1.0.0-5aff3119480996ca014ec0f8d26d74db617b5852.jar'.
> Could not GET 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-5aff3119480996ca014ec0f8d26d74db617b5852/x86_debug-1.0.0-5aff3119480996ca014ec0f8d26d74db617b5852.jar'.
> Read timed out
複製程式碼
- Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
- Get more help at help.gradle.org
BUILD FAILED in 3m 37s Exception: Gradle task assembleDebug failed with exit code 1
原因
字面意思:你的app沒有使用AndroidX 那就讓app使用AndroidX,在gradle.properties中新增:
android.enableJetifier=true
android.useAndroidX=true
複製程式碼
10.Unhandled Exception: PlatformException(already_active, Image picker is already active, null
使用image_picker時遇到的問題,解決辦法:檢查AndroidManifest.xml中是否新增了許可權 AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
複製程式碼
11.啟動頁修改
IOS啟動頁
在ios/Runner/Assets.xcassets/LaunchImage.imageset/下, 有 Contents.json 檔案和啟動圖片,將你的啟動頁放置在這個目錄下,並且修改 Contents.json 即可,具體尺寸自行谷歌即可。
Android啟動頁
在 android/app/src/main/res/drawable/launch_background.xml 中已經有寫好的啟動頁, 部分被遮蔽,只需要開啟這個遮蔽,並且將你啟動圖修改為launch_image並放置到各個 mipmap 資料夾即可,記得各個資料夾下提供相對於大小尺寸的檔案。