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

相关推荐
youyoulg2 分钟前
利用Android Studio编译Android上可直接执行的二进制
android·ide·android studio
早點睡39013 分钟前
基础入门 Flutter for OpenHarmony:FloatingActionButton 浮动按钮详解
flutter·harmonyos
闽农18 分钟前
Android ANR 调用栈溯源
android·anr
似霰19 分钟前
Android 日志系统7——Android 平台日志丢失问题分析
android·log
哈__31 分钟前
基础入门 Flutter for OpenHarmony:file_selector 文件选择详解
flutter
·云扬·32 分钟前
MySQL Undo Log 深度解析:事务回滚与 MVCC 的底层支柱
android·数据库·mysql
fareast_mzh38 分钟前
如何检测、排除手机控制屏幕
android
左手厨刀右手茼蒿41 分钟前
Flutter for OpenHarmony 实战:DartX — 极致简练的开发超能力集
android·flutter·ui·华为·harmonyos
codeGoogle44 分钟前
2026 年 IM 怎么选?聊聊 4 家主流即时通讯方案的差异
android·前端·后端