I'm sure that this has been asked before, but I'm just not finding the right keywords to ferret out answers, so...
How do I stop Gradle for Android (inside or outside of Android Studio) from building all build types of a library module when I request to build one build type? IOW, if I am building debug
, how do I prevent Gradle for Android from also building release
?
The back-story, for those with alternative ideas:
Suppose that I have two Android Studio projects, A and B. Each has two modules: an Android library module and a demo app that depends upon that library. So, I have a total of four modules:
- AL: project A's library
- AD: project A's demo app
- BL: project B's library
- BD: project B's demo app
So long as A and B are not related, life is good.
But what if I want BL to depend upon AL?
For release
, if I want those libraries to go in a Maven-style artifact repository, I need the release
variant of BL to depend upon the published artifact of AL. That way, my BL POM has the right dependency info.
For debug
, it would be ideal if BL could depend upon the working copy of AL. While setting that up is a bit hacky, I can make it work.
But then if I add stuff to AL, such as a new Java class, and I try using it from BL, I can't build. My debug
build is perfectly fine AFAICT. However, even though I really really really don't want to do a release
build now, Gradle for Android insists upon doing a release
build anyway:
$ gradle assembleDebug
:demo:preBuild UP-TO-DATE
:demo:preDebugBuild UP-TO-DATE
:demo:compileDebugNdk UP-TO-DATE
:demo:checkDebugManifest
:demo:preReleaseBuild UP-TO-DATE
:richedit:compileLint
:richedit:copyReleaseLint UP-TO-DATE
:richedit:mergeReleaseProguardFiles UP-TO-DATE
:richedit:preBuild UP-TO-DATE
:richedit:preReleaseBuild UP-TO-DATE
:richedit:checkReleaseManifest
:richedit:prepareReleaseDependencies
:richedit:compileReleaseAidl UP-TO-DATE
:richedit:compileReleaseRenderscript UP-TO-DATE
:richedit:generateReleaseBuildConfig UP-TO-DATE
:richedit:generateReleaseAssets UP-TO-DATE
:richedit:mergeReleaseAssets UP-TO-DATE
:richedit:generateReleaseResValues UP-TO-DATE
:richedit:generateReleaseResources UP-TO-DATE
:richedit:packageReleaseResources
:richedit:processReleaseManifest UP-TO-DATE
:richedit:processReleaseResources
:richedit:generateReleaseSources
:richedit:compileReleaseJava
(where richedit
is BL and demo
is BD in my nomenclature above)
I am asking to assemble the debug
build, but it still compiles the release
build. And the release
build cannot compile, because I am trying to have BL use new unreleased stuff from AL.
I am reasonably confident, though not 100% certain, that if Gradle for Android would just blithely ignore release
when I am trying to build debug
, that I would be in OK shape.
Of course, there are possible workarounds:
I could abandon the idea that these are separate libraries and consolidate them into one. I may yet do that. But it sure feels like what I'm trying to do should be possible.
I could not try using the AL changes until I publish a
release
AL, in which case BL can depend upon the published artifact for bothdebug
andrelease
. However, that seems like it will cause a lot of patchlevel churn in the A project, as my primary consumer "use case" of this new A functionality is B. Just because I have changes in A that pass instrumentation tests does not mean that they'll be what B needs, and I won't know that until I can build B with the changes in A.A variation on the above workaround may be
SNAPSHOT
releases, where I would somehow enable checking forSNAPSHOT
releases fordebug
but not forrelease
or something. However, the mix of Maven, Gradle, Android, andSNAPSHOT
all seems rather under-documented, and I have no idea if it's something that I should be pursuing. And, as with the preceding bullet, this still would result inrelease
being built unnecessarily; the build would just succeed in my case.
Is there some Gradle for Android setting somewhere that I am missing that says debug
means just debug
?