考虑以下项目结构:
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
然后我在SubProject中创建了lib文件夹,然后将.jar放到它上面.
在Android Studio中,我右键单击了库并选择了"Add as Library ...",其级别为:"Project Library"和模块:"SubProject".
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,但到目前为止还没有运气.
如何正确地将第三方库添加到项目中?我自己创建了"libs"文件夹是否可以?