我是Android Studio的新手。 我如何在< JDK >文件夹下面的外部库中添加几个jar文件?


当前回答

在你的android项目中添加一个罐子的“官方方式” 外部库,是在jar中添加依赖项{}节 build.gradle。

如果你做了以上所有的事情,但没有一个奏效,那么还有另外两种可能:

If Android Studio or some other IDE doesn't give red underlined errors in editor but runs in error in the Java Compiler, CHECK YOUR JAR. Your jar may not have a proper Manifest included therefore the compiler doesn't know what the jar can provide/don't know it's package name Maybe it's folder structure is messed up. The folder structure doesn't match with its package name. package a.b.c; should be matching to folder a > folder b > folder c. The package name has some conflict. (Trust me, this happened to me and it took hours to figure it out.)


然而,如果你打算用cordova,这里有一些添加外部罐子的技巧。

“build-extras。Gradle”是更好的管理Gradle文件的方法。

下面是在基于cordova的android项目中管理额外设置的步骤:

添加jar到build-extras.gradle: //其他设置在这里,例如:buildscript{…} ext.postBuildExtras = { //你可能有一些其他的设置,例如:android{…} 依赖关系{ 编译文件(“libs / abc.jar”) } }

(更详细的步骤在这里:扩展cordova gradle文件以包括谷歌服务)

在终端,做:

Cordova构建android

其他回答

将jar文件添加到app/libs文件夹中。然后右键单击jar文件并单击“添加为库”。

如果没有libs文件夹,您可以创建它。点击“Android”组合框,并将其更改为“项目”

从这里,你可以右键单击目录树中的“apps”,然后点击“New”=>“directory”

在应用程序目录中创建“libs”文件夹,将jar文件复制到libs文件夹中,右键单击Android Studio中的jar文件,并添加为库… 然后打开构建。Gradle并添加这个:

dependencies {
    implementation files('libs/your jar file.jar')
}

手动:

在项目中添加libs文件夹(Where build。Gradle被定位)。例如,应用程序 移动.jar到lib 在build.gradle中添加实现文件('libs/<name>.jar')。它与UI Add as library do相同

基于GUI的方法是在项目中添加一个额外的模块。

从“文件”菜单中选择“项目结构”并单击绿色部分 左上角的加号图标。 弹出新的Module对话框 从手机和平板电脑应用程序组中选择“Import JAR or AAR package”选项,然后单击下一步。 按照以下步骤创建一个包含JAR文件的新模块。 单击与主项目相对应的条目,并选择依赖项选项卡。 向步骤4中创建的模块添加依赖项。

最后一条建议。确保您包含的JAR文件最多是用JDK 1.7构建的。关于“com.android.dx.cf.iface”错误消息的许多问题。错误的类文件magic (cafebabe)或version(0034.0000)"根直接到这个:0。

如果你没有看到“添加为库”选项,确保你解压(解压缩)你的文件,使你有mail.jar而不是mail.zip。

然后右键单击你的文件,你可以看到“添加为库”选项。