本文介绍了如何在Android Studio项目中添加类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android项目,该项目的Android应用程序依赖于纯Java库(该Java库使用其他一些编译的jars库).
我添加了依赖项,可以构建该项目,但是在运行时我有一个ClassNotFoundException错误.
我必须将的路径添加到CLASSPATH environment变量.
有没有一种方法可以只在本地为项目设置类路径,例如使用命令行选项

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>

在Android Studio中运行/调试配置?

in the Android studio Run/Debug Configurations?

推荐答案

首先,请确保项目的"app"文件夹中有一个"libs"子文件夹.如果没有,请创建一个.接下来,在app/build.gradle文件中,添加以下代码行:

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'])
    ...
}

将所有.jar文件放置在"libs"文件夹中,瞧,就完成了

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

这篇关于如何在Android Studio项目中添加类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:34