============================================================
1.Flutter SDK not found. Define location with flutter.sdk in the local.properties file.
Open File
解决:在.android下面增加local.properties,里面加入flutter.sdk=E:\flutter
============================================================
cannot resolve symbol binding 解决:
gradle-wrapper使用4.10.2 (5.1.1以下就可以)
============================================================
- C:\Project\teck_note\module_flutter.android\include_flutter.groovy (C:\Project\teck_note\module_flutter.android\include_flutter.groovy)
Open File
解决:把报错的路径复制到电脑文件管理器,会报错。
改到路径对了为止。
============================================================
4.Configuration with name 'default' not found
解决:settings.gradle中的工程下面,没有build.gradle
============================================================
5.重建.android文件夹
解决:删除.android ,之后flutter packages get
============================================================
6.webView选择
webview_flutter:官方,功能少
flutter_webview_plugin: 不在Flutter Widget Tree内
flutter_inappwebview 最终选用这个,上面两个要么加载复杂本地html不方便,要么和js交互不方便
flutter_inappwebview加载本地html,需要把html用到的所有层级的js和资源,加到pubspec.yaml里面;和js的交互是异步的
============================================================
7.混合开发
原先的混合开发方式已不再适用,现在用
FlutterEngine flutterEngine = new FlutterEngine(this);
// Start executing Dart code in the FlutterEngine.
flutterEngine.getDartExecutor().executeDartEntrypoint(
DartExecutor.DartEntrypoint.createDefault()
);
// Cache the pre-warmed FlutterEngine to be used later by FlutterFragment.
FlutterEngineCache
.getInstance()
.put(MethodChannelPlugin.ENGINE_ID, flutterEngine);
GeneratedPluginRegistrant.registerWith(flutterEngine);
MethodChannelPlugin.registerWith(flutterEngine);
}
FlutterFragment flutterFragment = FlutterFragment.withCachedEngine(MethodChannelPlugin.ENGINE_ID).build();
============================================================
8.open for editing in android studio 不见了
复制别的项目的android/[project_name]_android.iml
============================================================
9.提示升级embedded v2
https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
============================================================
10.无法运行profile模式
-- 把build.gradle中,debug和release的自定义配置信息(如multiDexEnabled buildConfigField),放到defaultConfig中一份。
-- android/app/src/profile/AndroidManifest.xml 中修改包名等
============================================================
11.devTools跑不起来,一直build in progress
尝试如下也不行
flutter pub global deactivate devtools
flutter pub cache repair
flutter pub global activate devtools
flutter pub global run devtools
进入报错目录,用老版本覆盖
============================================================
- as中dart analyze 失败,但是命令行可以编译过
解决:as中设置flutter sdk路径
//flutter 2.0时代
============================================================
13.直接run的release包,没有arm-v7的.so。couldn't find "libflutter.so"启动崩溃
常见的 无效的 解决办法:
1:gradle中设置 abiFilters指定v7,这种只在用as打开app目录build.gradle中有效
release {
ndk {
abiFilters 'armeabi-v7a'
}
}
2:local.properties中设置target-platform=android-arm
3: 其他命令行加参数等方法
解决:在sdk/flutter/packages/flutter_tools/gradle/flutter.gradle中
private List<String> getTargetPlatforms() {
if (!project.hasProperty('target-platform')) {
println("NO!!!!!!!!!!!!!!!!!target-platform")
return DEFAULT_PLATFORMS
}
return project.property('target-platform').split(',').collect {
println("split!!!!!!!!!!!!!!!!!target-platform $it\n")
if (!PLATFORM_ARCH_MAP[it]) {
throw new GradleException("Invalid platform: $it.")
}
return it
}
}
然后编译看日志结果。
app模块中apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
把project传入给SDK的flutter.gradle
所以我们需要给app module中增加property
先在gradle.properties中设置target-platform=android-arm
然后在项目的根目录的build.gradle
rootProject.setProperty('target-platform', 'android-arm')
subprojects {
project.setProperty('target-platform', 'android-arm')
}
============================================================
14.直接run的debug包,couldn't find "libflutter.so"启动崩溃,即使apk中有对应.so
解决:检查各个子module中不能有其他格式的abiFilters
============================================================
15.ScrollAppBar配合listView滚动异常
滚不到最底
解决:延时100ms执行animateTo,动画duration要根据list长度大于100ms到1500ms
ListView逐渐边长,刚把SrollAppBar快顶出屏幕,ScrollAppBar异常跳动
解决:ListView高度不对,没有算进去ScrollAppBar
ListKey.currentContext.size.height不对
============================================================
16.语法小坑:
坑1:
dart的对象是引用传递
但是有一种情况不能传递。
class A{
Obj? obj;
classB.setValue(obj);//会给obj赋值
onDispose() {
obj?.dispose(); //obj一直是null
}
}
建议在A中初始化好obj
坑2:
static void send(String name, {Map<String, dynamic>? map}) {
if (map == null) map = {};
map.addAll({
"info": 'aaa',
});
send(name, map);
}
会报错type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Map<String, Object>' in type cast
建议指明类型
Map<String, String> infoMap = {
"info": 'aaa',
};
map.addAll(infoMap);
============================================================
17.flutter compileDebugJavaWithJavac
cd /Applications/Android\ Studio.app/Contents/jre
ln -s ../jre jdk
ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk
flutter doctor -v