How do you update the iOS & Android app version in Ionic w/ Capacitor?
Asked Answered
N

4

31

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.

Niggerhead answered 5/10, 2019 at 22:7 Comment(2)
Looking for the same thing. It seems like this is not possible as per github.com/ionic-team/capacitor/issues/840Devon
Oh, I actually found a way to do this, one sec ill post the answerNiggerhead
N
97

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)
Niggerhead answered 27/11, 2019 at 14:48 Comment(9)
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!Asta
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.Valeryvalerye
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.Semblance
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 <platform>)Tramway
Worked for me. :)Foreplay
why is the Android version not taken from AndroidManifest.xml?Assuage
@Mirko it is optional where you put the version.. i can be both waysTarantula
is there a way to set android and ios versions (both version name and code), taking the value from package.json file?Tarantula
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 :-|Neighbor
O
5

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
Obbard answered 20/3, 2023 at 5:54 Comment(0)
C
4

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

enter image description here

Collettecolletti answered 29/5, 2021 at 16:3 Comment(0)
S
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

Selfidentity answered 6/6, 2022 at 15:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.