Krystian
Krystian

Reputation: 3423

JAR libs are not added to the apk file

I've moved my project from ant build to gradle build, but I can't get it to use the jars from my libs directory.

  1. I have created app/libs directory
  2. I have moved there my jars
  3. I have added compile fileTree(dir: 'libs', include: '*.jar') to the app/build.gradle

Unfortunately, it didn't work, the classes from those jars are not available during runtime. I have ran the gradle from command line with debug option, to check the whole output, and it's clear to me that they are not processed.

I know I'm doing something wrong, but I have no idea what. I thought that in my other projects I have used it multiple times, but after going through every one of them, I can see that I have never used jars loaded from libs directory.

What am I missing?

Upvotes: 2

Views: 1569

Answers (2)

bastami82
bastami82

Reputation: 6153

I assume you are using Android Studio and you have a .jar file which you want to include in your project : (get rid of any changes you made in that matter- I just opened a new empty project:)

  1. right click on your app name in project structure column and click on 'open Module settings' enter image description here
  2. go to dependency tab and click on '+' and click on 'Jar dependency' and navigate to your jar library (you can also look for a online library dependency from 'library dependency' if you do not have local library)enter image description here
  3. that's it , it will add your jar library to your project (automatically will add it to the app/build.gradle)

Edited:


if you are not using Gui then add this to your Gradle under dependencies

compile fileTree(include: '*.jar', dir: 'libs')

and make sure you have libs directory on root(with your jar in it) finally run a clean build

Upvotes: 1

Mohsin Fareed
Mohsin Fareed

Reputation: 11

First you are missing the brackets in this line fileTree(dir: 'libs', include: '*.jar'). You need to write like this

compile fileTree(dir: 'libs', include: ['*.jar'])

Then make sure that you have added your .jar files to Project Structure->app->dependencies->Plus button -> add file dependency.

Upvotes: 1

Related Questions