Android Studio adds rxjava library

Consider the 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 .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 the lib folder in SubProject, and then put the .jar in it.

In Android Studio, I right-clicked on the library and selected "Add as library ...". with level: "Project library" and module: "Subproject".

Rxjava uses the package name "rx". I have specific code that imports this package:

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

When creating a project, the following error occurs:

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

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

 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 he throws:

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

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

How to add a third-party library to a project? Is it normal that I created the "libs" folder myself?

+6
source share
3 answers

you can simply add:

compile 'com.netflix.rxjava:rxjava-android:0.16.1'

and do not forget to click "Synchronize the project using the Gradle Files button".

+16
source

The final dependency for gradle should be:

 compile 'io.reactivex:rxjava:1.0.10' 

Link this link .

+5
source

first you need to add the compile 'libs/rxjava-core-0.16.0-sources.jar' code compile 'libs/rxjava-core-0.16.0-sources.jar' you can select the library in the libs folder and find "Synchronize + library name" to rebuild it, then you can use the library. hope can help you

0
source

All Articles