Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Android applications with reproducible builds?

In my experience, recompiling the source code for the same Android application won't produce the same binary every time. A reproducible build is very useful for developers, but I think the most important benefit from a reproducible build process is security. In open source Android apps, how we can verify produced binary (.apk) is really compiled from reviewed source code? Is there any way to generate reproducible builds from Android SDK or Java?

like image 316
manhood Avatar asked Oct 22 '13 07:10

manhood


2 Answers

"Reproducible"/"deterministic" build refers to build processes where the compiler outputs a binary that is always identical, given identical input files/build system/chroot. (The article you linked to is actually talking about being able to build/run the same version of an app that a bug is filed against, which is something different. See this description of how Tor makes deterministic builds.)

Java packages seem to be very difficult to work with, since timestamps are present in many, many places. One thing you could try, in lieu of exact binary compatibility, is to decompile the two .apk's, and see if that decompiled output is identical.

like image 107
chronospoon Avatar answered Oct 15 '22 05:10

chronospoon


The F-Droid project has been working on reproducible builds for Android for a couple years now. The Android-specific issues are tracked at https://f-droid.org/docs/Reproducible_Builds It is still a tricky process, especially if the app includes NDK code. If the app is only Java, then there are a few relatively easy steps that will get you there, like pre-crunching PNGs and committing them to git.

Google doesn't make it easy to reproduce APKs in the longer term, since they do a lot of random little changes, like:

  • adding a non-reproducible version to AndroidManifest.xml
  • different binary releases with the same version number

Definitely check out diffoscope for viewing the differences between two builds. You can see lots of example output at https://verification.f-droid.org

like image 40
Hans-Christoph Steiner Avatar answered Oct 15 '22 04:10

Hans-Christoph Steiner