Android的工作室:添加的水瓶中库? [英] Android Studio: Add jar as library?

查看:194
本文介绍了Android的工作室:添加的水瓶中库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用全新的Andr​​oid Studio,但我似乎无法得到它的正常工作。

I'm trying to use the new Android Studio but i can't seem to get it working correctly.

我使用的GSON库序列化/反序列化JSON对象。但库不知何故不包含在构建

I'm using the Gson-library to serialize/deserialize JSON-objects. But the library somehow isn't included in the build.

我创建了一个新的项目,只需MainActivity。复制GSON-2.2.3.jar在/ libs文件夹中,并将其添加为一个库(右点击 - >添加为库)。这包括在机器人工作室罐子,因此它可以从源文件中被引用。

I created a new project with just a MainActivity. Copied gson-2.2.3.jar in the /libs folder and added it as a library (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')

在日.gradle文件的依赖关系。之后,它编译正常,但在运行应用程序时,我收到了ClassDefNotFoundException。 有谁知道我在做什么错了?

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?

推荐答案

我一直挣扎着同样的事情,好几个小时,试图让GSON罐子工作不会少。我终于解决了 - 这里是我采取的步骤:

I've been struggling with the same thing for many hours, trying to get the Gson jar to work no less. I finally cracked it – here are the steps I took:

  1. 把GSON罐(对我来说, GSON-2.2.4.jar )进入文件夹
  2. 右键单击它并点击添加为库
  3. 确保编译文件(库/ GSON-2.2.4.jar')是在 build.gradle 文件
  4. 请一个干净的构建(你也许可以做到这一点罚款Android的工作室,但为了确保我导航的终端我的应用程序的根文件夹,并键入 gradlew干净我在Mac OS X上,该命令可能是您的系统上的不同
  1. Put the Gson jar (in my case, gson-2.2.4.jar) into the libs folder
  2. Right click it and hit 'Add as library'
  3. Ensure that compile files('libs/gson-2.2.4.jar') is in your build.gradle file
  4. Do a clean build (you can probably do this fine in Android Studio, but to make sure I navigated in a terminal to the root folder of my app and typed gradlew clean. I'm on Mac OS X, the command might be different on your system

在我做了以上四种,它开始工作的罚款。我认为,加为图书馆的步骤是一个我倒是previously错过了,没有工作,直到我打扫它的。

After I did the above four, it started working fine. I think the 'Add as library' step was the one I'd previously missed, and it didn't work until I cleaned it either.

这篇关于Android的工作室:添加的水瓶中库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆