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:
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')
}
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'
Try this...
1.Create libs folder:
2.Add .jar to libs folder:
3.Edit app's build.gradle dependency:
4.Sync project with Gradle files:
UPDATE:
Here I'm going to import org.eclipse.paho.client.mqttv3.jar file to our app module.
Happy coding...
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.
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.
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.