Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 of 4 tasks
MagTun opened this issue Aug 10, 2023 · 9 comments
Labels
2.16 Bug Keep Open avoids the stale bot Priority-High Release process Reproduced This bug has been reproduced by a maintainer
Milestone

Comments

@MagTun
Copy link

MagTun commented Aug 10, 2023

Checked for duplicates?

  • 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

  • I am reporting a bug specific to AnkiDroid (Android app)
  • 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)
@Exponent4806
Copy link

Exponent4806 commented Aug 14, 2023

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
Copy link
Author

MagTun commented Aug 14, 2023

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

@david-allison
Copy link
Member

david-allison commented Aug 14, 2023

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
Copy link
Member

david-allison commented Aug 14, 2023

@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

versionCode=21602300

// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
// We want the same version stream for all ABIs in debug but for release we can split them
if (variant.buildType.name == 'release') {
variant.outputs.all { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def abi = output.getFilter("ABI")
if (abi != null) { // null for the universal-debug, universal-release variants
// From: https://developer.android.com/studio/publish/versioning#appversioning
// "Warning: The greatest value Google Play allows for versionCode is 2100000000"
// AnkiDroid versionCodes have a budget 8 digits (through AnkiDroid 9)
// This style does ABI version code ranges with the 9th digit as 0-4.
// This consumes ~20% of the version range space, w/50 years of versioning at our major-version pace
output.versionCodeOverride =
// ex: 321200106 = 3 * 100000000 + 21200106
versionCodes.get(abi) * 100000000 + defaultConfig.versionCode
}
}
}
}

@david-allison david-allison added Priority-High Accepted Maintainers welcome a PR implementing this feature Release process Reproduced This bug has been reproduced by a maintainer and removed Needs Triage Accepted Maintainers welcome a PR implementing this feature labels Aug 14, 2023
@mikehardy
Copy link
Member

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
Copy link

Exponent4806 commented Aug 15, 2023

@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
Copy link
Member

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?

This comment was marked as outdated.

@github-actions github-actions bot added the Stale label Feb 26, 2024
@david-allison david-allison added Keep Open avoids the stale bot and removed Stale labels Feb 26, 2024
@FubayashiKazue
Copy link

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!

@mikehardy mikehardy added this to the 2.19 release milestone May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.16 Bug Keep Open avoids the stale bot Priority-High Release process Reproduced This bug has been reproduced by a maintainer
Projects
None yet
Development

No branches or pull requests

5 participants