简体   繁体   English

android studio java.lang.NoClassDefFoundError Gson

[英]android studio java.lang.NoClassDefFoundError Gson

I've made pretty much a fresh project. 我做了一个很新的项目。 I added in the gson library by google to my projects /libs directory and added it as a library. 我通过谷歌将gson库添加到我的projects /libs目录并将其添加为库。 I also added it into my build.gradle as 我还将它添加到我的build.gradle

compile files('libs/gson-2.2.4.jar')

So now everything looks ok, there aren't any errors given by Android Studio, no red underlines anywhere. 所以现在一切看起来都不错,Android Studio没有任何错误,任何地方都没有红色下划线。 I can build it and give it a shot. 我可以建立它并试一试。

But then I run into this error: 但后来我遇到了这个错误:

java.lang.NoClassDefFoundError: com.google.gson.Gson

Which I can see in the debugger. 我在调试器中可以看到。 The thing is i've added it in and android studio can see that but come build it gives me all these sorts of problems. 事情是我已经添加它并且android studio可以看到但是来构建它给了我所有这些类型的问题。

What am I doing wrong? 我究竟做错了什么?

Had the same issue. 有同样的问题。 What I did was gradle clean and then build my project with gradle from console. 我做的是gradle clean ,然后从控制台用gradle构建我的项目。 In my build.gradle gson dependency looks like this: 在我的build.gradle gson依赖关系如下所示:

dependencies {
    compile 'com.google.code.gson:gson:2.2.4'
}

Something went wrong in incremental build system. 增量构建系统出了问题。 One of this should help: 其中一个应该有所帮助:

  1. Menu Build -> Rebuild project 菜单构建 - >重建项目
  2. Delete folder /build 删除文件夹/构建
  3. Close Android Studio, delete /build folder 关闭Android Studio,删除/构建文件夹
  4. Right click on your project -> "Open module settings" -> Dependencies tab -> check if Export is checked for your library 右键单击您的项目 - >“打开模块设置” - >“依赖关系”选项卡 - >检查是否检查了库的“导出”

I'm using Android Studio. 我正在使用Android Studio。 and in my case, gradle clean and/or Rebuild project didn't work. 在我的情况下, gradle clean和/或Rebuild项目不起作用。 I had to uninstall the current SDK (in my case: 22) that was supposed to be corrupted and then reinstall it. 我不得不卸载当前被破坏然后重新安装的SDK(在我的情况下:22)。 After doing this, the project restarted to compile and run. 执行此操作后,项目重新启动以进行编译和运行。 Hope it can help someone. 希望它可以帮助某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM