How to add classpath in an Android Studio project

假如想象 提交于 2019-12-17 19:26:00

问题


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?


回答1:


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




回答2:


Thanks to Arnold Layne, I created a folder named libs.

Then, I went to

Files -> Project Structure (new menu opens) -> Modules (on the left) -> app -> Dependencies

There, I could add the library with the + Button.

This created this entry:

dependencies {
    implementation files('libs/commons-lang3-3.7.jar')
}


来源:https://stackoverflow.com/questions/26521836/how-to-add-classpath-in-an-android-studio-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!