我有一个这样的项目布局:
MyProject/
Project/
build.gradle
build.gradle
settings.gradle
thirdparty/
ActionBarSherlock/
actionbarsherlock/
build.gradle
build.gradle
settings.gradle
ActionBarSherlock
目录是一个指向 ActionBarSherlock 的 dev
分支的 git 子模块,其中包含 gradle 构建文件。
在 MyProject/settings.gradle
我添加了:
include '..:thirdparty:ActionBarSherlock:actionbar'
并在 MyProject/build.gradle
中添加:
compile '..:thirdparty:ActionBarSherlock:actionbar'
到 dependencies
部分。当我使用 gradle assemble
构建 MyProject/Project
时,出现以下错误:
> Project with path '..:thirdparty:ActionBarSherlock:actionbar' could not be found in project ':MyProject'
我可以单独构建ActionBarSherlock
,使用:
cd thirdparty/ActionBarSherlock/actionbarsherlock
gradle assemble
cp build/libs/actionbarsherlock-4.3.2-SNAPSHOT.aar ../../../MyProject/Project/libs
然后在 MyProject/build.gradle
的 dependencies
部分使用它作为:
compile files('libs/actionbarsherlock-4.3.2-SNAPSHOT.aar')
现在,当我构建 MyProject/Project
时,出现以下错误:
> Duplicate files at the same path inside the APK: AndroidManifest.xml
最佳答案
这个谷歌小组有来自 Android SDK 开发者 Xavier Ducrohet 的回答。 https://groups.google.com/forum/#!topic/adt-dev/bPY_Un8BsBY
引用:
To depend on a gradle project that's outside of your main project's root folder you can try to do the following:
include 'abs'
project(':abs').projectDir = new File('/some/path/relative/or/absolute')
Note that your app should do a dependency using project(':abs'), since the gradle path is :abs no matter what the on-disk path is.
关于Android gradle项目在不同的目录树中编译项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16941934/