8

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?

Vojtech B
  • 2,837
  • 7
  • 31
  • 59
  • Yes you have to create `libs` folder yourself. Have a look at [THIS](http://stackoverflow.com/a/10046725/1289716) answer. – MAC Jan 11 '14 at 09:34
  • @Mac: thank you. But I am probably missing something. I did create the libs folder i did copy the .jar file there but it does NOT WORK. Maybe the libs folder is in wrong place? – Vojtech B Jan 11 '14 at 09:46
  • possible duplicate of [importing jar libraries into android-studio](http://stackoverflow.com/questions/18735923/importing-jar-libraries-into-android-studio) – Scott Barta Jan 11 '14 at 16:18
  • Ok, first observation is that when compilig files "compile files 'libs/rxjava-core-0.16.0-sources.jar' " is the correct syntax. Didn`t fix the issue though – Vojtech B Jan 12 '14 at 08:00
  • i found this import for rx java on a pluralsight course compile "com.netflix.rxjava:rxjava-core:0.16.1" what is the difference?? – filthy_wizard Jan 16 '16 at 12:36

3 Answers3

18

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.

Reza
  • 1,164
  • 11
  • 9
8

The latest dependency for gradle should be:

compile 'io.reactivex:rxjava:1.0.10'

Ref this link.

peacepassion
  • 1,918
  • 2
  • 15
  • 19
  • If you are using rxandroid then https://search.maven.org/artifact/io.reactivex/rxandroid/ – Hanry Aug 22 '19 at 06:23
0

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