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

 

posted @   疯子FK  阅读(334)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
点击右上角即可分享
微信分享提示