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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)