1、Waiting for another flutter command to release the startup lock...
開啟新的專案或者使用Flutter Packages get時出現: Waiting for another flutter command to release the startup lock...
解決方案:
先開啟工作管理員,結束掉所有dart.exe即可,如果依然提示就開啟你的flutter安裝資料夾,找到\bin\cache中的lockfile檔案刪除。之後重啟專案。
複製程式碼
2、The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app
Android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) classpath. You should manually set the same version via DependencyResolution
解決方案一:
設法通過新增這樣的程式碼片段來修復錯誤
在專案 android > build.gradle 檔案中 buildscript { } 中新增此程式碼片段
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "27.1.1"
}
if (details.requested.group == 'androidx.core'
&& !details.requested.name.contains('androidx') ) {
details.useVersion "1.0.1"
}
}
}
}
解決方案二:
1.android/gradle/wrapper/gradle-wrapper.properties裡面
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip2.android/build.gradle
dependencies { classpath 'com.android.tools.build:gradle:3.3.0' }
3.android/gradle.properties
加入
android.enableJetifier=true
android.useAndroidX=true4.android/app/build.gradle 修改版本號:
make sure compileSdkVersion and targetSdkVersion are at least 28.
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"5.android/app/build.gradle /defaultConfig加上
multiDexEnabled true複製程式碼
3、Error connecting to the service protocol: HttpException: Connection closed before full header was...
12、setstate() called after dispose() ,setstate導致的記憶體洩漏
// flutter端請求網路時,呼叫的是宿主App的網路請求。
// flutter通過訊息通道傳送一個訊息,然後await等待訊息返回,最終宿主app會呼叫reply.reply(obj)方法返回資料。
// 如果在這個過程中,flutter頁面關閉,就會出現如下異常,類似Android中的記憶體洩漏。
/* setState() called after dispose(): _DetailCommentsState#5c3a1(lifecycle state: defunct, not mounted)
I/flutter ( 4677): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
I/flutter ( 4677): The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
I/flutter ( 4677): This error might indicate a memory leak ifsetState() is being called because another object is retaining a reference to this State object
after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose(). */
// 我們的錯誤原因是非同步訊息未返回,所以在setState方法之前呼叫mouted屬性進行判斷即可。具體示例如下:
if(mounted){
setState(() {
_movie = res.data;
_themeColor = paletteGenerator.colors.toList()[1];
_detailThemeColor = paletteGenerator.colors.toList()[0];
});
}
複製程式碼
13、xCode打包提示:Could not find included file 'Generated.xcconfig' in search paths (in target 'Runner')
/*
國內使用 flutter packages get 命令,一直是 This is taking an unexpectedly long time 狀態
科學上網無效
windows解決方案:配置 【環境變數】 > 【使用者變數】:
變數名:PUB_HOSTED_URL 值:https://pub.flutter-io.cn
變數名:FLUTTER_STORAGE_BASE_URL 值:https://storage.flutter-io.cn
最好重啟下windows電腦,flutter packages get 執行
*/
具體環境變數的值 需要看該網址 [Using Flutter in China](https://flutter.dev/community/china)複製程式碼
18、is a SingleTickerProviderStateMixin but multiple tickers were created.
// 報錯日誌:
I/flutter ( 4025): A SingleTickerProviderStateMixin can only be used as a TickerProvider once. If a State is used for
I/flutter ( 4025): multiple AnimationController objects, or if it is passed to other objects and those objects might
I/flutter ( 4025): use it more than one time in total, then instead of mixing in a SingleTickerProviderStateMixin, use
I/flutter ( 4025): a regular TickerProviderStateMixin.
大概翻譯意思:單個TickerProviderStateMixin,但建立了多個Ticker,單個statemixin 只能供一個TickerProvider使用,如果一個狀態用於多個物件,它可能被傳遞給其他物件。
// 解決方案:將SingleTickerProviderStateMixin換成TickerProviderStateMixin複製程式碼
19、動畫釋放報錯
// 報錯日誌:
e following assertion was thrown while finalizing the widget tree:
I/flutter ( 3776): _CustomScrollFooterState#3df1f(ticker active) was disposed with an active Ticker.
I/flutter ( 3776): _CustomScrollFooterState created a Ticker via its SingleTickerProviderStateMixin, but at the time
I/flutter ( 3776): dispose() was called on the mixin, that Ticker was still active. The Ticker must be disposed before
I/flutter ( 3776): calling super.dispose(). Tickers used by AnimationControllers should be disposed by calling
I/flutter ( 3776): dispose() on the AnimationController itself. Otherwise, the ticker will leak.
I/flutter ( 3776): The offending ticker was: Ticker(created by _CustomScrollFooterState#3df1f(lifecycle state:
I/flutter ( 3776): created))
// 解決方案:
controller.dispose()放在了 super.dispose()的後面:
@override
void dispose() {
//先呼叫controller.dispose釋放了動畫資源,再呼叫super
controller.dispose();
super.dispose();
}
複製程式碼
20、Could not resolve all files for configuration ':app:lintClassPath'.
// 報錯日誌:
* What went wrong:
Execution failed for task ':app:lintVitalRelease'.
> Could not resolve all files for configuration ':app:lintClassPath'.
> Could not download groovy-all.jar (org.codehaus.groovy:groovy-all:2.4.12)
> Could not get resource 'https://jcenter.bintray.com/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.jar'.
> Could not GET 'https://jcenter.bintray.com/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.jar'.
> Remote host closed connection during handshake
// 解決方案:
在app的build.gradle中的android部分新增如下程式碼塊即可
lintOptions {
checkReleaseBuilds false
abortOnError false
}
複製程式碼
22、更改檔名或刪除名稱時報錯,were declared as an inputs, but did not exist. Check the definition of target:kernel_snapshot for errors
// 報錯日誌
C:\Users\Admin\Desktop\flutter_jahn_douban\lib\pages\tabs\book_movie\movie\movieTop\movieTopAll\movie_top_all.dart, C:\Users\Admin\Desktop\flutter_jahn_douban\lib\pages\tabs\book_movie\movie\movieTop\movieTopAll\movie.dart were declared as an inputs, but did not exist. Check the definition of target:kernel_snapshot for errors
#0 Node.computeChanges (package:flutter_tools/src/build_system/build_system.dart:777:7)
<asynchronous suspension>
#1 _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:517:20)
<asynchronous suspension>
#2 _BuildInstance.invokeTarget.<anonymous closure> (package:flutter_tools/src/build_system/build_system.dart:481:35)
// 解決方案:
刪除.dart_tool資料夾,然後重新執行即可。
複製程式碼
/* The following ArgumentError was thrown while handling a gesture:
I/flutter ( 6034): Invalid argument(s): Illegal percent encoding in URI
I/flutter ( 6034): When the exception was thrown, this was the stack:
I/flutter ( 6034): #0 _Uri._uriDecode (dart:core/uri.dart:2951:11)
I/flutter ( 6034): #1 Uri.decodeComponent (dart:core/uri.dart:1120:17) */
無效的引數:URI中的非法編碼百分比
// 解決方案:
通過Uri.encodeComponent(Text)轉化
複製程式碼
25、TextField元件,報錯解決:The following assertion was thrown while handling a gesture