Android Gradle 找不到符号类 Gson

Android Gradle cannot find symbol class Gson(Android Gradle 找不到符号类 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 release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)