How to add classpath to Android Studio project
I have an Android project with an Android app that depends on a pure Java library (and the Java library uses some other compiled jars libraries).
I added dependencies, I can build the project, but at runtime I have an error ClassNotFoundException
. I had to add the jars CLASSPATH
path to my environment variable .
Is there a way to set the classpath only for the project, for example using the command line option
java –classpath <path to the jars>
in android studio run / debug settings?
source to share
First of all, make sure that there is a libs subfolder in the application folder of your project. If not, create it. Then in your app / build.gradle file add this line of code:
dependencies {
...
compile fileTree(dir:'libs', include: ['*.jar'])
...
}
Put all your .jar files in the libs folder and voila, you're done
source to share