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

相关推荐
走在路上的菜鸟12 分钟前
Android学Dart学习笔记第二十六节 并发
android·笔记·学习·flutter
坚果派·白晓明16 分钟前
Windows 11 OpenHarmony 版 Flutter 开发环境搭建常见问题解决方法
windows·flutter·开源鸿蒙·鸿蒙跨平台应用开发
00后程序员张18 分钟前
AppStoreInfo.plist 在苹果上架流程中的生成方式和作用
android·小程序·https·uni-app·iphone·webview
昼-枕21 分钟前
鸿蒙Flutter实战:构建智能健身教练应用
flutter·华为·harmonyos
昼-枕21 分钟前
鸿蒙与 Flutter 的融合探索:跨平台开发的新可能
flutter·华为·harmonyos
成都大菠萝26 分钟前
2-2-10 快速掌握Kotlin-out协变
android
成都大菠萝29 分钟前
2-2-8 快速掌握Kotlin-vararg关键字与get函数
android
成都大菠萝29 分钟前
2-2-7 快速掌握Kotlin-泛型类型约束
android
城东米粉儿36 分钟前
Collections.synchronizedMap()与ConcurrentHashMap的区别笔记
android
愤怒的代码40 分钟前
深入解析 Binder 运行的状态
android·app