2

I want to use the Jackson ObjectMapper library to parse JSON files for an android project in Android Studio.

I downloaded jackson-core-2.5.2.jar from this link: http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.5.2/

Then I added the jar file to the ~/MyProject/app/libs folder, right clicked on it, and selected "Add as Library". I checked the build.gradle file in the app directory, and it has the line compile files('libs/jackson-core-2.5.2.jar'). I cleaned and rebuilt the file, but the line

import com.fasterxml.jackson.databind.ObjectMapper;

Has databind highlighted in red, and says that it cannot be resolved. I am confused, because the fact that it recognizes jackson must mean that the library has been added to the app right? What am I doing wrong here?

user50210
  • 93
  • 2
  • 10
  • Have you tried using gradle dependency? if, yes then have you tried by updating entire project libraries? – Mitul Gedeeya Apr 19 '15 at 06:16
  • @Mitul sorry I am very new to Android, I'm not really sure what either of those things mean – user50210 Apr 19 '15 at 06:18
  • Using [this](http://stackoverflow.com/questions/16588064/how-do-i-add-a-library-project-to-the-android-studio), you can add library. just add jackson dependency in this and then update, clean and build your project. this may be works for you – Mitul Gedeeya Apr 19 '15 at 06:20
  • @Mitul unfortunately, for this project, I have to zip it up and send it, along with any external libraries. So I'm pretty sure I have to use the .jar file – user50210 Apr 19 '15 at 06:23
  • Okay try 'com.fasterxml.jackson.core:jackson-databind:2.5.2' as dependency. it will definitly solve your problem – Mitul Gedeeya Apr 19 '15 at 06:29
  • Hey, have you got solution? – Mitul Gedeeya Apr 19 '15 at 08:21
  • @Mitul Yes, the problem was that I had downloaded jackson-core.jar instead of jackson-databind.jar. Thanks for helping me out – user50210 Apr 19 '15 at 15:52

1 Answers1

1

You are probably using the dependency with a wrong artifact. jackson-core doesn't have com.fasterxml.jackson.databind.ObjectMapper but jackson-databind. Use this in your gradle script

dependencies {
     group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.4.+'
}

Take a look here.

mushfek0001
  • 3,845
  • 1
  • 21
  • 20