Search code examples
androidnoclassdeffounderrortwitter4jandroid-studio

How to fix NoClassDefFoundError in twitter4j using Android Studio?


I want to integrate my project with Twitter. So, I'm using the twitter4j for this. And I'm using gradle to manage the dependencies.

Currently, I am facing this issue:

java.lang.NoClassDefFoundError: twitter4j.conf.ConfigurationBuilder

I've googled and find a solution, that is to change the name of "lib" folder to "libs", but this is for Eclipse. How can I fix this issue in Android Studio?

Thank you!


Solution

  • In your build.gradle, add the following in the dependencies section:

    compile files('libs/android-support-v4.jar', 'libs/twitter4j.jar')
    

    or if you want to automatically add all jars in the libs directory:

    compile fileTree(dir: "libs", include: "*.jar")
    

    You might need to run this on the command line:

    ./gradlew clean