wiggle's blog

Building QUIK 4.3.4 on NixOS

I've contributed to the QUIK SMS app a few times in the past, and every time, I have to fight Android Studio to compile it. I'm writing this for myself, but maybe it will help others.

Nix files

These may not be optimal, but they work, ish. I use the NixIDEA plugin and direnv with fehnomenal's "Direnv Integration" plugin.

flake.nix

{
  description = "QUIK";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    devshell.url = "github:numtide/devshell";
    flake-utils.url = "github:numtide/flake-utils";
    android.url = "github:tadfisher/android-nixpkgs";
  };

  outputs = { self, nixpkgs, devshell, flake-utils, android }:
    {
      overlay = final: prev: {
        inherit (self.packages.${final.system}) android-sdk;
      };
    }
    //
    flake-utils.lib.eachSystem [ "aarch64-darwin" "x86_64-darwin" "x86_64-linux" ] (system:
      let
        inherit (nixpkgs) lib;
        pkgs = import nixpkgs {
          inherit system;
          config.allowUnfree = true;
          overlays = [
            devshell.overlays.default
            self.overlay
          ];
        };
      in
      {
        packages = {
          android-sdk = android.sdk.${system} (sdkPkgs: with sdkPkgs; [
            # build-tools-33-0-0
            build-tools-34-0-0
            cmdline-tools-latest
            emulator
            platform-tools
            platforms-android-33
            platforms-android-34
            system-images-android-35-default-x86-64
            ]);
        };

        devShell = import ./devshell.nix { inherit pkgs; };
      }
    );
}

devshell.nix

{ pkgs }:

with pkgs;

# Taken from numtide's devshell
# Documentation: https://github.com/numtide/devshell
devshell.mkShell {
  name = "android-project";
  motd = ''
    Entered the Android app development environment.
  '';
  env = [
    {
      name = "ANDROID_HOME";
      value = "${android-sdk}/share/android-sdk";
    }
    {
      name = "ANDROID_SDK_ROOT";
      value = "${android-sdk}/share/android-sdk";
    }
    {
      name = "JAVA_HOME";
      value = jdk17.home;
    }
  ];
  packages = [
    android-sdk
    gradle
    jdk17
  ];
}

Issues

Android Studio uses the wrong Android SDK

I would often modify the SDK in the flake, only to notice no difference in its behaviour. I kept forgetting to change the SDK to the value of $ANDROID_SDK_ROOT in Project Structure > SDK Location.

./gradlew build requires a keystore properties file

Comment this line in presentation/build.gradle:

throw new GradleException("Keystore properties file not found.")

See the relevant issue on QUIK's repository.

Android Studio doesn't respect JAVA_HOME, set in devshell.nix

This is annoying, as the project uses an old Gradle version, so it needs an old Java version (17). Change "Gradle JDK" to JAVA_HOME in AS Settings > Build, Execution, Deployment > Build Tools > Gradle.

Superclass access check failed

java.lang.IllegalAccessError: superclass access check failed: 
class org.jetbrains.kotlin.kapt3.base.javac.KaptJavaCompiler (in unnamed module @0x483ac2e8) cannot access 
class com.sun.tools.javac.main.JavaCompiler (in module jdk.compiler) 
because module jdk.compiler does not export com.sun.tools.javac.main to unnamed module @0x483ac2e8
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
	at java.base/java.security.SecureClassLoader.defineClass(Unknown Source)
	at java.base/java.net.URLClassLoader.defineClass(Unknown Source)
	at java.base/java.net.URLClassLoader$1.run(Unknown Source)
	at java.base/java.net.URLClassLoader$1.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.base/java.net.URLClassLoader.findClass(Unknown Source)
	at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
	at java.base/java.lang.ClassLoader.loadClass(Unknown Source)

I'm not sure how I fixed this in the past. This time, I downgraded the Kotlin version (ext.kotlin_version) in the root build.gradle from 1.7.21 to 1.7.20. We originally updated from .20 to .21 to fix this issue. I have no idea why this brought it back, only for me.

Emulator management

I had to create a new emulator using avdmanager.

avdmanager create avd --name 35 -k "system-images;android-35;default;x86_64"

and run using emulator.

emulator @35

Contact me: wiggle@mailbox.org

#android #nixos #quik