adbkit icon indicating copy to clipboard operation
adbkit copied to clipboard

client.install() fails on apk downgrade

Open lalith-b opened this issue 10 years ago • 8 comments

When I install apk which version is lesser or older than the one currently then the APK will not be installed you need to modify command to take adb install -d -r <apk> to make it work.

I created a PR for this minor change.

lalith-b avatar Dec 01 '14 22:12 lalith-b

Any updates on this ? can you merge this change and release ?

lalith-b avatar Dec 04 '14 18:12 lalith-b

:+1: This would be helpful to me.

btholt avatar Sep 24 '15 06:09 btholt

It's still an issue, furthermore I tried to solve it with an uninstall/install pair but I can't. I tried with client.shell too. My code without shell:

    this.client.install(device.id, `com.alibaba.aliexpresshd-6.1.0.apk`)
      .then(() => {
        console.log('ALIBABA 1.0 installed', );
        this.client.uninstall(device.id, this._getPackageName(
          path.normalize(`com.alibaba.aliexpresshd-6.1.0.apk`))).then(()=>{
        })
          .then(()=> {
            this.client.shell(device.id, `pm list packages`)
              .then(adb.util.readAll)
              .then((output) => {
                console.log(output.toString('utf8'));
              }).catch((error) => {
                console.log('ERROR DURING UNINSTALL', error);
              });
            console.log('ALIBABA UNINSTALLL COMPLETED');
            this.client.install(device.id, `com.alibaba.aliexpresshd-6.0.2.apk`)
              .then(() => {
                console.log('INSTALLL COMPLETED');
              })
              .catch(function(err) {
                console.error('Something went wrong:', err.stack);
              });
          });
      })
      .catch(function(err) {
        console.error('Something went wrong:', err.stack);
      });

After uninstall the package is still available on the device.

My output:

ALIBABA 1.0 installed

_getPackageName: apk is here C:<mypath>\com.alibaba.aliexpresshd-6.1.0.apk packageName is com.alibaba.aliexpresshd

ALIBABA UNINSTALLL COMPLETED

............ package:com.android.providers.calendar package:com.alibaba.aliexpresshd ......

Something went wrong: Error: /data/local/tmp/com.alibaba.aliexpresshd-6.0.2.apk could not be installed [INSTALL_FAILED_VERSION_DOWNGRADE]

Where did i make a mistake?

iabukai avatar Nov 17 '17 15:11 iabukai

Can you run your code with DEBUG=* node code.js and paste the output here? I’m not convinced the uninstallation is done properly.

sorccu avatar Nov 19 '17 09:11 sorccu

Yes, I forgot to mention that the code above is make a list about the packages after the uninstall, and the package ''package:com.alibaba.aliexpresshd" is still there. That is why I got INSTALL_FAILED_VERSION_DOWNGRADE "excepltion".

``` this.client.shell(device.id, pm list packages) .then(adb.util.readAll) .then((output) => { console.log(output.toString('utf8')); }).catch((error) => { console.log('ERROR DURING UNINSTALL', error); // here the error message is incorrect });


So you are right the uninstall is not completed, but the promise is resolved. 

iabukai avatar Nov 19 '17 16:11 iabukai

Just run it with the debug thing please I need the output.

sorccu avatar Nov 19 '17 17:11 sorccu

Before I did the debug I checked my code again and I realized the apk name was undefined because the a promise wasn't resolved with the package name when I called the uninstall. Downgrade is possible with install/uninstall workaround.

Sorry for the interrupt.

Downgrade example for the last device was found in the list devices :

var Promise = require('bluebird')
var adb = require('adbkit')
var apkReader = require('adbkit-apkreader')
var client = adb.createClient()
var apk = 'Sandbox.apk'
var device = {}
var path = require('path')

client.listDevices()
  .then((devices) => {
    return Promise.map(devices, (eszkoz) => {
      device = eszkoz
    })
  })
  .then(function() {
    client.install(device.id, `com.alibaba.aliexpresshd-6.1.0.apk`)
      .then(() => {
        console.log('ALIBABA 1.0 installed', );
		_getPackageName('com.alibaba.aliexpresshd-6.1.0.apk').then((manifest) => {
        client.uninstall(device.id, manifest.package)
          .then(()=> {
            console.log('ALIBABA UNINSTALLL COMPLETED');
            client.install(device.id, `com.alibaba.aliexpresshd-6.0.2.apk`)
              .then(() => {
                console.log('ALIBABA 6.0.2 INSTALLL COMPLETED');
              })
              .catch(function(err) {
                console.error('Something went wrong:', err.stack);
              });
          });
		})
	  })
      .catch(function(err) {
        console.error('Something went wrong:', err.stack);
      });
  })
  .catch(function(err) {
    console.error('Something went wrong:', err.stack)
  })
   function _getPackageName(apkPath) { 
    return apkReader.open(apkPath) 
      .then((reader) => reader.readManifest()) ;
  } 

iabukai avatar Nov 20 '17 08:11 iabukai

Yeah, that's pretty much what I thought. The debug output would have confirmed that, because it would have shown you something like pm uninstall undefined.

sorccu avatar Nov 20 '17 08:11 sorccu