问题:我可以执行以下操作,还是会导致问题?
MyAndroidGradleProject
|-- settings.gradle
|-- build.gradle
|-- app
| +-- build.gradle
+-- SomeLibraryAndroidGradleProject
|-- settings.gradle // root project within root project!
|-- build.gradle
|-- app
| +-- build.gradle
+-- library
+-- build.gradle
MyAndroidGradleProject/settings.gradle
看起来像这样:
include ':app'
include ':library'
project(':library').projectDir = new File('./SomeLibraryAndroidGradleProject/library')
据我所知,一切似乎都很好,但我不想在以后遇到问题...... 有人可以确认这符合Gradle的设计吗?
你为什么要这样做?
我的目录结构的原因是我想在SomeLibraryAndroidGradleProject
的git存储库中将MyAndroidGradleProject
作为git子模块。我目前将两个项目并排放在同一个父目录中,如此
AndroidStudioProjects
|-- MyAndroidGradleProject
+-- SomeLibraryAndroidGradleProject
但是那种方式我当然不能把一个作为另一个的子模块。我当然可以在一个公共父文件夹中有一个第三个git存储库,它有两个其他存储库作为子模块,但这看起来既复杂又语义错误。
答案 0 :(得分:1)
根据您的结构,我删除了第二个 settings.gradle
:
MyAndroidGradleProject
|-- settings.gradle
|-- build.gradle
|-- app
| +-- build.gradle
+-- SomeLibraryAndroidGradleProject
|-- app
| +-- build.gradle
+-- library
+-- build.gradle
settings.gradle
rootProject.name = "MyAndroidGradleProject"
include ":app"
include ":SomeLibraryAndroidGradleProject"
include ":SomeLibraryAndroidGradleProject:app"
include ":SomeLibraryAndroidGradleProject:library"
build.gradle
//在此处应用常见插件
应用/的build.gradle 强>
apply plugin: "com.android.application"
<强> SomeLibraryAndroidGradleProject 强>
此处不需要build.gradle
和settings.gradle
<强> SomeLibraryAndroidGradleProject /应用/的build.gradle 强>
apply plugin: "com.android.application"
dependencies {
compile project(":SomeLibraryAndroidGradleProject:library")
}
<强> SomeLibraryAndroidGradleProject /应用/的build.gradle 强>
apply plugin: "com.android.library"
此设置允许您在同一个git仓库中拥有并编译两个不同的应用程序。理想情况下,在编译时,您希望一次只编译1个,因此请务必相应地选择任务。