如何在Android库中包含内部jar文件 [英] How to include internal jar files in android library

查看:170
本文介绍了如何在Android库中包含内部jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试下载并运行现有的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 filesmake project

原始

File ->Project Structure ->App-> dependencies -> + ->add library 

这篇关于如何在Android库中包含内部jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆