Android的工作室:添加项目作为库
我想这个rel=\"nofollow\"> 项目作为库添加这就是我试过了,
I want to add this project as library to my project in android studio. this is what I tried,
我有我的项目目录 F:/我的项目/我的应用程序/ src目录
我的图书馆 F:/我的项目/我的图书馆/ src目录
我转到文件&gt导入模块(库);导入模块>选择库
然后我到文件>项目结构>模块>依赖标签>选择我的项目>添加模块依赖应用确定,然后完成
然而,当我使用code从库中我得到的通常的语法错误(类...找不到)
however when I use the code from the library I get the usual syntax error (the class ... could not be found)
也是我注意到这个弹出(见图片)
also I noticed this popup (see image)
我是新来的Android或工作室的IntelliJ,我该如何解决这个问题。
谢谢!
I am new to android studio or intelliJ, how do I fix this. Thanks!
编辑 settings.gradle
文件(目录 F:/我的项目
),它必须包含这样的:
Edit the settings.gradle
file (in directory f:/my project
), it must contains something like this:
include 'my app','my library'
如果这个文件不存在:手动创建它。在 settings.gradle
的gradle包含的模块在一个多模块项目列表中。
If this file don't exists: create it manually. The settings.gradle
contains the list of gradle modules in a multi-module project.
然后,你必须添加依赖关系到你的库应用程序。这样做编辑我的应用程序/的build.gradle
并添加此行:
Then you must add the dependency to your library in app. To do so edit the my app/build.gradle
and add this line :
dependencies {
compile project(':my library')
}
我也注意到,您不使用默认结构为您的项目(即你把code在的src /
而不是钢骨混凝土/主/ JAVA
),所以你必须覆盖在的build.gradle
你的项目的默认文件集的一些值。确保有这样的事情在我的应用程序/的build.gradle
和我的图书馆/的build.gradle
:
I also notice that you don't use default structure for your projects (i.e. you put the code in src/
instead of src/main/java
) so you will have to overwrite some values of the default fileSet in the build.gradle
of your projects. Be sure to have something like this in my app/build.gradle
and my library/build.gradle
:
android {
sourceSets {
main {
java.srcDirs = ['src']
}
}
}