43

I'm working the basic android application , I do not know where to add the jar file in the android studio.

Seenu S
  • 3,381
  • 6
  • 30
  • 45
  • If that .jar file is any api you want to use in your project then copy it in `yourProject/app/libs` directory – Apurva Mar 23 '15 at 10:05
  • i add the jar in the libs folder but it's not taking – Seenu S Mar 23 '15 at 10:06
  • also add `compile fileTree(include: ['*.jar'], dir: 'libs')` under `dependencies {...}` in `gradle.build` – Apurva Mar 23 '15 at 10:09
  • Error:(7, 0) Gradle DSL method not found: 'compile()' Possible causes: The project 'App' may be using a version of Gradle that does not contain the method. Gradle settings.The build file may be missing a Gradle plugin. – Seenu S Mar 23 '15 at 10:12
  • buildscript { repositories { jcenter() } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') classpath 'com.android.tools.build:gradle:1.1.0' } } allprojects { repositories { jcenter() } } – Seenu S Mar 23 '15 at 10:22
  • You are adding in wrong `gradle.build` remove it from `gradle.build(Project:projectName)` and add in `gradle.build(Module:app)` see my answer – Apurva Mar 23 '15 at 10:31
  • refer this http://stackoverflow.com/questions/16608135/android-studio-add-jar-as-library – Fahim Mar 23 '15 at 10:33
  • This is my post. You may find it useful. I tried to explain 3 different approaches for importing JAR files into Android studio step by step by screenshots. Please visit this link: [http://stackoverflow.com/a/35345492/5475941][1] [1]: http://stackoverflow.com/a/35345492/5475941 – Mohammad Feb 11 '16 at 17:04

2 Answers2

68

You can add the jar file in the android studio as follows:

  1. Add a folder in your project named "Libs" and keep the jar files inside this folder , which you want to use in your project.

  2. In the "Project->Project" view, You will be able to see the jar file from android studio (you may not see it in the "Project->android" view). Right click on the jar file and select the option "Add as Library" and Click Ok.

Hong
  • 526
  • 6
  • 21
Prince
  • 734
  • 7
  • 6
24

First copy the .jar file in yourproject/app/libs directory

Then open your gradle.build(Module:app) and copy compile fileTree(include: ['*.jar'], dir: 'libs') in dependencies{}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.2'
    defaultConfig {
        applicationId "com.android...."
        minSdkVersion 9
        ....
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs') <--- here
    compile 'com.android.support:appcompat-v7:21.0.3'
}

After this select: Tools -> Android -> Sync Project with Gradle Files

DevB2F
  • 4,674
  • 4
  • 36
  • 60
Apurva
  • 7,871
  • 7
  • 40
  • 59
  • I've tried this and still no go. Noticed `libs` doesn't show up in my project tree, even though it is definitely in the file system. – trans Feb 07 '17 at 19:04
  • @trans it happens if Android Studio can't refresh your project tree. Collapse project directory and reopen in project tree, it should show your libs dir or restart Android Studio. – Apurva Feb 08 '17 at 05:10