找不到方法compile() [英] Could not find method compile()

查看:111
本文介绍了找不到方法compile()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在android studio中添加一个lib,但无法正常工作.这是屏幕截图

我也试图在gradle.build中添加一个依赖项,但这也行不通.也许是因为我落后于代理人了?

解决方案

使用了错误的 build.gradle 文件.

您不能在顶级文件中使用 compile .
使用 module/build.gradle .

< PROJECT_ROOT> \ app \ build.gradle 是特定于应用程序模块的.

< PROJECT_ROOT> \ build.gradle 顶级构建文件" ,您可以在其中添加所有子项目/模块共有的配置选项./p>

此外,您还应该将库包含在 dependencies 块中,而不是在 buildscript 块中.

顶级文件示例:

  buildscript {储存库{jcenter()}依赖项{classpath'com.android.tools.build:gradle:2.3.0'classpath'com.google.gms:google-services:3.0.0'}} 

app \ build.gradle 中,您仅定义模块的属性:

  apply插件:"com.android.application"安卓 {compileSdkVersion ...buildToolsVersion ...}依赖项{//..... 这里 !} 

I want to add a lib in android studio but it is not working. Here is a screenshot

I also tried to add a dependency in the gradle.build but that also does not work. Maybe it is because I am behind a proxy ?

解决方案

You are using the wrong build.gradle file.

You can't use compile in the top-level file.
Use the module/build.gradle.

<PROJECT_ROOT>\app\build.gradle is specific for app module.

<PROJECT_ROOT>\build.gradle is a "Top-level build file" where you can add configuration options common to all sub-projects/modules.

Also you should include the libraries in the dependencies block, not inside the buildscript block.

Top level file example:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
       classpath 'com.android.tools.build:gradle:2.3.0'
       classpath 'com.google.gms:google-services:3.0.0'
    }
}

In the app\build.gradle you define only the properties for the module:

apply plugin: 'com.android.application'


android {
    compileSdkVersion ...
    buildToolsVersion ...
}

dependencies {
    //..... HERE !
}

这篇关于找不到方法compile()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆