ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.79k stars 2.25k forks source link

[BUG]: FDroid: "Error installing package" for multiple versions of AnkiDroid if app data already exists #14216

Open MagTun opened 1 year ago

MagTun commented 1 year ago

Checked for duplicates?

What are the steps to reproduce this bug?

After migrating my phone from Android 10 to Android 13, I had to move the Ankidroid folder from /storage/emulated/0/AnkiDroid to storage/emulated/0/Android/data/com.ichi2.anki/files/AnkiDroid but this caused several problems*. So, I decided to uninstall Anki and reinstalled it from f-droid. But I got this error:

Screenshot_20230810-094653_F-Droid

I was able to install Ankidroid from Github but I had to use the "arm64-V8A" version otherwise I also got an error "App not installed as package appears to be invalid". **

For information, when I was on Android 10, I first installed Ankidroid via the Play Store, then I used several alpha versions of the "armeabi-v7a.apk", and recently the app was automatically updated by Play Store to 2.16. On Android 10 and with Anki 2.16, I was still able to use the /storage/emulated/0/AnkiDroid folder It's only when I migrated to Android 13 that I had to use the app data path.

In brief, I guess the version on F-droid doesn't include all the versions of the apk.

(*) For example:

(**)Also, it's strange that I had to use the "arm64-V8A" version as I always used the "armeabi-v7a" before for the alpha updates (I kept the same smartphone).

Expected behaviour

Being able to install AnkiDroid via F-droid

Actual behaviour

Unable to install the app (cf printscreen above).

Debug info

AnkiDroid Version = 2.16.2

Android Version = 13

ProductFlavor = full

Manufacturer = Xiaomi

Model = Redmi 7A

Hardware = qcom

Webview User Agent = Mozilla/5.0 (Linux; Android 13; Redmi 7A Build/TQ3A.230705.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/115.0.5790.166 Mobile Safari/537.36

ACRA UUID = 4ac4b3ea-fcbf-45cc-8b32-b24e7122a658

New schema = false

Scheduler = std2

Crash Reports Enabled = true

DatabaseV2 Enabled = true

(Optional) Anything else you want to share?

On F-droid there is a warning "This app has features you may not like. Learn more! [...] This app promotes or depends entirely on a non-free network service".

Research

Exponent4806 commented 1 year ago

This issue can be reproduced on Android 12: Motorola e32(s). Exactly the same problem. The .apk from Github works correctly (AnkiDroid-2.16.2-arm64-v8a.apk)

MagTun commented 1 year ago

@ApprobationBW : which version of the apk from github did you install?

david-allison commented 1 year ago

TL;DR: INSTALL_FAILED_VERSION_DOWNGRADE: Downgrade detected: Update version code 21602300 is older than current 321602300

Reproduction Steps:

====

Workarounds (⚠️ causes data loss)

1.

2.

adb shell pm uninstall com.ichi2.anki

Old content ==== I've tried to reproduce: * Uninstall all AnkiDroid apps from my Phone * Reinstall F-Droid and wipe data * Install via F-Droid * After the download, it shows the Android "update" prompt, rather than "install" I get the following in my logcat: ``` 2023-08-14 22:55:19.455 1558-1795 PackageManager system_server W Downgrade detected: Update version code 21602300 is older than current 321602300 2023-08-14 22:55:19.455 1558-1795 PackageInstallerSession system_server D Marking session 1606263976 as failed: INSTALL_FAILED_VERSION_DOWNGRADE: Downgrade detected: Update version code 21602300 is older than current 321602300 ``` Reproduced the error message * Restarted my phone. Same problem FoxyDroid gives: `App not installed as package conflicts with an existing package` in the Android prompt * app is still listed in `pm list packages -u` > `package:null=com.ichi2.anki` ==== I fixed this by installing from the Play Store, uninstalling + wiping data, then installing from F-Droid This is reproducible
david-allison commented 1 year ago

@mikehardy

https://github.com/ankidroid/Anki-Android/blob/9d5a6ae98da1be87da297be2189673b4a6369683/AnkiDroid/build.gradle#L69

https://github.com/ankidroid/Anki-Android/blob/9d5a6ae98da1be87da297be2189673b4a6369683/AnkiDroid/build.gradle#L188-L213

mikehardy commented 1 year ago

Interesting! I just got home from traveling since July 2 (!) And FDroid distribution is my first goal for ankidroid as I get moving again.

I don't see why we can't have the full version of 2.16 use the top version code so that FDroid can install over it as we get 2.16 rolled out there. I'll look through the other related items...

For context we only just hit around 50% adoption via play store of 2.16 and the release has been a real bear to get released, so please have a little patience while we get everything releasing smoothly in all channels like 2.15...

Exponent4806 commented 1 year ago

@ApprobationBW : which version of the apk from github did you install?

AnkiDroid-2.16.2-arm64-v8a.apk (The universal version also works. This is an F-Droid specific issue that can be reproduced)

mikehardy commented 1 year ago

we do ABI splits using versions that are either the number 1, 2, 3 or 4 (depending on which ABI we are building) multiplied by 100000000 and added to the base version code.

So going from an ABI split to a universal build (which is what F-droid uses) will always look like a downgrade.

A quick fix would be to alter the build script in f-droid to add 400000000 to it. This is not great though, as it will just cause problems later when/if f-droid does ABI splits for ankidroid.

I submit that f-droid should do ABI splits so I think the real solution is to pursue the solution hinted at in the related issue here: https://gitlab.com/fdroid/fdroiddata/-/issues/3047

It doesn't look that hard, just adding stanzas to the script, I think?

github-actions[bot] commented 9 months ago

Hello 👋, this issue has been opened for more than 3 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

FubayashiKazue commented 9 months ago

Just ran into this issue with Anki 2.17. Previously installed Anki through Play Store, uninstall and keep data led to the abovementioned error when trying to install from F Droid. Reinstall through Playstore and then uninstall with "keep data" unchecked worked like mentioned in the first post. Thanks!