Anki-Android icon indicating copy to clipboard operation
Anki-Android copied to clipboard

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

Open MagTun opened this issue 2 years ago • 9 comments

Checked for duplicates?

  • [X] This issue is not a duplicate

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:

  • a js function I used in a deck to read all the sound files on the card in a single click didn't work anymore even after updating the paths - it worked again once I reinstalled Anki from the Github apk - I guess, the js was allowed to access the files.
  • I couldn't édit in another app (Acode) the .js files from storage/emulated/0/Android/data/com.ichi2.anki/files/AnkiDroid

(**)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

  • [X] I am reporting a bug specific to AnkiDroid (Android app)
  • [X] I have checked the manual and the FAQ and could not find a solution to my issue
  • [ ] (Optional) I have confirmed the issue is not resolved in the latest alpha release (instructions)

MagTun avatar Aug 10 '23 14:08 MagTun

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)

Exponent4806 avatar Aug 14 '23 07:08 Exponent4806

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

MagTun avatar Aug 14 '23 21:08 MagTun

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

Reproduction Steps:

  • Install from Play Store
  • Uninstall + Keep Data
  • Install from F-Droid

====

Workarounds (⚠️ causes data loss)

1.

  • Install (again) from Play Store
  • Uninstall + Wipe Data
  • Install from F-Droid

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 avatar Aug 14 '23 22:08 david-allison

@mikehardy

  • F-Droid uses a lower versionCode than play (FDroid: 21602300 , Play: 321602300)
  • If a user uninstalls and keeps data, F-Droid doesn't allow us to downgrade to a lower versionCode

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

david-allison avatar Aug 14 '23 22:08 david-allison

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...

mikehardy avatar Aug 14 '23 23:08 mikehardy

@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)

Exponent4806 avatar Aug 15 '23 04:08 Exponent4806

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?

mikehardy avatar Aug 28 '23 22:08 mikehardy

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

github-actions[bot] avatar Feb 26 '24 17:02 github-actions[bot]

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!

FubayashiKazue avatar Mar 01 '24 02:03 FubayashiKazue