2

I'm working on an update of the database, my new version is using ORMLite, so I have the playstore version on a device and I want to test if the data migration gonna works, so I connect my device and run the app from Android Studio but I get this error:

Installation failed with message INSTALL_FAILED_UPDATE_INCOMPATIBLE. It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing.

WARNING: Uninstalling will remove the application data!

Do you want to uninstall the existing application?

The answers to this question are not applicable because the solution there is to remove the application, then install the new version. This question is about how to avoid uninstalling.

Dale
  • 5,520
  • 4
  • 43
  • 79
Ben
  • 761
  • 1
  • 12
  • 35
  • Not my downvote but database version changes will NOT cause this problem. When you change DB version, your app will install alright. – Sufian Feb 24 '17 at 14:04
  • Duplicate - http://stackoverflow.com/questions/11891848/install-failed-update-incompatible-when-i-try-to-install-compiled-apk-on-device – Sufian Feb 24 '17 at 14:05
  • It could be happening because the APKs are not signed with the same signature (it happens if you have app installed from Play Store and are installing debug APK with same package name). So you should try installing signed APK. – Sufian Feb 24 '17 at 14:06

2 Answers2

2

This has got nothing to do with your database, this is because you're trying to install an .apk file that has a version number that is less than or equal to the version number of an app already installed on your device with the same application id.

Just increase your versionCode in your gradle.build file (or your AndroidManifest.xml if that's where you define it) and the operating system will let you install your new version without clearing the data.

If changing the versionCode doesn't fix it, then it is likely due to a conflict with the signing of the .apk like Sufian mentioned here.

The 'Generate an apk' option in Android Studio will run you through some prompts to assign a keystore to sign the .apk with, which is the manual way.

You can set up your build.gradle file to automatically sign your .apk with a keystore when you run a given flavour as your build. You can read about how to do this here.

Community
  • 1
  • 1
DanielLaneDC
  • 1,731
  • 11
  • 9
  • Same error i changed: versionCode 13 versionName "1.3"and database version – Ben Feb 24 '17 at 14:17
  • @Ben have you tried installing a signed APK? Make sure you use same keystore which was used to sign the APK uploaded to the PlayStore. – Sufian Feb 24 '17 at 14:22
  • 1
    The database version won't matter, this is to do with the .apk, no code is actually getting run yet. Do you know what the versionCode of the Play Store app is? If it's not the versionCode, it will most likely be the signing issue that Sufian is talking about. – DanielLaneDC Feb 24 '17 at 14:23
  • How I see it ? the problem is that before upgrading my AndroidStudio it was working – Ben Feb 24 '17 at 14:24
  • Ohhhh ! I have to generate the apk and not run it from Android Studio – Ben Feb 24 '17 at 14:25
  • If you have your release flavour configured to sign the .apk with your keystore, then you can just swap to the release flavour and run that from Android Studio. You change flavours by using the flavour tab normally found in the bottom left. – DanielLaneDC Feb 24 '17 at 14:27
  • Looks working :) I upgraded versionCode and versionName, and I generated a signed APK using flavours, but I think I can remove flavours because when I'm generating the APK I already have the passwords in the message box. – Ben Feb 24 '17 at 15:20
-1

I faced the same problem. My solution was to decrease the DB version number to make it correspond to the version on the store, run the current version (not the one on the store) then update the DB version number to last version and re-run it. This way apk update is done and the method onUpgrade() of DBHelper is called.

Cedric Franck
  • 526
  • 4
  • 9