Android Studio + Volley = NoClassDefFound?

一世执手 提交于 2019-12-18 05:53:45

问题


Well, I decided to try out the Volley networking library for Android and the new Android Studio IDE at the same time.. However, I'm running into some problems.

I built volley.jar, copied it into my libs folder for a new project, edited build.gradle to include volley, and setup a static ImageLoader and RequestQueue in my main activity. However, when I load the app onto an emulator (4.2), I end up getting

E/AndroidRuntime: FATAL EXCEPTION: main
        java.lang.NoClassDefFoundError: com.android.volley.toolbox.Volley

when invoking Volley as follows:

        queue = Volley.newRequestQueue(this);

Gradle edits to support the library:

dependencies {
    compile files('libs/android-support-v4.jar')
    compile files('libs/volley.jar')
}

Anyone mind pointing me in the right direction?


回答1:


Exception java.lang.NoClassDefFoundError: com.google.android.gms.common.AccountPicker

Found the fix here.

Basically, open a command prompt (or terminal) and navigate to your project directory. Use the following command on Windows:

For Windows users: gradlew.bat clean

And for mac users type: ./gradlew clean

Then reload Android Studio and try again!




回答2:


I'm sure your method works too, but I didn't even mess around with the gradle build stuff. Instead, I simply copied the com folder into my java src folder in Android Studio. It works for Eclipse too.




回答3:


  • Open "File -> Project Structure"

  • Click "Project Settings -> Modules"

  • Click "Add -> Import Module"

  • Select Volley directory on your computer that you already cloned the Volley Project via "git clone"

  • After adding Volley as a library project/module, check if there is a cyclic dependency reference to your main project under "Modules -> Volley -> Dependencies", delete it if available

  • Check if Volley module is added to your main Project Module under "Modules -> Your Projects Main Module -> Dependencies", if there is no depencency on there, click "Add -> Module Depencency"

  • After adding Volley depencency, move to "Up" if needed. I'm not sure if it's necessary.

  • Click "Project Settings -> Facets -> Volley" tick the checkbox named "Library module", to make your volley module not to run standalone but run like a module with your Project's Main module




回答4:


I was having the same error trying to run an application with volley

E/AndroidRuntime: FATAL EXCEPTION: main
        java.lang.NoClassDefFoundError: com.android.volley.toolbox.Volley

in IntelliJ.

I simply had to go into File >> Project Structure (CTRL+ALT+SHIFT+S)

to the volley module, then the associated facet and check the checkbox 'Library module' to resolve the issue.



来源:https://stackoverflow.com/questions/17002636/android-studio-volley-noclassdeffound

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!