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:
- Copy jar to root/project/libs folder;
- Right-click and add as library;
- Add the jar to root/project/build.gradle (something like
compile files('libs/test-jar-to-import.jar')
); - 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
Select Import .JAR/.AAR
Package
Select the .JAR/.AAR file and put a module name
Add the module as a dependency
Related Topics
Android: Specify Two Different Images for Togglebutton Using Xml
Apache Http Client or Urlconnection
Android: Changing Background-Color of the Activity (Main View)
Converting Epoch Time to Date String
How to Install Rjava in R 3.0 in Ubuntu 13.04
Python: How to Execute a Jar File Through a Python Script
Jackson Serialization: Ignore Empty Values (Or Null)
Android: How to Hide Actionbar on Certain Activities
Convert a String to a Byte Array and Then Back to the Original String
Why Do We Have to Call Super in Android Sometimes
Portrait for Phone, Landscape for Tablet (Android-Layout)
R.Raw.Anything Cannot Be Resolved
Is There an Advantage to Running Jruby If You Don't Know Any Java