Android Studio Gradle 找不到方法 compile() [英] Android studio Gradle Could not find method compile()

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

问题描述

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

The past two days i have tried to find a solution to this problem but with no luck.

我正在尝试包含 GSON 库.进入我的安卓项目.

I am trying to include GSON lib. Into my android project.

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

Here is a picture of my folder structure:

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

Now in my build.gradle i have the following:

    // 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')
}

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

i have also right clicked gson-2.2.4.jar and added it as a lib.

当我编译时出现以下错误:

When i compile i get the following error:

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

谁能帮我解决这个问题?

Can anyone help me with this?

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

please tell me if you need more information!

推荐答案

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

The answer to this question might help you to import your gson library correctly and avoid any compile/link issues: Android Studio - Importing external Library/Jar. Another related link: Android Studio: Add jar as library? with accepted answer. Both answers say the same thing. gradlew clean after you add/import the jar file and edit the build.gradle file.

HTH.

有两个 build.gradle 文件.您应该编辑项目文件夹下的 build.gradle,而不是项目根文件夹下的那个.

There are two build.gradle files. You should be editing the build.gradle that's under your project folder and not the one under your project-root folder.

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

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