Search code examples
androidactionbarsherlockgradle

Android gradle project compiling project in a different directory tree


I have a project layout like this:

MyProject/
    Project/
        build.gradle
    build.gradle
    settings.gradle
thirdparty/
    ActionBarSherlock/
        actionbarsherlock/
            build.gradle
        build.gradle
        settings.gradle

The ActionBarSherlock directory is a git submodule pointing to the dev branch of ActionBarSherlock which contains gradle build files.

In MyProject/settings.gradle I added:

include '..:thirdparty:ActionBarSherlock:actionbar'

and in MyProject/build.gradle added:

compile '..:thirdparty:ActionBarSherlock:actionbar'

to the dependencies section. When I build MyProject/Project with gradle assemble I get the following error:

> Project with path '..:thirdparty:ActionBarSherlock:actionbar' could not be found in project ':MyProject'

I can build ActionBarSherlock separately, using:

cd thirdparty/ActionBarSherlock/actionbarsherlock
gradle assemble
cp build/libs/actionbarsherlock-4.3.2-SNAPSHOT.aar ../../../MyProject/Project/libs

and then use it in the dependencies section of MyProject/build.gradle as:

compile files('libs/actionbarsherlock-4.3.2-SNAPSHOT.aar')

Now, when I build MyProject/Project I get the following error:

> Duplicate files at the same path inside the APK: AndroidManifest.xml

Solution

  • This google group has an answer from Android SDK developer Xavier Ducrohet. https://groups.google.com/forum/#!topic/adt-dev/bPY_Un8BsBY

    To quote:

    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.