adbkit
adbkit copied to clipboard
client.install() fails on apk downgrade
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.
Any updates on this ? can you merge this change and release ?
:+1: This would be helpful to me.
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?
Can you run your code with DEBUG=* node code.js and paste the output here? I’m not convinced the uninstallation is done properly.
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.
Just run it with the debug thing please I need the output.
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()) ;
}
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
.