Flutter导入安卓第三方库报错:Flutter Could not find method implementation() 的可能原因及解决办法

build.gradle里面试图添加引用一个库:

kotlin 复制代码
buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        implementation 'com.abc.def:ghi:114.514.1919810'
    }
}

然后运行的时候报错:

复制代码
A problem occurred evaluating root project 'android'.
> Could not find method implementation() for arguments [com.abc.def:ghi:114.514.1919810] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

可能原因:Flutter项目的android目录下有两个build.gradle文件,一个是android/build.gradle,另一个是android/app/build.gradle,在前者文件里面添加引用就会出这个错,解决办法是改在后者文件中另起一行添加:

kotlin 复制代码
dependencies {
    implementation 'com.abc.def:ghi:114.514.1919810'
}

参考来源:https://ourcodeworld.com/articles/read/1590/how-to-solve-android-error-could-not-find-method-implementation-for-arguments-on-object-of-type-orggradleapiinternalartifactsdsldependenciesdefaultdependencyhandler

相关推荐
雨声不在16 分钟前
docker-android 重启后镜像起不来
android·docker·容器
阿pin30 分钟前
Android随笔-Framework
android·framework
达达尼昂1 小时前
Flutter AI Harness 如何让 Agent 参与软件开发全流程
android·人工智能·后端
sRect1 小时前
用ESP32-S3开发板开发一个接收消息的BB机
android·serverless·嵌入式
AFinalStone2 小时前
Android 7系统无障碍服务(二)AccessibilityManagerService 启动与初始化
android·无障碍服务
小孔龙2 小时前
BufferQueue 多缓冲与背压
android
阿pin2 小时前
Android随笔-kotlin Flow
android·kotlin·flow
阳光予你2 小时前
App 启动流程:从 Launcher 点击到 Activity 创建
android
小孔龙3 小时前
BufferQueue 对象交接与同步
android
XiaoLeisj3 小时前
Kotlin Flow 常用操作符:数据变换 map、filter、onEach,时间控制 debounce、sample,终端聚合 reduce、fold
android·kotlin·android jetpack·协程·响应式编程·flow