Android studio Gradle无法找到方法compile()

Mar*_*sen 7 android android-studio

过去两天我试图找到解决这个问题的方法,但没有运气.

我想包括GSONlib.进入我的android项目.

这是我的文件夹结构的图片:

夹

现在在我的build.gradle中,我有以下内容:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

dependencies {
    compile files('libs/gson-2.2.4.jar')
}
Run Code Online (Sandbox Code Playgroud)

我也右键单击了gson-2.2.4.jar并将其添加为lib.

当我编译时,我得到以下错误:

    Gradle: A problem occurred evaluating root project 'notebox-android'.
> Could not find method compile() for arguments [directory 'libs'] on root project 'notebox-android'.
Run Code Online (Sandbox Code Playgroud)

谁能帮我这个?

如果您需要更多信息,请告诉我!

VJ *_*ons 10

这个问题的答案可能会帮助您正确导入您的gson库并避免任何编译/链接问题:Android Studio - 导入外部库/ Jar.另一个相关链接:Android Studio:添加jar作为库?接受的答案.两个答案都说同样的话.gradlew clean添加/导入jar文件并编辑build.gradle文件后.

HTH.

编辑:有两个build.gradle文件.您应该编辑项目文件夹下的build.gradle而不是project-root文件夹下的build.gradle.