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

相关推荐
帅得不敢出门7 分钟前
精简Android SDK(AOSP)的git项目提高git指令速度
android·java·开发语言·git·elasticsearch
2501_9371892310 分钟前
神马 9.0 2025 最新版源码系统:安全加固 + 二次开发友好
android·源码·开源软件·源代码管理·机顶盒
モンキー・D・小菜鸡儿1 小时前
Android 中 StateFlow 的使用
android·kotlin
二川bro1 小时前
字符串特性解析:Python不可变性引发的错误
android·开发语言·python
2501_937154932 小时前
酷秒神马 9.0 2025 版:微服务架构
android·源码·源代码管理·机顶盒
L、2182 小时前
Flutter + OpenHarmony + 区块链:构建去中心化身份认证系统(DID 实战)
flutter·华为·去中心化·区块链·harmonyos
我又来搬代码了2 小时前
【Android】【Compose】Compose知识点复习(一)
android·前端·kotlin·android studio
fatiaozhang95272 小时前
九联UNP-SJA8-国科GK6323V100C-2+8G-安卓9.0-原厂强刷固件包-可救砖及开ADB教程
android·adb·电视盒子·刷机固件·机顶盒刷机·机顶盒刷机固件·九联unp-sja8
西西学代码2 小时前
Flutter---右滑显示删除按钮
flutter
似霰2 小时前
传统 Hal 开发笔记4----实现 Hal 模块
android·hal