Android Studio 添加 rxjava 库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21060607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio adding rxjava library
提问by Vojtech B
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
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
我从http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.netflix.rxjava%22%20AND%20a%3A%22rxjava-core%22(sources.jar ) - 但我也试过其他人
Then I created lib folder in the SubProject and then put the .jar to it.
然后我在子项目中创建了 lib 文件夹,然后将 .jar 放入其中。
In Android Studio I rightclicked on the library and selected "Add as Library..." with level: "Project Library" and module: "SubProject".
在 Android Studio 中,我右键单击库并选择“添加为库...”,级别为:“项目库”和模块:“子项目”。
The rxjava uses package name "rx".I have some code implemented that imports this package:
rxjava 使用包名“rx”。我实现了一些导入这个包的代码:
import rx.Observable;
import rx.Observer;
import rx.Subscription;
import rx.subscriptions.Subscriptions;
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
...
I found that it is required to put a line to SubProject/build.grandle:
我发现需要在 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
I tried to moving the .jar around the project structure but so far no luck.
我试图在项目结构周围移动 .jar,但到目前为止没有运气。
How do I properly add a 3rd party library to the project? Is it ok that I created the "libs" folder myself?
如何在项目中正确添加 3rd 方库?我自己创建了“libs”文件夹可以吗?
采纳答案by Reza
you could just try adding:
你可以尝试添加:
compile 'com.netflix.rxjava:rxjava-android:0.16.1'
compile 'com.netflix.rxjava:rxjava-android:0.16.1'
and dont forget to click "Sync Project With Gradle Files" button.
并且不要忘记单击“将项目与 Gradle 文件同步”按钮。
回答by peacepassion
回答by Justlove_DK
first you need to add the code compile 'libs/rxjava-core-0.16.0-sources.jar'
you can choose the library in the libs folder and find the "Synchronize + library name" to rebuild it ,then you can use the library.
hope can help you
首先你需要添加代码compile 'libs/rxjava-core-0.16.0-sources.jar'
你可以在libs文件夹中选择库并找到“同步+库名”来重建它,然后你就可以使用这个库了。希望能帮到你