Home Android Studio: Add jar as library?

# Android Studio: Add jar as library?

user7128
1#
user7128 Published in September 20, 2018, 12:47 pm

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?

• Refer : stackoverflow.com/a/6859020/28557 – Vinayak Bevinakatti Aug 26 '16 at 18:50
• Although this doesn't solve the problem, just wanna point that "compile" was deprecated in favor of "implementation". – Amir Rezazadeh Jun 17 at 14:32