How to include internal jar files in android libra

2019-07-10 17:15发布

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

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

The app build.gradle shows:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(path: ':client')
}

The client build.gradle shows:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation files('libs/gson-2.8.1.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!

1条回答
一夜七次
2楼-- · 2019-07-10 17:40

Expanding on Mr.AF's answer:

In the app build.gradle file I added

dependencies {
    implementation files('../client/libs/gson-2.8.1.jar')
}

sync project with gradle files and make project

Original

File ->Project Structure ->App-> dependencies -> + ->add library 
查看更多
登录 后发表回答