Importing External .Jar File to Android Project

Importing external jar file in Android Studio---NoClassDefFoundError

I found the solution to my problem. Since I've been lost on this for hours I'll keep the thread instead of deleting it.

The jar I was importing had been compiled/exported with Java 7 in mind. Once I enabled compliance with Java 6 it worked fine.

To sum it up, when adding an external jar file in Android Studio:

  1. Copy jar to root/project/libs folder;
  2. Right-click and add as library;
  3. Add the jar to root/project/build.gradle (something like compile files('libs/test-jar-to-import.jar'));
  4. Make sure the imported jar complies with Java 6 (7 will not do, for now).

Importing Class from External Jar, Android

Take a look here
http://developer.android.com/guide/appendix/faq/commontasks.html#addexternallibrary
are you placing the jar in subfolder of your project ?

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 - Importing external Library/Jar

So,

Steps to follow in order to import a JAR sucesfully to your project using Android Studio 0.1.1:

  • Download the library.jar file and copy it to your /libs/ folder inside your application project.
  • Open the build.gradle file and edit your dependencies to include the new .jar file:

compile files('libs/android-support-v4.jar', 'libs/GoogleAdMobAdsSdk-6.4.1.jar')

  • File -> Close Project
  • Open a command prompt on your project's root location, i.e 'C:\Users\Username\AndroidStudioProjects\MyApplicationProject\'
  • On the command prompt, type gradlew clean, wait till it's done.
  • Reopen your application project in Android Studio.
  • Test run your application and it should work succesfully.

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



Related Topics



Leave a reply



Submit