Platforms affected
Motivation and Context
This PR adds support to build android bundle (aab) files.
Fixes: #729
Description
~Adds an --bundle
flag to the cordova build
command. If present, cordova will do the necessary steps to run the gradlew bundleDebug
command (or gradlew bundleRelease
if --release
flag is present)~
Accepts packageType
property from build.json
, or optionally the --packageType=apk|bundle
command line argument. The packageType
property was chosen to keep consistency with the iOS platform.
This PR does not change the current build commands. Building APKs is still necessary for deploying apps to test devices, or of course to upload to the Google Play store using the traditional way. Bundle files are exclusively for deploying to Google Play Store.
You can however use the google provided bundletool
program to build APKs from a bundle file so this PR still provides the ability to build bundles in both debug and release variants.
If build.json
is present in the cordova project, just like building APKs, bundles will automatically be signed using the key and password as defined in build.json
.
This PR does alter a previous constraint where if a signing property is present, but is missing the required properties for signing a warning would be displayed. This was altered to only show the warning if a property for signing is present is missing the required properties for signing. In other words, if packageType
is the only property defined in the build.json
file, then a warning about missing required properties for signing won't be emitted.
The cordova run android
command has been modified to produce an error if packageType
is set to bundle
. This is because you cannot execute/deploy a bundle directly to the phone. I believe it is possible to replace all usages of the adb
tool and instead use Google's bundletool
, which provides tools to deploy bundle files to devices and thus support the cordova run
command using bundles, but that would be another PR for another day.
Testing
I have done the following:
- Added unit tests for using the
--packageType
flag
- Ran
npm test
and ensure all tests passed (Running Node 10.x & cordova@9)
- I installed
cordova-android
platform to a test app via cordova platform add https://github.com/breautek/cordova-android.git#app-bundle
and manually ran build commands and all combinations of --debug
, --release
, and --bundle
- I have created a test app on Google Play store to ensure that google will accept a signed aab file created by
cordova build android --bundle --release
.
- I have tested app-bundle branch against one of my work projects which involves a more complicated project structure and includes the use of native libraries (crosswalk) and observed successful builds.
Checklist
- [x] I've run the tests to see all new and existing tests pass
- [x] I added automated test coverage as appropriate for this change
- [x] Commit is prefixed with
(platform)
if this change only applies to one platform (e.g. (android)
)
- [x] If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
- [x] I've updated the documentation if necessary
TODO
- [x] Additionally fallback to build.json
packageType
to decide whether to build an APK or bundle. Overridable by --packageType (Removing the --bundle flag)
- [x] Update build.json documentation
- [x] Fix the added unit test so that they are consistent (one uses
withContext
, the other doesn't)
- [x] Revert devDependencies
nyc
and jasmine
Crosswalk Users
See https://github.com/apache/cordova-android/pull/764#issuecomment-534101278
enhancement