[英]Android Studio: add project as library
I want to add this project as library to my project in android studio. 我想将此项目作为库添加到android studio中的项目中。 this is what I tried,
这就是我尝试过的
I have my project directory as f:/my project/my app/src
and my library in f:/my project/my library/src
我的项目目录为
f:/my project/my app/src
,我的库位于f:/my project/my library/src
I import the module (the library) by going to file > import module > selecting the library
then I got to file > project structure > modules > dependencies tab > select my project > add module dependency apply ok and then done
我通过转到
file > import module > selecting the library
来导入模块(库),然后进入file > project structure > modules > dependencies tab > select my project > add module dependency apply ok and then done
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) 我也注意到了这个弹出窗口(见图)
I am new to android studio or intelliJ, how do I fix this. 我是android studio或intelliJ的新手,如何解决此问题。 Thanks!
谢谢!
Edit the settings.gradle
file (in directory f:/my project
), it must contains something like this: 编辑
settings.gradle
文件(在目录f:/my project
),它必须包含以下内容:
include 'my app','my library'
If this file don't exists: create it manually. 如果此文件不存在:请手动创建。 The
settings.gradle
contains the list of gradle modules in a multi-module project. settings.gradle
包含多模块项目中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 : 为此,请编辑
my app/build.gradle
并添加以下行:
dependencies {
compile project(':my library')
}
I also notice that you don't use default structure for your projects (ie 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. 我还注意到您没有为项目使用默认结构(即,将代码放在
src/
而不是src/main/java
),因此您将不得不覆盖build.gradle
中默认文件集的某些值项目。 Be sure to have something like this in my app/build.gradle
and my library/build.gradle
: 确保在
my app/build.gradle
和my library/build.gradle
:
android {
sourceSets {
main {
java.srcDirs = ['src']
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.