You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将Flutter模块集成至原生Android应用时遇依赖查找错误求助

解决Flutter模块集成到Android原生时"Could not find com.example.fluttermodule:flutter_debug:1.0"错误

问题根源分析

从你的配置文件能看出几个核心问题:

  1. 依赖配置重复混乱:同时存在implementation project(':flutter')、环境区分的flutter_debug/profile/release依赖,以及额外的com.example.my_flutter依赖,这些配置冲突且不符合官方集成规范。
  2. Flutter模块的本地Maven仓库可能未生成,或者路径配置存在偏差。

分步解决方案

1. 清理app/build.gradle中错误的依赖配置

保留官方推荐的集成方式,删除冗余冲突的依赖,修改后的dependencies块如下:

dependencies {
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.5.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation "androidx.core:core-ktx:+"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // 仅保留这一行,include_flutter.groovy脚本会自动处理多环境依赖映射
    implementation project(':flutter')
}

说明:include_flutter.groovy脚本已经自动完成了debug/profile/release环境的依赖适配,无需手动添加flutter_debug这类aar引用。

2. 生成Flutter模块的本地Maven仓库

进入Flutter模块的根目录,执行以下命令生成供Android原生引用的仓库文件:

flutter build aar

执行成功后,确认flutterModule/build/host/outputs/repo路径下存在生成的仓库文件,且该路径与你settings.gradle中配置的maven url完全一致。

3. 校验settings.gradle的路径配置

确认include_flutter.groovy的路径正确,你的配置中使用了settingsDir.parentFile下的flutterModule/.android/include_flutter.groovy,需保证Flutter模块确实位于原生项目的同级目录。若路径不符,修改为实际的相对路径或绝对路径。

4. 同步并清理项目

  • 点击Android Studio右上角的"Sync Project with Gradle Files"按钮同步项目
  • 执行File -> Invalidate Caches... -> Invalidate and Restart清理缓存并重启IDE
  • 尝试重新构建项目

额外注意事项

  • 确保Flutter SDK版本与依赖的io.flutter:flutter:2.8.0版本一致,避免版本不兼容问题
  • 不要混合使用"项目依赖"和"本地aar依赖"两种集成方式,官方推荐通过include_flutter.groovy脚本进行项目依赖集成

内容的提问来源于stack exchange,提问作者Soft Power

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 23:06:21