Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 

project explorer

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') 

build.gradle

And got an error message: cannot resolve symbol dependencies

Another question, where would the libs folder be. Does it mean the External Libraries?

like image 831
ant2009 Avatar asked Sep 11 '13 08:09

ant2009


People also ask

Where do I put libraries in Android Studio?

To use your Android library's code in another app module, proceed as follows: Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Library Dependency in the dropdown. In the Add Library Dependency dialog, use the search box to find the library to add.

Where is the JAR file in Android Studio?

How to find the libs folder in Android Studio? If you are unable to find the libs folder in Android studio then open your android project in “Project” mode If the project is already opened in the “Android” mode. Then go to Your Project Name > app > libs and right-click on it and paste the downloaded JAR files.

Can I run jar files on Android?

You cannot directly run jar files in android as android runs on Dalvik Virtual Machine , whereas to run jar files you will need Java Runtime Environment which has Java Virtual Machine .

Can use Java library in Android Studio?

To use a Java library (JAR file) inside your Android project, you can simple copy the JAR file into the folder called libs in your application. *. jar files in this folder are included into the compile classpath via the default build.


1 Answers

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.

open project structure

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

project structure

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

add jar

  1. Click plus icon then select File dependency

File dependency

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

jar path

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

imported jar file

like image 106
Silambarasan Poonguti Avatar answered Oct 07 '22 02:10

Silambarasan Poonguti