我需要在多个项目(其中一个是 ProjectOne)中使用外部项目 (ResuableProject) 作为模块。到目前为止我在这里所做的是:
在ProjectOne的settings.gradle中添加了以下内容
include ':ProjectOne', ':ResuableProject'
project(':ResuableProject').projectDir = new File(settingsDir, '../ResuableProject/module')
在 build.gradle 中添加了以下内容
dependencies {
compile project(':ResuableProject')
}
在 gradle sync 没有任何错误之后,在 Project Explorer 中包含了该模块,但是当我使用 ResuableProject
中的任何类时,它给我一个错误,直到我点击类名和它为我提供了添加对 ResuableProject 的依赖
的选项。当我选择该选项时,该类是可访问的,并且似乎一切正常。
但是当我构建项目并尝试运行它时,它给了我这个:
Error:Execution failed for task ':ProjectOne:compileDevDebugJava'.
> Compilation failed; see the compiler error output for details.
Error:(10, 30) error: package <packagename of ResuableProject> does not exist
我是不是遗漏了什么,或者我是否必须在 ProjectOne 中包含 ResuableProject 的源目录,如果是的话,怎么做?
此外,是否有更好的方法在多个应用程序中使用一个公共(public)项目? (不是 jar 或 maven,因为我需要在每个项目中包含源代码,并且公共(public)项目将托管在单独的 git 存储库中)
以前我在 Eclipse(一个常见的库项目)中使用这种方法并将其包含在多个应用程序中。
更新:添加文件系统结构
workspace
----ResuableProject (Android Common stuff)
--------.git
--------module
----ProjectOne (Android App One)
--------.git
--------ProjectOne (module)
------------build.gradle
--------settings.gradle
----ProjectOne (Android App Two)
--------.git
--------ProjectOne (module)
最佳答案
事实证明,您可以添加 ResuableProject
但如果 build.gradle 具有值 apply plugin: 'android'
则不能使用其源,即项目类型为 application .
我将其更改为 apply plugin: 'android-library'
即它必须是一个库,现在一切正常。
关于安卓工作室 : Setup external project as module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22679677/