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

相关推荐
爱勇宝9 小时前
鸿蒙生态的下半场:开发者不只要能开发,还要能赚钱
android·前端·程序员
Yeyu13 小时前
刷新一帧的艺术:invalidate / postInvalidate / postInvalidateOnAnimation全解析
android
潘潘潘14 小时前
Android OTA 升级原理和流程介绍
android
悟空瞎说16 小时前
Flutter 架构详解:新手必懂底层原理
flutter
SoaringHeart19 小时前
Flutter最佳实践:IM聊天文字链接自动识别跳转
前端·flutter
plainGeekDev20 小时前
null 判断 → Kotlin 可空类型
android·java·kotlin
plainGeekDev20 小时前
getter/setter → Kotlin 属性
android·java·kotlin
YXL1111YXL21 小时前
Handler 消息回收与协程异步执行的时序陷阱
android
恋猫de小郭1 天前
KMP / CMP 鸿蒙版本 Beta 发布,他有什么特别之处?
android·前端·flutter
三少爷的鞋1 天前
Android 协程并发控制:别动线程池,控制好并发语义就够了
android