Ionic native code push auto rollback problem


#1

app.component.ts file

import { Component } from '@angular/core';
import { Platform,ToastController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HomePage } from '../pages/home/home';
import { CodePush,InstallMode,SyncStatus } from '@ionic-native/code-push';
@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage:any = HomePage;
  
  constructor(
	platform: Platform, 
	statusBar: StatusBar, 
	splashScreen: SplashScreen, private codePush: CodePush,public toastCtrl: ToastController,
	) {
    platform.ready().then(() => {
		this.checkCodePush();
      statusBar.styleDefault();
      splashScreen.hide();
    });
  }
  checkCodePush() {
		 this.codePush.sync({
      updateDialog: {
       appendReleaseDescription: true,
       descriptionPrefix: "\n\nChange log:\n"   
      },
      installMode: InstallMode.ON_NEXT_RESTART
   }).subscribe(//,downloadProgress
     (data) => {
      
        if(data == SyncStatus.CHECKING_FOR_UPDATE)
			
			alert("Check for update");
		
		if(data == SyncStatus.DOWNLOADING_PACKAGE)
			
			alert('downloading_package ');
		
		if(data == SyncStatus.IN_PROGRESS)
			
			alert('in_progress ');
		
		if(data == SyncStatus.INSTALLING_UPDATE)
			
			alert('installing_update ');
		
		if(data == SyncStatus.UPDATE_INSTALLED)
			
			alert('update_installed ');
		
		if(data == SyncStatus.ERROR)
			
			alert('error');
		
     },
     (err) => {
      console.log('CODE PUSH ERROR: ' + err);
	  let toast = this.toastCtrl.create({
				message: 'CODE PUSH ERROR: ' + err,
				duration: 10000,
				position: 'bottom'
			});
			toast.onDidDismiss(() => {});
			toast.present();
     }
   );
    
	
  }
	
  
  
}

Please see attach gif image.

The problem is that after the app is updated i close the app, and it rollback to the previus version, but there are no error with the update. Someone can help me with this?

How do i solve this problem?


#2

Take a look at notifyApplicationReady()

You need to call this once the update is complete - which notifies the plugin that the update was successful.

Try:

platform.ready().then(() => {
this.codePush.notifyApplicationReady();
this.checkCodePush();
statusBar.styleDefault();

#3
platform.ready().then(() => {
    this.codePush.notifyApplicationReady();
    this.checkCodePush();
    statusBar.styleDefault();
    splashScreen.hide();
});

I have tried this but it is not working for me.


#4

Please help me. what should i do?


#5

Sorry @ismailcse11,

This is obviously difficult to help because of the work required to reproduce.

I don’t understand why your code has sync parameters as: installMode: InstallMode.ON_NEXT_RESTART, yet it seems to restart immediately?

Can you try with installMode: InstallMode.IMMEDIATE and have something else (ie. a button) call notifyApplicationReady() manually - just so we know it’s being called once the app has been updated.


#6

At first i tried installMode: InstallMode.IMMEDIATE but not working. then i tried installMode: InstallMode.ON_NEXT_RESTART.
I am using this below process. is my process is right?

config.xml

<platform name="android">
        <preference name="CodePushDeploymentKey" value="5fUEhS8tfRPMLNgihTvwoORiXELS3485857a-6fe9-4501-b521-228920abce45" />
    </platform>

app.component.ts file

import { Component } from '@angular/core';
import { Platform,ToastController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HomePage } from '../pages/home/home';
import { CodePush,InstallMode,SyncStatus } from '@ionic-native/code-push';
@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage:any = HomePage;
  
  constructor(
	platform: Platform, 
	statusBar: StatusBar, 
	splashScreen: SplashScreen, private codePush: CodePush,public toastCtrl: ToastController,
	) {
    platform.ready().then(() => {
this.codePush.notifyApplicationReady().then((data) => {
				//it's say **OK** in console mode.
			});		
this.checkCodePush();
      statusBar.styleDefault();
      splashScreen.hide();
    });
  }
  checkCodePush() {
		 this.codePush.sync({
      updateDialog: {
       appendReleaseDescription: true,
       descriptionPrefix: "\n\nChange log:\n"   
      },
      installMode: InstallMode.IMMEDIATE
   }).subscribe(//,downloadProgress
     (data) => {
      
        if(data == SyncStatus.CHECKING_FOR_UPDATE)
			
			alert("Check for update");
		
		if(data == SyncStatus.DOWNLOADING_PACKAGE)
			
			alert('downloading_package ');
		
		if(data == SyncStatus.IN_PROGRESS)
			
			alert('in_progress ');
		
		if(data == SyncStatus.INSTALLING_UPDATE)
			
			alert('installing_update ');
		
		if(data == SyncStatus.UPDATE_INSTALLED)
			
			alert('update_installed ');
		
		if(data == SyncStatus.ERROR)
			
			alert('error');
		
     },
     (err) => {
      console.log('CODE PUSH ERROR: ' + err);
	  let toast = this.toastCtrl.create({
				message: 'CODE PUSH ERROR: ' + err,
				duration: 10000,
				position: 'bottom'
			});
			toast.onDidDismiss(() => {});
			toast.present();
     }
   );
    
	
  }
}

i also used in home.ts file through button.

notifyAppReady(){
	this.codePush.notifyApplicationReady();
  }

code push
I am using below task

  1. ionic cordova build android --prod --release
  2. jarsigner -verbose -sigalg SHA1withRSA -digestalg.........
  3. zipalign -v.............
  4. then install apk file in my mobile
    after some mdifying
  5. ionic cordova build android --prod --release
  6. code-push release-cordova school1-android android --targetBinaryVersion "0.0.1" -m -d "Production" --description "Modified app"

#7

anyone can share your code for ionic native code push plugin.


#8

Please see my update code. it is too frustrating. I am not understanding that my code is right or wrong. my process is right or wrong.


#9

Hi,

Take a look at my logs and see if you get similar:

11:47:29.597 codePushUtil.js:36 [CodePush] Checking for update.
11:47:30.077 codePushUtil.js:36 [CodePush] Reported status: {"status":0,"appVersion":"0.0.1","deploymentKey":"xxx"}
11:47:30.250 codePushUtil.js:36 [CodePush] An update is available. {"appVersion":"0.0.1","deploymentKey":"xxx","description":"App Update","downloadUrl":"https://codepushupdates.azureedge.net/storagev2/xyz","isMandatory":false,"label":"v101","packageHash":"abc","packageSize":4765563,"failedInstall":false}
11:47:30.268 12.js:108 Update Package Info RemotePackage {appVersion: "0.0.1", deploymentKey: "xxx", description: "App Update", downloadUrl: "https://codepushupdates.azureedge.net/storagev2/xyz", isMandatory: false, …}
11:50:01.735 VM232 12.js:128 CODE PUSH UPDATE: 5
11:50:01.959 VM31 codePushUtil.js:36 [CodePush] Checking for update.
11:50:03.297 VM31 codePushUtil.js:36 [CodePush] An update is available. {"appVersion":"0.0.1","deploymentKey":"xxx","description":"App Update","downloadUrl":"https://codepushupdates.azureedge.net/storagev2/xyz","isMandatory":false,"label":"v101","packageHash":"abc","packageSize":4765563,"failedInstall":false}
11:50:03.310 VM31 codePushUtil.js:36 [CodePush] Awaiting user action.
11:50:03.317 VM232 12.js:128 CODE PUSH UPDATE: 6
11:50:08.158 VM232 12.js:128 CODE PUSH UPDATE: 7
11:50:08.172 VM31 codePushUtil.js:36 [CodePush] Downloading update
11:50:17.965 VM31 codePushUtil.js:36 [CodePush] Package download success: {"deploymentKey":"xxx","description":"App Update","label":"v101","appVersion":"0.0.1","isMandatory":false,"packageHash":"abc","isFirstRun":false,"failedInstall":false,"localPath":"cdvfile://localhost/files/codepush/download/update.zip"}
11:50:17.968 VM232 12.js:128 CODE PUSH UPDATE: 8
11:50:17.971 VM31 codePushUtil.js:36 [CodePush] Installing update
11:50:19.254 VM31 codePushUtil.js:36 [CodePush] Applying full update
11:50:19.386 VM31 codePushUtil.js:36 [CodePush] Install succeeded.
11:50:19.390 VM232 12.js:128 CODE PUSH UPDATE: 1
11:50:19.648 Navigated to file:///data/user/0/com.mydomain.myapp/files/codepush/deploy/versions/abc/www/index.html
11:55:53.418 [CodePush] Reported status: {"status":1,"label":"v101","appVersion":"0.0.1","deploymentKey":"xxx","previousLabelOrAppVersion":"0.0.1","previousDeploymentKey":"xxx"}

My code isn’t in the main component, but a separate page. It’s also not production ready so it’s not automatic:

  constructor(private codePush: CodePush, ...) {

      this.codePush.notifyApplicationReady();

      this.codePush.checkForUpdate()
        .then(packageInfo => {
          if (packageInfo) {
            this.updatePackage = packageInfo;
            console.log('Update Package Info', packageInfo);
          }
        });
    }

  sync() {
      this.codePush.sync({
        updateDialog: {
          appendReleaseDescription: true,
          descriptionPrefix: "\n\nChange log:\n"
        },
        installMode: InstallMode.IMMEDIATE
      }).subscribe(
        (data) => {
          console.log('CODE PUSH UPDATE: ' + data);
        },
        (err) => {
          console.log('CODE PUSH ERROR: ' + err);
        }
      );
  }


I also deploy using appcenter:

appcenter codepush release-cordova -a mydomain/myapp-Android -d Staging --description "v${BUILD_ID}"

#10

I am also using home.ts file.
In my terminal show some error like below:

console.log: [CodePush] Reported status:
[app-scripts]             {"status":0,"appVersion":"0.0.1","deploymentKey":"xxxxx"}
[app-scripts] [13:22:35]  console.log: [CodePush] An update is available.
[app-scripts]             {"appVersion":"0.0.1","deploymentKey":"xxxxx","description":"Modified
[app-scripts]             app","downloadUrl":"https://codepushupdates.azureedge.net/storagev2/ZThrCJXwsQu9Hv8evd6D9C9DSjEb3485857a-6fe9-4501-b521-228920abce45","isMandatory":true,"label":"v29","packageHash":"0eb7b1733d1cea385b74b0141927a5189a85f56d8911fac45e8ec546cce2027b","packageSize":499859,"failedInstall":false}
[app-scripts] [13:22:35]  console.log: [CodePush] Awaiting user action.
[app-scripts] [13:22:35]  console.log: CODE PUSH UPDATE: 6
[app-scripts] [13:22:35]  console.log: [CodePush] An update is available.
[app-scripts]             {"appVersion":"0.0.1","deploymentKey":"xxxxx","description":"Modified
app","downloadUrl":"https://codepushupdates.azureedge.net/storagev2/ZThrCJXwsQu9Hv8evd6D9C9DSjEb3485857a-6fe9-4501-b521-228920abce45","isMandatory":true,"label":"v29","packageHash":"0eb7b1733d1cea385b74b0141927a5189a85f56d8911fac45e8ec546cce2027b","packageSize":499859,"failedInstall":false}
[app-scripts] [13:22:40]  console.log: [CodePush] Downloading update
[app-scripts] [13:22:43]  console.log: [CodePush] Package download success:
[app-scripts]             {"deploymentKey":"xxxxx","description":"Modified       app","label":"v29","appVersion":"0.0.1","isMandatory":true,"packageHash":"0eb7b1733d1cea385b74b0141927a5189a85f56d8911fac45e8ec546cce2027b","isFirstRun":false,"failedInstall":false,"localPath":"cdvfile://localhost/files/codepush/download/update.zip"}
[app-scripts] [13:22:43]  console.log: CODE PUSH UPDATE: 8
[app-scripts] [13:22:43]  console.log: [CodePush] Installing update
[app-scripts] [13:22:45]  console.log: [CodePush] Applying full update
[app-scripts] [13:22:45]  console.error: [CodePush] Preinstall failure. Could not get the package start page
[app-scripts] [13:22:45]  console.log: CODE PUSH ERROR: Error: An error has occured while installing the package. Could not get the
[app-scripts]             package start page
[app-scripts] [13:22:45]  console.error: [CodePush] An error has occured while installing the package. Could not get the package start
[app-scripts]             page. StackTrace: Error: An error has occured while installing the package. Could not get the package start
[app-scripts]             page at preInstallFailure
[app-scripts]             (http://192.168.0.103:8100/plugins/cordova-plugin-code-push/bin/www/localPackage.js:246:41) at
[app-scripts]             Object.callbackFromNative (http://192.168.0.103:8100/cordova.js:293:52) at processMessage
[app-scripts]             (http://192.168.0.103:8100/cordova.js:1115:17) at processMessages
[app-scripts]             (http://192.168.0.103:8100/cordova.js:1138:9) at t.invoke
[app-scripts]             (http://192.168.0.103:8100/build/polyfills.js:3:14976) at r.run
[app-scripts]             (http://192.168.0.103:8100/build/polyfills.js:3:10143) at
[app-scripts]             http://192.168.0.103:8100/build/polyfills.js:3:20242 at t.invokeTask
[app-scripts]             (http://192.168.0.103:8100/build/polyfills.js:3:15660) at r.runTask
[app-scripts]             (http://192.168.0.103:8100/build/polyfills.js:3:10834) at o
[app-scripts]             (http://192.168.0.103:8100/build/polyfills.js:3:7894)
[app-scripts] [13:22:45]  console.error: [CodePush] An error occurred during sync. An error has occured while installing the package.
[app-scripts]             Could not get the package start page. StackTrace: Error: An error has occured while installing the package.
[app-scripts]             Could not get the package start page at preInstallFailure
[app-scripts]             (http://192.168.0.103:8100/plugins/cordova-plugin-code-push/bin/www/localPackage.js:246:41) at
[app-scripts]             Object.callbackFromNative (http://192.168.0.103:8100/cordova.js:293:52) at processMessage
[app-scripts]             (http://192.168.0.103:8100/cordova.js:1115:17) at processMessages
[app-scripts]             (http://192.168.0.103:8100/cordova.js:1138:9) at t.invoke
[app-scripts]             (http://192.168.0.103:8100/build/polyfills.js:3:14976) at r.run
[app-scripts]             (http://192.168.0.103:8100/build/polyfills.js:3:10143) at
[app-scripts]             http://192.168.0.103:8100/build/polyfills.js:3:20242 at t.invokeTask
[app-scripts]             (http://192.168.0.103:8100/build/polyfills.js:3:15660) at r.runTask
[app-scripts]             (http://192.168.0.103:8100/build/polyfills.js:3:10834) at o
[app-scripts]             (http://192.168.0.103:8100/build/polyfills.js:3:7894)

where i’ll check to solve this problem.


#11

Problem solved by this post https://github.com/Microsoft/cordova-plugin-code-push/issues/459