Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add classpath in an Android Studio project

I have an Android project with an Android application that depends on a pure Java library (and the Java library uses some others compiled jars libraries).
I added the dependencies, I can build the project, but at run time I have a ClassNotFoundException error.
I had to add to theCLASSPATHenvironment variable the path to the jars.
Is there a way to set the classpath locally for the project only, like using the command line option

java –classpath <path to the jars>

in the Android studio Run/Debug Configurations?

like image 458
Stefano Piovesan Avatar asked Oct 23 '14 05:10

Stefano Piovesan


People also ask

What is class path in Android?

android.graphics.Path. The Path class encapsulates compound (multiple contour) geometric paths consisting of straight line segments, quadratic curves, and cubic curves. It can be drawn with canvas.

What is classpath in gradle?

A configuration is simply a named set of dependencies. The compile configuration is created by the Java plugin. The classpath configuration is commonly seen in the buildSrc {} block where one needs to declare dependencies for the build. gradle, itself (for plugins, perhaps).

Where do I put repositories in Android Studio?

Open the project where you want to use your cloned library, then select 'File > New > Import Module' from the Android Studio toolbar. Click the three-dotted button and navigate to your cloned repository. Select this repository, then click 'OK. '


1 Answers

First off all, be sure there's a "libs" subfolder in the "app" folder of your project. If there's not, create one. Next, in the app/build.gradle file, add this line of code:

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

Place all of your .jar files in the "libs" folder, and voila, you're done

like image 138
Arnold Layne Avatar answered Nov 15 '22 06:11

Arnold Layne