Flutter module集成到Android原生项目报错
使用AAR方案集成遇到两个诡异错误
环境:
- Flutter (Channel stable, 3.3.10, on macOS 13.5.2 22G91 darwin-x64, locale
zh-Hans-CN) - Android Studio (version 2022.3)
- Android toolchain - develop for Android devices (Android SDK version 34.0.0)
- 生成flutter module aar
flutter build aar
- 按照终端提示操作集成
...
同步失败
报错:Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'app/build.gradle'
错误原因:
在settings.gradle里面定了repositories和maven,又在build.gradle里面定义repositorie导致冲突
解决方法:
不在build.gradle里定义repositorie,仅在settings.gradle定义
// settings.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
url 'path/to/your/flutter_module/build/host/outputs/repo'
// This is relative to the location of the build.gradle file
// if using a relative path.
}
maven {
url 'https://storage.googleapis.com/download.flutter.io'
}
}
}
修正上面错误后sync成功,运行项目失败
错误:Could not find flutter-1.0-debug.jar
错误原因:
没找到之前输出打包的aar
解决方法:
dependencies {
debugImplementation 'com.example.flutter_module:flutter:1.0:debug'
profileImplementation 'com.example.flutter_module:flutter:1.0:profile'
releaseImplementation 'com.example.flutter_module:flutter:1.0:release'
}
// 修正为
dependencies {
debugImplementation 'com.example.flutter_module:flutter_debug:1.0'
profileImplementation 'com.example.flutter_module:flutter_profile:1.0'
releaseImplementation 'com.example.flutter_module:flutter_release:1.0'
}
修改后可以正确加载打包的aar依赖并成功运行
基本这两个错误都是flutter的文档过时了...没点安卓原生功底解决起来真的麻烦
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了