问题描述
我正在尝试下载并运行现有的android studio项目,当前出现错误:
I am trying to download and run an existing android studio project and currently I am getting the error:
error: package com.google.gson does not exist
需要gson的Java文件位于主应用程序部分. gson-2.8.1.jar
文件位于libs
文件夹内的client
库中.
The java file that needs gson is in the main app section. The gson-2.8.1.jar
file is in a client
library inside of a libs
folder.
所以文件结构看起来像:
So the file structure looks a little like:
project_root
|-- app/
| |-- src/
| |-- main/
| |-- java/
| |-- com.company.stuff/
| |-- controller
| |-- fileThatUsesGson.java
|-- client/
|-- libs/
|-- gson-2.8.1.jar
应用程序build.gradle
显示:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(path: ':client')
}
客户端build.gradle
显示:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation files('libs/gson-2.8.1.jar')
}
这似乎是一个较旧的项目.我不得不将compile
更改为implementation
,这似乎可能是问题的一部分,但我似乎无法弄清楚如何添加这些.jar
文件.
This does seem to be an older project. I had to change compile
to implementation
which seems like it might be part of the problem but I can't seem to figure out how to add those .jar
files.
任何帮助将不胜感激.谢谢!
Any help would be appreciated. Thanks!
推荐答案
扩大AF先生的答案:
在我添加的应用程序build.gradle
文件中
In the app build.gradle
file I added
dependencies {
implementation files('../client/libs/gson-2.8.1.jar')
}
sync project with gradle files
和make project
原始
File ->Project Structure ->App-> dependencies -> + ->add library
这篇关于如何在Android库中包含内部jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!