Android Gradle cannot find symbol class Gson(Android Gradle 找不到符号类 Gson)
问题描述
所以我将 gson-2.2.4.jar 添加到 libs 目录(我使用的是 android studio).我的项目找不到 Gson 的东西,所以我将它作为库依赖项添加到项目结构"中的模块中.当我尝试运行该项目时,构建失败并出现以下错误:
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
为什么我不能让它工作?我在别处读到,如果将 Gradle 放在 lib 目录中,Gradle 应该会自动处理所有内容.
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.
推荐答案
在项目结构设置中将其添加为依赖项是不够的.该设置仅适用于 IDE.要真正构建,Gradle 还需要意识到这一点.您必须像这样将 .jar 文件添加到 build.gradle 文件中......
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android Gradle 找不到符号类 Gson


基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01