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

相关推荐
mmsx2 分钟前
Android 栅格数据缓冲区的类型包装:用匿名子类破解泛型擦除
android·地图·栅格
叶羽西5 分钟前
Android Camera HAL调整图像处理线程优先级
android
HouWan1 小时前
Flutter: MediaQuery.of(context) 为什么可能拖慢页面?
android·flutter·ios
事圆则缓1 小时前
Android 图片内存到底怎么算
android
Godikov2 小时前
弱网环境离线优先:Android 终端数据可靠同步架构实战
android
爱编程的小新☆4 小时前
Fake GPS 虚拟定位保姆级使用教学
android·移动开发·gps·虚拟定位
执明wa5 小时前
Android RecyclerView 多类型, 多种 Item
android·xml·开发语言·设计模式·android studio
silianpan6 小时前
CAD 文档预览 UTS 插件
android·ios·harmonyos
小麦在野6 小时前
独立 App 开发系列:用 GitHub Pages 托管隐私政策和用户协议
android·github