对flutter有兴趣的小伙伴可以一起学习呀~
好用的命令行
flutter pub pub cache repair :清理缓存
错误一:
- flutter project插入图片异常
xjdMacBook-Pro:flutter_app_layout xj.d$ flutter run -d all
Running "flutter packages get" in flutter_app_layout...
Error on line 40, column 2 of pubspec.yaml: Expected a key while parsing a block mapping.
assets:
^
pub get failed (65)
flutter插入图片
1.根项目创建文件名为【图像】文件夹
2.将文件复制到文件夹下面
3.pubspec.yaml文件下面配置该图片
注意图的名字都正确,配置和使用都保持一致(楼主该图随便百度下的),否则无法找到资源
错误二:
- 错误提示:请在android / folde中查看您的Gradle项目设置
+818 ms]
------------------------------------------------------------
Gradle 4.1
------------------------------------------------------------
Build time: 2017-08-07 14:38:48 UTC
Revision: 941559e020f6c357ebb08d5c67acdb858a3defc2
Groovy: 2.4.11
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_152-release (JetBrains s.r.o 25.152-b06)
OS: Mac OS X 10.14.1 x86_64
[{"event":"app.progress","params":{"appId":"d7911b72-32cb-4f2c-b548-e7b8e073da36","id":"0","progressId":null,"finished":true}}]
Resolving dependencies...
[{"event":"app.progress","params":{"appId":"d7911b72-32cb-4f2c-b548-e7b8e073da36","id":"1","progressId":null,"message":"Resolving dependencies..."}}]
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/xj.deng/Ali/widgets/hybrid_stack_manager/example/android/app/build.gradle' line: 15
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not resolve all files for configuration 'classpath'.
> Could not find lint-gradle-api.jar (com.android.tools.lint:lint-gradle-api:26.1.2).
Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/lint/lint-gradle-api/26.1.2/lint-gradle-api-26.1.2.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
.....
* Error running Gradle:
Exit code 1 from: /Users/xj.deng/ali/widgets/hybrid_stack_manager/example/android/gradlew app:properties:
Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
java.lang.IllegalStateException: compileSdkVersion is not specified.
at com.google.common.base.Preconditions.checkState(Preconditions.java:456)
at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.java:590)
at com.android.build.gradle.BasePlugin.lambda$null$3(BasePlugin.java:555)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:81)
- flutter - >在android stuido错误中打开android模块
Could not find lint-gradle-api.jar (com.android.tools.lint:lint-gradle-api:26.1.2).
Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/lint/lint-gradle-api/26.1.2/lint-gradle-api-26.1.2.jar
Open File
- 解决办法:
因为是GitHub的上拉下来的代码,gradle4.1,查看自己配置环境的gradle这个版本,是否一致,需改版本。
我解决办法直接删了项目gralde,粘贴自己没有问题的flutter gralde文件,上图。就是这么暴力~~
错误三:
-
异常:Android dependency ‘com.android.support:support-core-utils’ has different version for the compile (25.3.0) and runtime (27.1.1) classpath. You should manually set the same version via DependencyResolution
-
原因:创建一个lib【common】,app:依赖【common】出现该原因。
-
解决办法:
subprojects {
// project.evaluationDependsOn(':app')
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "27.1.1"
}
}
}
}
如图:
错误:
日志: Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
修改:
MainActivity主题配置:
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/Theme.AppCompat"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
错误
日志:androidstudio 切换到flutter项目Android报错
Flutter SDK not found. Define location with flutter.sdk in the local.properties file.
解决办法:删android/local.properties文件,运行【flutter build apk】
然后重新打开studio到Android channel,如下图,ok~
错误
混合开发,Native+Flutter
错误提示:
/Users/xx/xx/flutter-project/my_flutter/.android/include_flutter.groovy (/Users/xx/alibaba/flutter-project/my_flutter/.android/include_flutter.groovy)
修改:补全路径
提示
Androidstudio打开flutter project 无法切换Android版本:【Open Android module in Android Studio】无法选择
正常情况如图:
解决办法:查看是否有这个.iml文件 没有就加进去
错误提示:
编译ios出错:
diff: /Podfile.lock: No such file or directory
diff: /Manifest.lock: No such file or directory
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
解决方案:
控制台敲命令行:
flutter build ios --release
关闭xcode重启项目
错误
最近在弄IOS打包,遇到的问题是,debug包都没问题,release包安装在手机上面后,页面一直停留在欢迎页面,无法进入首页。
原因:flutter一部分dart包过时,无法支持release
解决:对应更新一下flutter 项目里面依赖都dart包就好了
具体因为哪一个导致的没有细查,大部分都更新了一下,就好了~
错误提醒
[+3059 ms] FAILURE: Build failed with an exception.
[ +1 ms] * What went wrong:
[ ] Execution failed for task ':app:processDebugResources'.
[ ] > Android resource linking failed
[ ] /Users/xj.deng/alibaba/xj_fluttergo/flutter-go/android/app/src/main/res/drawable/launch_background.xml:8: AAPT: error: resource mipmap/splash (aka com.alibaba.fluttergo:mipmap/splash) not found.
[ ] error: failed linking file resources.
[ ] * 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 https://help.gradle.org
[ ] BUILD FAILED in 3s
[ +367 ms] *******************************************************************************************
[ ] The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
[ ] See https://goo.gl/CP92wY for more information on the problem and how to fix it.
[ ] *******************************************************************************************
项目使用了gradle-4.10-all.zip,导致androidX,解决办法下面链接
https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
错误提示:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alibaba.fluttergo/com.alibaba.fluttergo.MainActivity}: java.lang.IllegalStateException: ensureInitializationComplete must be called after startInitialization
Caused by: java.lang.IllegalStateException: ensureInitializationComplete must be called after startInitialization
at io.flutter.view.FlutterMain.ensureInitializationComplete(FlutterMain.java:177)
at com.alibaba.fluttergo.MainActivity.onCreate(MainActivity.kt:49)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
解决处理:
添加FlutterMain.startInitialization(this)
如下图所示:ensureInitializationComplete前添加