如何在android studio的外部库中添加jar

[英]How to add a jar in External Libraries in android studio


I am new to Android Studio.Now what i need was just want to add a few jar file in the External Libraries below the < JDK > folder.

我是Android Studio的新手。现在我只需要在< JDK >文件夹下的外部库中添加几个jar文件。

enter image description here

If anyone have idea about this please help me

如果有人知道这件事,请帮助我

9 个解决方案

#1


187  

A late answer, although I thought of giving an in-depth answer to this question. This method is suitable for Android Studio 1.0.0 and above.

虽然我想对这个问题做个深入的回答,但回答得有点晚。此方法适用于Android Studio 1.0.0及以上版本。


STEPS

步骤


  1. First switch your folder structure from Android to Project.
  2. 首先将文件夹结构从Android切换到Project。

enter image description here

  1. Now search for the libs folder inside app - build folder.
  2. 现在在app - build文件夹中搜索libs文件夹。

enter image description here

  1. Once you have pasted the .jar file inside libs folder. Right click on the jar file and at end click on Add as library. This will take care of adding compile files('libs/library_name.jar') in build.gradle [You don't have to manually enter this in your build file].
  2. 在libs文件夹中粘贴.jar文件之后。右键单击jar文件,最后单击Add as library。这将负责在构建中添加编译文件(“libs/library_name.jar”)。gradle(你不需要在你的构建文件中手动输入)。

enter image description here

Now you can start using the library in your project.

现在可以开始在项目中使用库了。

#2


98  

Add your jar file to the folder app/libs. Then right click the jar file and click "add as library".

将jar文件添加到文件夹应用程序/libs。然后右键单击jar文件,然后单击“添加为库”。

If there is no libs folder you can create it. Click on the combo box that says "Android", and change it to "Project"

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

enter image description here

From here, you can right click on "apps" in the directory tree and go to "New" => "Directory"

从这里开始,你可以右键点击目录树中的“apps”,进入“New”=>“directory”

#3


36  

Put your JAR in app/libs, and in app/build.gradle add in the dependencies section:

把你的JAR放到app/libs中,在app/build中。附件部分的附加等级:

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

编译fileTree(dir: 'libs',包括:['*.jar'])

#4


18  

Create "libs" folder in app directory copy your jar file in libs folder right click on your jar file in Android Studio and Add As library... Then open build.gradle and add this:

在app目录中创建“libs”文件夹,在libs文件夹中复制你的jar文件,在Android Studio中单击你的jar文件,然后添加为库…然后打开构建。gradle并添加:

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

#5


9  

This is how you can add .jar file in Android Studio 2.1.3.

这就是如何在Android Studio 2.1.3中添加.jar文件的方法。

  1. Copy the .jar file jar file copy screenshot

    将. jar文件复制

  2. paste the file in Libs folder and then right click on .jar file and press Add as library enter image description here

    将文件粘贴到Libs文件夹中,然后右键单击.jar文件,然后按下Add作为库。

  3. open build.gradle enter image description here

    打开build.gradle

  4. add lines under dependencies as shown in screenshot enter image description hereenter image description here

    在依赖项下添加行,如屏幕截图所示

  5. Now press play button and you are done adding .jar file enter image description here

    现在按play按钮,就完成了添加.jar文件

#6


8  

Example with Parse jar...

例子与解析罐子…

Add jars to libs folder from Project view … create lib folder if not exists

从项目视图中添加jar到libs文件夹,如果不存在,创建lib文件夹。

enter image description here

Copy all jars there...

复制所有罐子…

Add libs to gradle.... in build.gradle file :

添加填词gradle ....在构建。gradle文件:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.android.support:design:23.0.0'
    compile 'com.android.support:percent:23.0.0'
    compile 'com.parse.bolts:bolts-android:1.+'
    compile fileTree(dir: 'libs', include: 'Parse-*.jar’)
}

For add all jars of lib folder... change Parse-*.jar to *.jar

用于添加lib文件夹的所有jar…改变解析- *。jar * . jar

#7


2  

The GUI based approach would be to add an additional module in your project.

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

  1. From the File menu select Project Structure and click on the green plus icon on the top left.
  2. 从“文件”菜单中选择“项目结构”,点击左上方的“绿色+”图标。
  3. The new Module dialog pops
  4. 弹出新的模块对话框
  5. From the phone and tablet application group select the "Import JAR or AAR package" option and click next.
  6. 从手机和平板应用程序组选择“导入JAR或AAR包”选项并单击next。
  7. Follow the steps to create a new module that contains your JAR file.
  8. 按照步骤创建包含JAR文件的新模块。
  9. Click on the entry that corresponds to your main project and select the dependencies tab.
  10. 单击与主项目对应的条目,并选择dependencies选项卡。
  11. Add a dependency to the module that you created in step 4.
  12. 向步骤4中创建的模块添加依赖项。

One final piece of advice. Make sure that the JAR file you include is build with at most JDK 1.7. Many problems relating to error message "com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)" root straight to this :0.

最后一条建议。确保包含的JAR文件是在大多数JDK 1.7中构建的。与错误消息有关的许多问题“com.android.dx.cf.iface”。ParseException:错误的类文件魔术(cafebabe)或版本(0034.0000)“根指向这个:0。

#8


2  

A simple way to add Jar file Android Studio Steps:

一种简单的添加Jar文件Android Studio步骤的方法:

  1. Copy and paste your jar file to libs folder of your project.
  2. 复制并粘贴您的jar文件到项目的libs文件夹。
  3. Click File from File menu -> Project Structure (CTRL + SHIFT + ALT + S on Windows/Linux, ⌘ + ; on Mac OS X).
  4. 单击文件从文件菜单- >项目结构(CTRL + SHIFT + ALT + S在Windows / Linux,⌘+;在Mac OS X)。
  5. Select Modules at the left panel -> Dependencies tab.
  6. 在左侧面板-> Dependencies选项卡中选择模块。
  7. Add... → Project Library → Attach Jar.
  8. 添加……库→→项目附加Jar。

#9


1  

If anyone is looking for another solution without actually copying the jar file(s) into the project directory, e.g. when using a jar in multiple projects:

Open build.gradle and add

如果有人正在寻找另一种解决方案而实际上并没有将jar文件复制到项目目录中,例如在多个项目中使用jar时:Open build。gradle并添加

def myJarFolder = 'C:/Path/To/My/Jars'

[...]

dependencies {
    [...]
    compile fileTree(dir: myJarFolder + '/jar/Sub/Folder/1', include: ['*.jar'])
    compile fileTree(dir: myJarFolder + '/jar/Sub/Folder/2', include: ['*.jar'])
    [...]
}

Note that of course you don't have to use the myJarFolder variable, I find it useful though. The path can also be relative, e.g. ../../Path/To/My/Jars.
Tested with AndroidStudio 3.0

请注意,当然不需要使用jarmyfolder变量,但我发现它很有用。路径也可以是相对的,例如.. ../路径/到/我的/ jar。测试与AndroidStudio 3.0

Update: For Gradle Plugin > 3.0 use implementation instead of compile:

更新:对于等级插件> 3.0使用实现而不是编译:

dependencies {
        [...]
        implementation fileTree(dir: myJarFolder + '/jar/Sub/Folder/1', include: ['*.jar'])
        implementation fileTree(dir: myJarFolder + '/jar/Sub/Folder/2', include: ['*.jar'])
        [...]
    }
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2014/09/04/6be81164851e486bcc1b1ee26bcb346c.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告