keldar
keldar

Reputation: 6252

[email protected] and gradle configuration in Android Studio not working

I have updated my Cordova project so it now uses [email protected]. So far it seems good but I cannot work out some things which I need to know in order to create an APK.

The newest version utilises gradle and creates an Android Studio compatible project - great! Also, you can use the new Crosswalk WebView which I decided I need to because I have seen increasing issues on older devices (typically pre-Android KitKat - 4.3 and lower). So Crosswalk seems to have overcome the issues I had and comes with a marginally noticeable increase in speed.

Anyway, a couple of issues/confusion I have been having with regards to [email protected]/gradle/Android Studio:

  1. My armv7 APK created has now inflated from a moderate 8MB to 28MB! The www folder is the same - is there any chance it's duplicating these in the APKs generated? If not, why is it so big?

  2. versionCode - the app version is set in config.xml - mine is set to 4.9.1.2. When cordova generates the versionCode (used in the AndroidManifest.xml) - Cordova has a weird parsing rule which replaces the periods '.' with '0's - but only for the first three values. So 4.9.1.2 becomes 40902. In existing versions of Cordova, you could manually edit AndroidManifest.xml and supply your own value - and Eclipse build would not overwrite this.

I have a feeling either Gradle or Android Studio is overwriting this - I cannot workout which. Please can somebody explain as I need to fix this come go-live otherwise the versionCode will not supersede my current live version of my app!

  1. Gradle options - how do I set these!? There seem to be two places. I can either:

Run the following command (I will explain the extra flags in point (4))

cordova build android --gradle --release --versionCode=49120 --gradleArg=PcdvBuildMultipleApks=false

Or

Create a file named gradle.properties and place the following two properties in there:

cdvBuildMultipleApks=false
cdvVersionCode=49120

Both methods explained: https://cordova.apache.org/docs/en/edge/guide_platforms_android_tools.md.html#Android%20Shell%20Tool%20Guide_building_with_gradle

  1. This point kinda ties in (2) and (3) - but if I can set those two options, I think I can overcome my two issues explained above! Although as a side not, the documentation states by default cdvBuildMultipleApks is set to false, but it isn't - in CordovaLib, the gradle build file sets it to true if it is null - am I missing something obvious here?

  2. Final point and question! If I run cordova build android this builds my project with gradle - good! If I then open Android Studio and my project, whenever I export a signed APK, it also runs through some gradle scrips - are the two builds the same process? Do I need to run cordova build or does Android Studio essentially run it for me?

A long thread but I think just a few teething issues with [email protected] and gradle so if you could clarify, that would be greatly appreciated.

Upvotes: 3

Views: 2589

Answers (2)

codevision
codevision

Reputation: 5560

  1. The Crosswalk contains compiled version of browser, that's why APK size increases by 12MB.
  2. The versionCode calculated by Android Studio, but could be overriden by the Gradle property cdvVersionCode
  3. When running build from the command line you could override cdvVersionCode by using following command

    cordova build android -- --gradleArg=-PcdvVersionCode=49120
    

Most likely you miss - before Pcdv... when specify --gradleArg

Second method with additional file is also viable. choose whatever will work for you.

  1. To set multiple Gradle options, use

     cordova build android -- --gradleArg=-PcdvVersionCode=49120 --gradleArg=-PcdvBuildMultipleApks=true
    
  2. The cordova build android and Android Studio both use Gradle to build Cordova project. They both interchangeable.

Upvotes: 7

GrieveAndrew
GrieveAndrew

Reputation: 196

You can also set the versionCode explicitly by:

<widget android:versionCode="123">

in your config.xml.

To help alleviate the APK size increased caused by Crosswalk, you can opt to use Crosswalk only for pre-L Android versions (or for pre-kitkat if you find that webview good enough). Since L has an updatable webview, it almost certainly use a version of Chromium that is the same or newer than the one Crosswalk bundles. Details in plugin README, but pasted here for convenience as well:

To build Crosswalk-enabled apks, add crosswalk plugin and run:

$ cordova build --release

To build System-webview apk, remove crosswalk plugin and run:

$ cordova build --release -- --android-minSdkVersion=21

Upvotes: 2

Related Questions