考虑以下项目结构:
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
我从http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.netflix.rxjava%22%20AND%20a%3A%22rxjava-core%22 (sources.jar ) - 但我也尝试过其他人
然后我在 SubProject 中创建了 lib 文件夹,然后将 .jar 放入其中。
在 Android Studio 中,我右键单击库并选择“添加为库...”,级别:“项目库”和模块:“子项目”。
rxjava 使用包名“rx”。我实现了一些导入这个包的代码:
import rx.Observable;
import rx.Observer;
import rx.Subscription;
import rx.subscriptions.Subscriptions;
构建项目时发生以下错误:
Gradle: package rx does not exist
Gradle: package rx.util.functions does not exist
Gradle: cannot find symbol class Action1
...
我发现需要在 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'
}
但随后它抛出:
Gradle: A problem occurred evaluating project ':SubProject'.
> The description libs/rxjava-core-0.16.0-sources.jar is invalid
我试图在项目结构中移动 .jar,但到目前为止还没有运气。
如何正确地将 3rd 方库添加到项目中?我自己创建“libs”文件夹可以吗?