importing jar libraries into android-studio
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:
1) Drag the jtwitter.jar into the root directory of my project explorer, see picture
2) File | project structure
3) Modules | yamba-yamba | dependencies
4) Click the plus sign | jars or directories | and navigate to jtwitter jar | click ok
When I import the jar file I get the following error:
import winterwell.jtwitter.Twitter;
Cannot resolve symbol winterwell
Gradle: error: package winterwell.jtwitter does not exist
I researched and found that android-studio has some issues and that you have to edit the build.gradle
file yourself.
So I tried adding this to my build.gradle file:
dependencies {
compile files('libs/jtwitter.jar')
And got an error message: cannot resolve symbol dependencies
Another question, where would the libs folder be. Does it mean the External Libraries
?
Solution 1:
Try this...
- Create libs folder under the application folder.
- Add .jar files to libs folder.
- Then add .jar files to app's build.gradle dependency.
- Finally Sync project with Gradle files.
1.Create libs folder:
2.Add .jar to libs folder:
3.Edit app's build.gradle dependency:
- Open app/build.gradle
4.Sync project with Gradle files:
- Finally add .jar files to your application.
UPDATE:
Here I'm going to import org.eclipse.paho.client.mqttv3.jar file to our app module.
- Copy your jar file and paste it in directory called libs.
- Press Ctrl + Alt + Shift + s or just click project structure icon on the toolbar.
- Then select your module to import .jar file, then select dependencies tab.
- Click plus icon then select File dependency
- Select .jar file path, click OK to build gradle.
- Finally we're imported .jar file to our module.
Solution 2:
Updated answer for Android Studio 2
The easy and correct way to import a jar/aar into your project is to import it as a module.