Understanding details of build environment

I am trying to understand a bug in the F-droid version of org.totschnig.myexpenses which seems caused by some details of the tool chain that are different from when I build the app locally.

The app crashes on Android 10 when using code from ktor-server library with

Caused by: java.lang.VerifyError: Verifier rejected class dd.a: void dd.a.E(int, int, byte[]) failed to verify: void dd.a.E(int, int, byte[]): [0x8] void dd.a.E(int, int, byte[]): [0x8] register v3 has type Precise Reference: byte[] but expected Reference: java.lang.Object[]

When I build the app locally with the Gradle command that is also used by F-droid (packageExternReleaseUniversalApk), the crash does not happen.

Looking at the log file (log: org.totschnig.myexpenses:834 - F-Droid Monitor), I could not find any conclusive difference:

  • It does not use the Gradle wrapper, but still uses the same Gradle version 9.3.1.
  • The log file does not print which version of the Android Gradle Plugin is used, so I guess, it respects the version from my catalogue: 9.0.1
  • It mentions Build tools version 36.0.0, which might be different from the one I would by default use locally (36.1.0), but even if add buildToolsVersion "36.0.0" to my local build, to force the same, my build still does not reproduce the issue.
  • The log file does not print very specific information about the Java version used, besides the mention of “Java compiler version 21”

So I am left wondering, what else could cause the F-Droid build to behave differently, for example pick up a different AGP or R8 version?

So what if you disassemble both APKs and run them through diffoscope?

I realized that actually the difference was not between the F-Droid build and my local build, but between the build from the latest release tag (r834) and the current Head of master. It seems that the failing build runs into some R8 edge case of how registers are used. I will try to protect against this with adding R8 rules. I started diffoscope on a comparison between the 2 builds, but was not able to complete it due to it slowing down my workstation for too long, but will launch it again later.

pleas first run apktool d to disassemble, then diffoscope --exclude-directory-metadata=recursive folder2 folder2

This results in a file of 105M (9M gzipped). If you think it is relevant, I can attach it here (if allowed, on Github, or send it by email). But I found a solution to the problem, that is not dependent on R8. Both apks (from release tag and from master) use version 1.71 of bouncycastle. If I patch both versions to use the current version 1.83, the crash is solved. It seems bouncycastle improved support for r8 in the meantime.

I don’t care, fix it and carry on :slight_smile: