android 与flutter 混合开发
android 与flutter 混合开发 搞了很久,项目老是报错,各种问题,后来找了一种方案,可以下载
下载android Studio 3.6.3 好像可以自动配置
settings.gradle 自动生成配置内容
1 2 3 4 5 6 7 8 9 10 | rootProject.name= 'androidFlutterDemo3' include ':app' setBinding( new Binding([gradle: this ])) evaluate( new File( settingsDir, '../flutter_module/.android/include_flutter.groovy' )) include ':flutter_module' project( ':flutter_module' ).projectDir = new File( '../flutter_module' ) |
gradle-wrapper.properties内容 gradle-5.6.4
1 2 3 4 5 6 | #Wed Nov 16 16 : 54 : 56 CST 2022 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\: //services.gradle.org/distributions/gradle-5.6.4-all.zip |
app build.gradle implementation project(path: ':flutter')
1 2 3 4 5 6 7 8 9 10 11 | dependencies { implementation fileTree(dir: 'libs' , include: [ '*.jar' ]) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.core:core-ktx:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' implementation project(path: ':flutter' ) } |
Android Studio报错:Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
1 2 3 | 解决办法 1 : 将工程的build.gradle中的ext.kotlin_version = "1.3.72" (低版本)改成ext.kotlin_version = "1.5.21" (不一定是 1.5 . 21 ,最新版也行),再sync一下,重新运行就可以了。 |
添加跳转到flutter 页面
1 2 3 | btnStart.setOnClickListener { startActivity(FlutterActivity.withNewEngine().initialRoute( "params" ).build( this )) } |
报错
添加FlutterActivity
1 2 3 | <activity android:name= "io.flutter.embedding.android.FlutterActivity" > </activity> |
setBinding(new Binding) Binding 一直找不到 解决办法按以下步骤 创建子flutter项目
参考: https://blog.csdn.net/mawlAndroid/article/details/124861260
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报