android 与flutter 混合开发

android 与flutter 混合开发 搞了很久,项目老是报错,各种问题,后来找了一种方案,可以下载

下载android Studio 3.6.3 好像可以自动配置

 

settings.gradle 自动生成配置内容

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

#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')

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:

        将工程的build.gradle中的ext.kotlin_version = "1.3.72"(低版本)改成ext.kotlin_version = "1.5.21"(不一定是1.5.21,最新版也行),再sync一下,重新运行就可以了。

 

添加跳转到flutter 页面

 btnStart.setOnClickListener {
            startActivity(FlutterActivity.withNewEngine().initialRoute("params").build(this))
        }

 报错

 

 添加FlutterActivity

        <activity android:name="io.flutter.embedding.android.FlutterActivity">

        </activity>

 

 

 

setBinding(new Binding)  Binding 一直找不到  解决办法按以下步骤  创建子flutter项目

 

 

 

 

参考: https://blog.csdn.net/mawlAndroid/article/details/124861260

 

posted @ 2022-11-16 17:30  疯子FK  阅读(307)  评论(0编辑  收藏  举报