Home » Android » java – Android Studio adding rxjava library

java – Android Studio adding rxjava library

Posted by: admin June 15, 2020 Leave a comment


Consider following project structure:

--libs //I created this folder manually
---main //+ all the sources
-//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?

How to&Answers:

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.


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