diff --git a/lib/uiautomator2.js b/lib/uiautomator2.js index d839a17c9..88ba2adcb 100644 --- a/lib/uiautomator2.js +++ b/lib/uiautomator2.js @@ -116,8 +116,9 @@ class UiAutomator2Server { ); this.log.debug(`Server packages status: ${JSON.stringify(packagesInfo)}`); - // Enforce server packages reinstall if any of the packages is not installed, while the other is - const shouldUninstallServerPackages = (packagesInfo.some(({installState}) => installState === this.adb.APP_INSTALL_STATE.NOT_INSTALLED) + // Enforce server packages reinstall if any of the packages is not installed, + // or newer one than uia2 driver is going to use. + const shouldUninstallServerPackages = (packagesInfo.some(({installState}) => installState === this.adb.APP_INSTALL_STATE.NEWER_VERSION_INSTALLED) && !packagesInfo.every(({installState}) => installState === this.adb.APP_INSTALL_STATE.NOT_INSTALLED)); // Install must always follow uninstall. Also, perform the install if // any of server packages is not installed or is outdated