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-objects. But the library somehow isn't included in the build.
I had created a new project with just a MainActivity. Copied gson-2.2.3.jar in the /libs folder and added it as a library dependancy(right click->Add as library). This includes the jar in android studio so it can be referenced from the source files.
When I try to run the project it cannot compile so I added:
compile files('libs/gson-2.2.3.jar')
to the dependencies in de .gradle file. After that it compiles correctly but when running the application I get a ClassDefNotFoundException
.
Does anyone know what I'm doing wrong?
I have read all the answers here and they all seem to cover old versions of Android Studio!
With a project created with Android Studio 2.2.3 I just needed to create a
libs
directory underapp
and place my jar there. I did that with my file manager, no need to click or edit anything in Android Studio.Why it works? Open Build / Edit Libraries and Dependencies and you will see:
libs
folder at the level ofapp
.jars
in this project.libs
folder,add library
I observed CTRL + ALT + SHIFT + S --> project structure --> app-module -->Dependencies" already had an entry as
(dir: 'libs', include: '*.jar')
undercompile-option
, initially. And after adding the jar's as per the steps stated above, thebuild.gradle
got the entries for the new added jar's, itself.In Android Studio 2.1 I follow the this way,
Goto app -> src-> main -> assets folder (If not available create it) -> put your JAR files
In your build.gradle add dependency like this,
Sync now. Now your JAR files ready to use.
Download & Copy Your
.jar
file inlibs
folder then adding these line to build.gradle:Do not forget to click "Sync now"
I made it work by just adding one line to build.gradle:
Do not forget to click "Sync now" in the top right corner.
I´m using Android Studio 1.0.1.
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