I\'m trying to use the new Android Studio but I can\'t seem to get it working correctly.
I\'m using the Gson library to serialize/deserialize JSON-o
Here are the instructions for adding a local jar file as a library to a module:
Create a 'libs' folder in the top level of the module directory (the same directory that contains the 'src' directory)
In the build.gradle file
add the following so that your dependencies closure has:
dependencies {
// ... other dependencies
compile files('libs/<your jar's name here>')
}
Android Studio should have already setup a gradlew wrapper. From the command line, navigate to the top level of your project (the directory that has a gradlew
file).
Run ./gradlew assemble
. This should compile the project with the library. You may need to fix errors in your build.gradle file as necessary.
In order to have Android Studio recognize the local jar files as libraries for support while coding in the IDE, you need to take a few more steps:
4.1. Right click on the module in the left hand panel and choose Open Library Settings
.
4.2. On the left panel of the dialog, choose Libraries
.
4.3. Click the +
sign above the panel second from the left -> Java
4.4. Select your local jar and add it to the project.
You may need to run the above ./gradlew
command one more time
Ive done above 3 steps and its work charm for me.
(I am using Android Studio 2.1.2)
Step 1
compile 'com.squareup.okhttp3:okhttp:3.3.1'
) into gradle build script under build.gradle(Module:app).Step 2: Right click on app folder -> New -> Module
Step 3: Click Import JAR/.AAR Package Then browse your package. as an example: OkHttp.jar
Put the .jar
files in libs
folder of the Android project.
Then add this line of code in the app's gradle file:
compile fileTree(dir: 'libs', include: ['*.jar'])
For Android gradle plugin 3.0 and later, it is better to use this instead:
implementation fileTree(dir: 'libs', include: ['*.jar'])
Unlike Eclipse we don't need to download jar and put it in /libs folder. Gradle handles these things we only need to add Gradle dependencies, Gradle downloads it and puts in gradle cache.
We need to add dependencies as:
dependencies {implementation 'com.google.code.gson:gson:2.2.4'}
thats it However we can also download jar & add that as library but the best practice is to add Gradle dependencies.
menu File -> project struct -> module select "app" -> dependencies tab -> + button
-> File dependency -> PATH/myfile.jar
In android Studio 1.1.0 . I solved this question by following steps:
1: Put jar file into libs directory. (in Finder)
2: Open module settings , go to Dependencies ,at left-bottom corner there is a plus button. Click plus button then choose "File Dependency" .Here you can see you jar file. Select it and it's resolved.