How to include internal jar files in android library

luckyging3r :

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!

Mr.AF :

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 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=151925&siteId=1