所以我将 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
更新到 Android Build Tools 25.1.6 GCM/FCM 后出现 IncompIncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM(更新到 Android Build Tools 25.1.6 GCM/FCM 后出现 Incompatible
如何在 gradle 中获取当前风味How to get current flavor in gradle(如何在 gradle 中获取当前风味)
如何修复“意外元素<查询>在“清单How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修复“意外元素lt;查询gt;在“清单中找到错误
基于 Android Gradle 中多风味库的多风味应用Multi flavor app based on multi flavor library in Android Gradle(基于 Android Gradle 中多风味库的多风味应用)
Android 依赖在编译和运行时有不同的版本Android dependency has different version for the compile and runtime(Android 依赖在编译和运行时有不同的版本)
本地 aar 库的传递依赖Transitive dependencies for local aar library(本地 aar 库的传递依赖)