且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找不到Gradle DSL方法:android()

更新时间:2022-03-18 05:32:37

如果构建脚本中包含android块,则需要以下两个语句之一,具体取决于您的模块是应用程序模块还是应用程序模块.库模块:

If you have an android block in your build script, you need one of the following two statements, depending on whether your module is an application module or a library module:

apply plugin: 'com.android.application'

或:

apply plugin: 'com.android.library'

话虽如此,您的构建脚本还有其他问题.例如,这是一个顶层构建脚本(如注释中所示的可以在其中添加配置选项的顶层构建文件..."所示),因此实际上可能没有顶层脚本级别模块适用于android块,因此添加apply plugin语句可能只会导致其他错误.如果发生这种情况,请删除android块.

Having said that, there are other problems with your build script. For one, this is a top-level build script (as you can see by the comment that says "Top-level build file where you can add configuration options..."), so it's likely that there isn't actually a top-level module for the android block to apply to, so adding the apply plugin statement may just lead to a different error. If that happens, remove the android block.

另一个问题是此构建脚本中已经有一个apply plugin: 'java'语句.您不能在同一构建脚本中同时使用Java和Android插件.他们彼此碰撞.

Another issue is that you already have a apply plugin: 'java' statement in this build script. You can't use both the Java and the Android plugins in the same build script; they collide with each other.