本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 05:23