Android Gradle找不到符号类Gson [英] Android Gradle cannot find symbol class Gson

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

问题描述

所以我添加了gson-2.2.4.jar到libs目录(我正在使用android studio)。我的项目找不到gson的东西,所以我在Project Structure中将它作为库依赖项添加到我的模块中。当我尝试运行该项目时,构建失败,出现以下错误:

 错误:(12,23)Gradle:包com.google.gson不存在
错误:(37,3)Gradle:找不到符号类Gson
错误:(37,19)Gradle:找不到符号类Gson

为什么我无法工作?我在其他地方读过,如果将gradle放在lib目录中,它应该自动处理所有内容。

解决方案

将它添加为依赖项项目结构设置是不够的。该设置仅适用于IDE。为了实际构建,Gradle还需要了解它。你必须像这样将.jar文件添加到你的build.gradle文件中......

 依赖关系{
编译文件('libs / gson-2.2.4.jar')
}


So i added gson-2.2.4.jar to the libs dir (I'm using android studio). My project couldn't find the gson stuff so I added it as a library dependency to my module in the "Project Structure". When I try to run the project, the build is failing with the following errors:

Error:(12, 23) Gradle: package com.google.gson does not exist
Error:(37, 3) Gradle: cannot find symbol class Gson
Error:(37, 19) Gradle: cannot find symbol class Gson

Why can't I get this working? I read elsewhere that gradle is supposed to handle everything automatically if it's put in the lib dir.

解决方案

Adding it as a dependency in the Project Structure settings is not enough. That setting is only for the IDE. To actually build, Gradle also needs to be aware of it. You must add the .jar file to your build.gradle file like so...

dependencies {
    compile files('libs/gson-2.2.4.jar')
}

这篇关于Android Gradle找不到符号类Gson的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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