How to get simply app version?

how to get app version ?
install native plugin getting back error in ionic/native

1 Like

You can store the App version in a separate JSON file in your assets folder.

{ "version": "1.0.0" }

Thats it :slight_smile:

1 Like

You need to provide more information about what you have tried and not tried and what version of ionic native you are using.

Also providing the actual error message would help.

Are you talking about setting the version number or reading it out ?

To read it out, mine works using the latest version of ionic native.

I imported like so
import { AppVersion } from ā€˜@ionic-native/app-versionā€™;

In my constructor I injected the dependency
constructor(private appVersion: AppVersion)

Then I got the app version like this

this.appVersion.getVersionNumber().then(version => {
this.versionNumber = version;
});

I also had to add appversion to my providers in my app.module.ts

1 Like

please give me a full exampleā€¦

i gave verion:1.1.1 in config.xml but couldnā€™t get the version in login formā€¦ what to do?

iā€™m also do this. but error in native/core

What version of ionic are you use and what is the exact error message

this.appVersion.getVersionNumber().then(version => {
this.versionNumber = version;
});

iā€™m using this code. but when i run my app getting error ā€¦ it said runtime error
native/core

1 Like

With my method ou have to access the JSON file with an HTTP get request.

http.get('assets/appversioon.json')...

If you want to use the native plugin, you can test it only on your device and not in your browser. This is your mistake.

1 Like
<?xml version='1.0' encoding='utf-8'?>

widget id=ā€œcom.ionicframework.eattendanceā€ version=ā€œ1.1.0ā€ xmlns=ā€œhttp://www.w3.org/ns/widgetsā€ xmlns:cdv=ā€œhttp://cordova.apache.org/ns/1.0ā€>
Employee Attendance
Employee Attendance Application

how to get this version. itā€™s under the folder is www/config.xml

Runtime Error
Cannot find module ā€œ@ionic-native/coreā€

iā€™m using constructor(private appVersion: AppVersion) getting above error

Runtime Error
Cannot find module "@ionic-native/core"
Stack
Error: Cannot find module "@ionic-native/core"
at Object. (http://localhost:8100/build/main.js:114239:7)
at webpack_require (http://localhost:8100/build/main.js:20:30)
at Object. (http://localhost:8100/build/main.js:26686:84)
at webpack_require (http://localhost:8100/build/main.js:20:30)
at Object. (http://localhost:8100/build/main.js:103748:77)
at webpack_require (http://localhost:8100/build/main.js:20:30)
at Object. (http://localhost:8100/build/main.js:92442:73)
at webpack_require (http://localhost:8100/build/main.js:20:30)
at Object. (http://localhost:8100/build/main.js:114227:70)
at webpack_require (http://localhost:8100/build/main.js:20:30)
Ionic Framework: 2.1.0
Ionic Native: ^2.4.1
Ionic App Scripts: 1.1.3
Angular Core: 2.2.1
Angular Compiler CLI: 2.2.1
Node: 6.9.1
OS Platform: Windows 10
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)

You still havenā€™t told us what version of ionic you are using. Type ionic info in and post the results.

This says you are using Ionic Native 2.x.

But this module is part of Ionic Native 3.x.

Please post your package.json.

You will probably want to remove everything that has to do with Ionic Native and then follow these instructions:

https://ionicframework.com/docs/native/ (all of them, also at the bottom!)
https://ionicframework.com/docs/native/app-version/

PS D:\Arul MaNo\Ionic2\EAttendanceApp> ionic info

Your system information:

ordova CLI: 6.5.0
Ionic Framework Version: 2.0.0-rc.1
Ionic CLI Version: 2.1.12
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.36
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.9.1
Xcode version: Not installed

{
  "name": "ionic-hello-world",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "4.0.0",
    "@angular/compiler": "4.0.0",
    "@angular/compiler-cli": "4.0.0",
    "@angular/core": "4.0.0",
    "@angular/forms": "4.0.0",
    "@angular/http": "4.0.0",
    "@angular/platform-browser": "4.0.0",
    "@angular/platform-browser-dynamic": "4.0.0",
    "@ionic-native/background-geolocation": "^3.5.0",
    "@ionic-native/core": "3.4.2",
    "@ionic-native/geolocation": "^3.5.0",
    "@ionic-native/splash-screen": "3.4.2",
    "@ionic-native/sqlite": "^3.5.0",
    "@ionic-native/status-bar": "3.4.2",
    "@ionic/storage": "2.0.1",
    "ionic-angular": "3.0.1",
    "ionicons": "3.0.0",
    "rxjs": "5.1.1",
    "sw-toolbox": "3.4.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@ionic/app-scripts": "1.3.0",
    "typescript": "~2.2.1"
  },
  "cordovaPlugins": [
    "cordova-plugin-whitelist",
    "cordova-plugin-statusbar",
    "cordova-plugin-console",
    "cordova-plugin-device",
    "cordova-plugin-splashscreen",
    "ionic-plugin-keyboard"
  ],
  "cordovaPlatforms": [],
  "description": "EAttendanceApp: An Ionic project"
}

how to update my ionic native 2.x to 2.4.1

According to this package.json there is no need for this any more, this looks good. Now only follow the two links I posted to install the plugin needed to output the app version.

For ionic2/3
Check here

https://learnionic2.com/2017/04/04/getting-app-version-ionic-2-application/

Are you incrementing appversion.json, via a script? Could you please share the script.
and how you include the script into every ā€œionic cordova build ā€¦ā€ process?
Thank you.

For Ionic 4 and 3 Install App version native Plugin

Step by Step Tutorial for Ionic 4 but you can following Ionic 3 as well

this.appVersion.getVersionNumber().then(value => {
  this.AppVersionNumber = value;
}).catch(err => {
  alert(err);
});
1 Like

this method not working on production build.

This should be the accepted answer