Could not find method compile()

故事扮演 提交于 2021-02-08 03:41:27

问题


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 ?


回答1:


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 !
}


来源:https://stackoverflow.com/questions/46049022/could-not-find-method-compile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!