Android的工作室加入rxjava库 [英] Android Studio adding rxjava library

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

问题描述

请考虑以下的项目结构:

Consider following project structure:

MainProject
-.idea
-.grandle
-src
-SubProject
--libs //I created this folder manually
---rxjava-core-0.16.0-sources.jar
--src
---main //+ all the sources
--build.grandle
--SubProject.iml
-build.grandle
-//other files

我从网上下载的.jar <一href="http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.netflix.rxjava%22%20AND%20a%3A%22rxjava-core%22" rel="nofollow">http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.netflix.rxjava%22%20AND%20a%3A%22rxjava-core%22 (sources.jar) - 但我也尝试过其他

I downloaded the .jar from http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.netflix.rxjava%22%20AND%20a%3A%22rxjava-core%22 (sources.jar) - but I also tried others

然后,我在子项目中创建lib文件夹,然后把该.jar吧。

Then I created lib folder in the SubProject and then put the .jar to it.

在Android的工作室我上的RightClicked图书馆和选择添加库... 与级别:项目库和模块:子项目

In Android Studio I rightclicked on the library and selected "Add as Library..." with level: "Project Library" and module: "SubProject".

该rxjava使用包名​​RX。我有一些code实施了进口这个包:

The rxjava uses package name "rx".I have some code implemented that imports this package:

import rx.Observable;
import rx.Observer;
import rx.Subscription;
import rx.subscriptions.Subscriptions;

在建项目下面的错误occure:

When building the project following error occure:

Gradle: package rx does not exist
Gradle: package rx.util.functions does not exist
Gradle: cannot find symbol class Action1
...

我发现,它需要把线子项目/ build.grandle:

I found that it is required to put a line to SubProject/build.grandle:

dependencies {
    compile 'libs/rxjava-core-0.16.0-sources.jar' //added line
    compile 'com.android.support:support-v4:19.0.0'
    compile 'com.android.support:appcompat-v7:19.0.0'
}

但随后抛出:

but then it throws:

Gradle: A problem occurred evaluating project ':SubProject'.
> The description libs/rxjava-core-0.16.0-sources.jar is invalid

我试图移动的.jar围绕项目结构,但至今没有运气。

I tried to moving the .jar around the project structure but so far no luck.

我如何正确地添加第三方库的项目?那是正确的,我创建了库文件夹自己?

How do I properly add a 3rd party library to the project? Is it ok that I created the "libs" folder myself?

推荐答案

你可以只尝试添加:

编译com.netflix.rxjava:rxjava-机器人:0.16.1

和不要忘记点击同步工程用摇篮文件按钮。

and dont forget to click "Sync Project With Gradle Files" button.

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

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