• android 项目中导入flutter module


    1、环境介绍

    Android studio版本:
    flutter版本:2.10.5
    Java版本:Java8

    2、步骤

    一、创建一个Android工程
    这里就不说了

    2、创建一个flutter module
    方法一:和加入普通的module一样,File -> New -> New Module,然后选择flutter module即可。
    方法二:我的Android studio中找不到flutter module,所以我只能手动创建,终端切到Android功能根目录下,执行

    flutter create -t module --org com.example my_flutter
    
    • 1

    这里就创建了一个名字为my_flutter的工程了,使用命令flutter run运行一下,它是能跑起来的。

    3、加入module

    在setting.gradle中,配置module,加入

    include ':my_flutter'
    
    setBinding(new Binding([gradle: this]))
    evaluate(new File(
            settingsDir,
            'my_flutter/.android/include_flutter.groovy'
    )
    )
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    这里的路径“my_flutter/.android/include_flutter.groovy”是一个相对路径,my_flutter是我们创建的flutter工程,路径不要填错了。
    还要继续改一下dependencyResolutionManagement,原来是

    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
        repositories {
            google()
            mavenCentral()
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    改为

    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) // edit this
        repositories {
            google()
            mavenCentral()
    
            String flutterStorageUrl = System.getenv("FLUTTER_STORAGE_BASE_URL") ?: "https://storage.googleapis.com"
            maven {
                url flutterStorageUrl + "/download.flutter.io"
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    最后在app/build.gradle中加入flutter module依赖

    dependencies {
    
        implementation 'androidx.appcompat:appcompat:1.4.2'
        implementation 'com.google.android.material:material:1.6.1'
        implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
        implementation project(path: ':flutter')
        testImplementation 'junit:junit:4.13.2'
        androidTestImplementation 'androidx.test.ext:junit:1.1.3'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    细心的你可能注意到了,我们的flutter module名字不是my_flutter吗,怎么这里是flutter了,其实这个我也不清楚,如果写成my_flutter的话会有找不到的错误,最好的办法是点击 File -> project structure -> Dependencies手动的加进去。

  • 相关阅读:
    02_Alibaba微服务组件Nacos注册中心
    Spring Boot、Spring MVC 和 Spring Cloud 深度解析
    进行股票量化交易接口程序化开发要注意的事项
    【Python基础知识】(16)Range的经典用例
    Met no ‘TRANSLATIONS’ entry in project
    视频上传阿里云,如何获取视频的某一帧作为封面??
    MyBatis-动态SQL
    告别杂音,从 AI 音频降噪开始
    商业智能BI与业务管理决策思维之三:业务质量分析
    DRL基础(十一)——近端策略优化算法PPO【附代码】
  • 原文地址:https://blog.csdn.net/qq_41818873/article/details/126610064