This currently does not work the way I want, but I want to document it for personal reference.
Scenario:
I have an app that uses a library project being build in parallel. I want to have three different build types: debug, internal, release. I want each of those to have it's own package name, app name, version number, and version code. I want to be able to at least automate a build for internal on a nightly basis and upload to HockeyApp.
Problems:
- First problem I ran into was that buildTypes in gradle do not allow you to specify versionNumber or versionCode. Just suffixes for those properties. So I moved to flavors...
- Unfortunately, I'm using BuildConfig and with flavors, BuildConfig.java is not found by Android Studios. Everything does work this way (I can run gradle commands from the command line just fine), but without my IDE, it's kind of hard to work. Also, a downside to this approach is that it produces too many apks. If I have the three desired build types and have to have three flavors, I end up with nine apks. Not a show stopper, but kind of annoying.
- So I removed the flavors, and tried to manually update the AndroidManifest in the build directory. To do this, I call variant.processManifest.doLast for each application variant (see code) and try to modify the file directly. This would at least allow me to inject the versionName and code. Unfortunately, this procedure does not happen at the correct time and the manifest would lose some other change (i.e.: the adding of a packageNameSuffix would no longer be applied)
- I tried several other [task].doLast or [task].doFirst, but each resulted in an incorrect manifest.
That's where I'm currently at. All of this could have been prevented if I could just set versionName and versionCode in buildTypes, but that's not supported as of now.
The files below are what I currently have and I will update them as I figure things out.