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

相关推荐
胖虎13 小时前
Android Studio 读取本地文件(以 ZIP 为例)
android·ide·android studio·本地文件·读取本地文件
出海小纸条3 小时前
Google Play 跨应用脚本漏洞(Cross-App Scripting)
android
小孔龙3 小时前
Android Runtime(ART) GC 日志手册
android
袁美丽..3 小时前
Android --- SystemUI 导入Android Studio及debug
android·ide·android studio
袁美丽..4 小时前
Android studio的adb和终端的adb互相抢占端口
android·adb·android studio
鹏多多.4 小时前
flutter-使用fluttertoast制作丰富的高颜值toast
android·前端·flutter·ios
守城小轩5 小时前
Firefox Android 开发环境搭建全流程(四)
android·firefox·chrome devtools·指纹浏览器·浏览器开发
袁美丽..5 小时前
Android --- AOSP源码导入Android Studio
android·android studio
LiuYaoheng5 小时前
【Android】View 的基础知识
android·java·笔记·学习
出海小纸条6 小时前
Google Play 应用被拒-数据安全表单无效(设备上的应用)
android