importing jar libraries into android-studio

后端 未结 13 1530
孤独总比滥情好
孤独总比滥情好 2020-11-29 01:32
android-studio 0.2.7
Fedora 18

Hello,

I am trying to add the jtwitter jar to my project.

First I tried doing the following:

相关标签:
13条回答
  • 2020-11-29 01:57

    Running Android Studio 0.4.0 Solved the problem of importing jar by

    Project Structure > Modules > Dependencies > Add Files
    Browse to the location of jar file and select it
    

    For those like manual editing Open app/build.gradle

    dependencies {
        compile files('src/main/libs/xxx.jar')
    }
    
    0 讨论(0)
  • 2020-11-29 02:01

    Android Studio 1.0.1 doesn't make it any clearer, but it does make it somehow easier. Here's what worked for me:

    1) Using explorer, create an 'external_libs' folder (any other name is fine) inside the Project/app/src folder, where 'Project' is the name of your project

    2) Copy your jar file into this 'external_libs' folder

    3) In Android Studio, go to File -> Project Structure -> Dependencies -> Add -> File Dependency and navigate to your jar file, which should be under 'src/external_libs'

    3) Select your jar file and click 'Ok'

    Now, check your build.gradle (Module.app) script, where you'll see the jar already added under 'dependencies'

    0 讨论(0)
  • 2020-11-29 02:02

    Try this...

    1. Create libs folder under the application folder.
    2. Add .jar files to libs folder.
    3. Then add .jar files to app's build.gradle dependency.
    4. Finally Sync project with Gradle files.

    1.Create libs folder:

    enter image description here

    2.Add .jar to libs folder:

    enter image description here

    3.Edit app's build.gradle dependency:

    • Open app/build.gradle

    enter image description here

    4.Sync project with Gradle files:

    • Finally add .jar files to your application.

    enter image description here

    UPDATE:

    Here I'm going to import org.eclipse.paho.client.mqttv3.jar file to our app module.

    1. Copy your jar file and paste it in directory called libs.

    1. Press Ctrl + Alt + Shift + s or just click project structure icon on the toolbar.

    1. Then select your module to import .jar file, then select dependencies tab.

    1. Click plus icon then select File dependency

    1. Select .jar file path, click OK to build gradle.

    1. Finally we're imported .jar file to our module.

    Happy coding...

    0 讨论(0)
  • 2020-11-29 02:02

    I also faced same obstacle but not able to find out solution from given answers. Might be it's happening due to project path which is having special characters & space etc... So please try to add this line in your build.gradle.

    compile files('../app/libs/jtwitter.jar')// pass your .jar file name
    

    ".." (Double dot) will find your root directory of your project.

    0 讨论(0)
  • 2020-11-29 02:03

    If the code for your jar library is on GitHub then importing into Android Studio is easy with JitPack.

    Your will just need to add the repository to build.gradle:

    allprojects{
     repositories {
        jcenter()
        maven { url "https://jitpack.io" }
     }
    }
    

    and then the library's GitHub repository as a dependency:

    dependencies {
        // ...
        compile 'com.github.YourUsername:LibraryRepo:ReleaseTag'
    }
    

    JitPack acts as a maven repository and can be used like Maven Central. The nice thing is that you don't have to upload the jar manually. Behind the scenes JitPack will check out the code from GitHub and compile it. Therefore it works only if the repo has a build file in it (build.gradle).

    There is also a guide on how to prepare an Android project.

    0 讨论(0)
  • 2020-11-29 02:05

    Android Studio 1.0 makes it easier to add a .jar file library to a project. Go to File>Project Structure and then Click on Dependencies. Over there you can add .jar files from your computer to the project. You can also search for libraries from maven.

    0 讨论(0)
提交回复
热议问题