28

I am developing an app using Ionic and Capacitor. Builds are generated using Ionic's new AppFlow service, so I don't build them locally.

How do I go about updating the iOS and Android version numbers? I've tried updating the plist and config.xml, but all updates result in a version number of "1.0", regardless of what I do.

Bryant Makes Programs
  • 1,493
  • 2
  • 17
  • 39

4 Answers4

86

So, Capacitor is neat! The android and ios configs are actually committed to source control. To update version number, simply update the following files:

  • Android - android/app/build.gradle (you're looking for the versionName variable)
  • iOS - ios/App/App/Info.plist *(you're looking for the CFBundleShortVersionString key)
Bryant Makes Programs
  • 1,493
  • 2
  • 17
  • 39
  • 3
    Thanks @Bryant! So should the ios / android folders be committed to git? I currently have the folders as part of my .gitignore. If I include those directories, I'm just concerned that I might run into problems - not to mention bloating the repo sizes? Thanks! – ustad Dec 30 '19 at 21:43
  • I recommend "not" to commit the ios & android directories to your code repository. To your point, it will cause a lot of additional fluff. I recommend to zip them up into another location (AWS S3) and download them as-necessary for when you deploy. – Jeffrey Wen May 05 '20 at 06:58
  • 11
    This is not good advice. You SHOULD include it in your repo. Don't be overly concerned about the size of your repo. After all .. that is the point. More importantly, If you later write native code for your app or make any native changes. Those are lost if not committed. – eDriven_Levar Jun 23 '20 at 12:21
  • 10
    Capacitor (compared to Cordova) actually encourages having platform-specific folders (e.g. `android` or `ios`) under Git control. It allows a much better control over each platform files, since those directories are not getting renegenerated on build (with Cordova those get regenerated on `cordova prepare `) – Eric Gopak Aug 27 '20 at 16:55
  • 1
    Worked for me. :) – Naveen Kumar V Sep 14 '20 at 18:24
  • why is the Android version not taken from `AndroidManifest.xml`? – Paranoid Android Apr 26 '21 at 08:59
  • @Mirko it is optional where you put the version.. i can be both ways – Carlos.V May 17 '21 at 14:18
  • 6
    is there a way to set android and ios versions (both version name and code), taking the value from package.json file? – Carlos.V May 17 '21 at 16:08
  • 3
    Committing the `/android` and `/ios` folders to the repo is one thing that bothers me about Capacitor. They are source and artifact at the same time. For some things they replicate information, for others they are the single source of truth. It's a very un-elegant solution :-| – Fred Dec 08 '21 at 17:26
4

In Android Studio 4.2.1 We can set version values in File > Project Structure > Modules > Default Config

enter image description here

rashidnk
  • 4,096
  • 2
  • 22
  • 32
1

So, Capacitor is neat! The android and ios configs are actually committed to source control. To update version number, simply update the following files:

  • Android - android/app/build.gradle (you're looking for the versionName variable)
  • iOS - ios/App/App/Info.plist *(you're looking for the CFBundleShortVersionString key)

Bryant James's answer is correct, but if you want to change these files version number and build number in one single command, there is a npm package called capacitor-set-version.

It's pretty simple to use:-

USAGE
  $ capacitor-set-version <project-root-dir> -v <version> -b <build-no> --json

ARGUMENTS
  DIR  Capacitor project root directory

OPTIONS
  -b, --build=10       App build number (Integer)
  -v, --version=x.x.x  App version
  --json               Print errors and result as JSON
  -h, --help           Show help

Examples:-

# Set version to 1.2.3 and build number to 10 on current folder.
capacitor-set-version -v 1.2.3 -b 10

# Set version of project on folder ./my-app
capacitor-set-version -v 1.2.3 -b 10 ./my-app

# Set android only version and build number
capacitor-set-version set:android -v 1.2.3-rc1 -b 1546 ./my-app

# Set iOS version only
capacitor-set-version set:ios -v 1.2.3 -b 10 ./my-app
Muhammed Rahif
  • 434
  • 1
  • 5
  • 17
0

I have made a custom version of the package standar-version to update the package.json, IOS(./ios/App/App.xcodeproj/project.pbxproj) and Android (./android/app/build.gradle) file after each commit on master, you can check it there: https://github.com/Cap-go/capacitor-standard-version In the doc, you have the example to use in GitHub Action

This tool has been made for the open-source Appflow alternative capacitor-updater

Martin Donadieu
  • 115
  • 1
  • 5