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:
- Put the Gson jar (in my case,
gson-2.2.4.jar
) into thelibs
folder - Right click it and hit 'Add as library'
Ensure that
compile files('libs/gson-2.2.4.jar')
is in yourbuild.gradle
file (orcompile fileTree(dir: 'libs', include: '*.jar')
if you are using many jar files)Edit : Use
implementation files('libs/gson-2.2.4.jar')
(orimplementation fileTree(dir: 'libs', include: '*.jar')
) in Android Studio 3.0+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
- Copy JAR File to libs Folder
- Register module in build.gradle file, instructions for which are given in steps 3 through 9
- Open file menu and click on project structure
- Now in Project Structure dialog box select app under module
- Now Click on Dependencies tab in project structure dialog
- Click on + sign in right side corner
- Select File Dependency from list
- Select jar file from libs folder
- Click apply and Ok
- 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
Select Import .JAR/.AAR
Package
Select the .JAR/.AAR file and put a module name
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
Android Activity Life Cycle - What Are All These Methods For
Failed to Resolve: Com.Android.Support:Cardview-V7:26.0.0 Android
Example: Communication Between Activity and Service Using Messaging
Determining the Current Foreground Application from a Background Task or Service
How to Add Dividers and Spaces Between Items in Recyclerview
Recyclerview Inside Scrollview Is Not Working
How to Listen For a Webview Finishing Loading a Url
How to Change the Font on the Textview
Passing Android Bitmap Data Within Activity Using Intent in Android
How to Hook into the Power Button in Android
How to Get a List of Installed Android Applications and Pick One to Run
Making Textview Scrollable on Android
Replace Fragment Inside a Viewpager
Communicating Between a Fragment and an Activity - Best Practices
Android Toolbar Center Title and Custom Font