Android Studio: Add Jar as Library

Adding external library (.jar) in Android Studio

I ran the gradlew.bat file, which gave me the following Exception:

Exception in thread "main" java.lang.RuntimeException: Could not determine wrapper version.at
org.gradle.wrapper.GradleWrapperMain.wrapperVersion(GradleWrapperMain.java:111)at
org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)Caused by:
java.lang.RuntimeException: No build receipt resource found.at
org.gradle.wrapper.GradleWrapperMain.wrapperVersion(GradleWrapperMain.java:97)... 1 more

which brought me to this answer and indeed i had used an ! in my project name. Removing it somehow solved the problem.

Android Studio: Add jar as library?

I've been struggling with the same thing for many hours, trying to get the Gson jar to work no less. I finally cracked it – here are the steps I took:

  1. Put the Gson jar (in my case, gson-2.2.4.jar) into the libs folder
  2. Right click it and hit 'Add as library'
  3. Ensure that compile files('libs/gson-2.2.4.jar') is in your build.gradle file (or compile fileTree(dir: 'libs', include: '*.jar') if you are using many jar files)

    Edit : Use implementation files('libs/gson-2.2.4.jar') (or implementation fileTree(dir: 'libs', include: '*.jar')) in Android Studio 3.0+

  4. Do a clean build (you can probably do this fine in Android Studio, but to make sure I navigated in a terminal to the root folder of my app and typed gradlew clean. I'm on Mac OS X, the command might be different on your system

After I did the above four, it started working fine. I think the 'Add as library' step was the one I'd previously missed, and it didn't work until I cleaned it either.

[Edit - added the build.gradle step which is also necessary as others have pointed out]

How to add external dependencies (jar file) to android studio?

Step wise

  1. Copy JAR File to libs Folder
  2. Register module in build.gradle file, instructions for which are given in steps 3 through 9
  3. Open file menu and click on project structure
  4. Now in Project Structure dialog box select app under module
  5. Now Click on Dependencies tab in project structure dialog
  6. Click on + sign in right side corner
  7. Select File Dependency from list
  8. Select jar file from libs folder
  9. Click apply and Ok
  10. Finally click on sync gradle button

One more thing, check for proxy connection if you are using it.

importing jar libraries into android-studio

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.

New -> Module

Right click on the main project and New -> Module

Select Import .JAR/.AAR Package

Import .JAR/.AAR Package

Select the .JAR/.AAR file and put a module name

Select the .JAR/.AAR file

Add the module as a dependency

Add the module as a dependency

How to add and import .jar files in android stduio

Did you tell the gradle script to compile your jar file?

you can follow this link
Android Studio: Add jar as library?

Simply add this line in your app gradle

implementation files('libs/ksoap2_3.6.3.jar')

Error in adding external Jar libraries in android studio

When you add any module dependency then it will not automatically added to gradle file.

You have to add that dependancy to gradle file manually..

Now here you are adding module to Android Studio project then, You have to add

  compile project(':module_name') 

So that you module will be attached to your app module.

Hope It will help.

Thank you.!



Related Topics



Leave a reply



Submit