Gradle: interchangeably use AAR or project dependency <p>I have an AAR library that I want to distribute to partners along with a sample project that uses it. I want to also use the same sample project for manual testing while developing the AAR library. Thus, I would like to be able to use the library <em>project</em> as a dependency when developing, and the <em>AAR file</em> as a dependency when distributing.</p> <p>I tried to define two flavors in the sample application:</p> <pre><code> productFlavors { aar {} project {} } </code></pre> <p>...and then define dependencies like this:</p> <pre><code> dependencies { //other dependencies projectCompile project(':myLibrary') aarCompile 'com.example.mylibrary:myLibrary-release@aar' } </code></pre> <p>The <code>aar</code> flavor builds if I comment out the dependency for the <code>project</code> flavor, but if I leave both uncommented, Gradle sync fails if the myLibrary directory is not present - despite the fact that the <code>project</code> build flavor is not part of the current build variant.</p> <p>What is the correct way to do this? Or do I have to choose between creating a whole separate project for distribution or always referencing the AAR even when debugging/testing?</p>