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
Then I created lib folder in the SubProject and then put the .jar to it.
In Android Studio I rightclicked on the library and selected "Add as Library..." with level: "Project Library" and module: "SubProject".
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;
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:
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.
How do I properly add a 3rd party library to the project? Is it ok that I created the "libs" folder myself?
RxJava is a very common tool used for asynchronous calling in Android development and provides a great alternative to typical asynchronous development.
RxJava is a JVM library that uses observable sequences to perform asynchronous and event-based programming. Its primary building blocks are triple O's, which stand for Operator, Observer, and Observables. And we use them to complete asynchronous tasks in our project. It greatly simplifies multithreading in our project.
RxJava is a Java VM implementation of ReactiveX a library for composing asynchronous and event-based programs by using observable sequences. The building blocks of RxJava are Observables and Subscribers. Observable is used for emitting items and Subscriber is used for consuming those items.
To use RxJava in retrofit environment we need to do just two major changes: Add the RxJava in Retrofit Builder. Use Observable type in the interface instead of Call.
you could just try adding:
compile 'com.netflix.rxjava:rxjava-android:0.16.1'
and dont forget to click "Sync Project With Gradle Files" button.
The latest dependency for gradle should be:
compile 'io.reactivex:rxjava:1.0.10'
Ref this link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With