diff --git a/android.nix b/android.nix
index 30309a0e642a6983d924ef5320a1e4a3809af076..f031ae0b5803ce9102c0d4bbbd7aab7f068a4544 100644
--- a/android.nix
+++ b/android.nix
@@ -1,20 +1,19 @@
-{ androidenv, cmakeVersion }:
+{ androidenv, cmakeVersion, buildToolsVersion, ndkVersion }:
 let
   androidComposition = androidenv.composeAndroidPackages {
     toolsVersion = "26.1.1";
     # platformToolsVersion = "30.0.5";
-    buildToolsVersions = [ "30.0.3" ];
+    buildToolsVersions = [ buildToolsVersion ];
     includeEmulator = false;
     emulatorVersion = "30.3.4";
-    platformVersions = [ "27" "28" "29" "30" ];
+    platformVersions = [ "31" ];
     includeSources = false;
     includeSystemImages = false;
     systemImageTypes = [ "google_apis_playstore" ];
     abiVersions = [ "armeabi-v7a" "arm64-v8a" ];
     cmakeVersions = [ cmakeVersion ];
     includeNDK = true;
-    # Check out pkgs/development/mobile/androidenv/repo.json
-    ndkVersions = [ "23.0.7123448-rc1" "22.0.7026061" ];
+    ndkVersions = [ ndkVersion ];
     useGoogleAPIs = false;
     useGoogleTVAddOns = false;
     includeExtras = [
diff --git a/app/app/build.gradle b/app/app/build.gradle
index 683f3595b14b84b2a6e6d2bf915bd4d94ff09197..e25b51898d6a45a8e7dac7c5e17c07159a3353d3 100644
--- a/app/app/build.gradle
+++ b/app/app/build.gradle
@@ -5,7 +5,14 @@ plugins {
 }
 
 android {
-    compileSdk 32
+    compileSdk 31
+    buildToolsVersion "30.0.3"
+    ndkVersion "23.0.7123448"
+    externalNAtiveBuild {
+        cmake {
+	    version "3.10.2"
+        }
+    }
 
     defaultConfig {
         applicationId "com.example.privatestorage"
diff --git a/flake.nix b/flake.nix
index 7866fe675aec453afdb209229a4e279be45f589b..3577166966b2bc0641bc518437c9826248434cb3 100644
--- a/flake.nix
+++ b/flake.nix
@@ -64,10 +64,28 @@
 
       };
 
+      # THESE MUST AGREE WITH app/app/build.gradle
+      #
+      # If they do not you will get failures that look something like:
+
+      # FAILURE: Build failed with an exception.
+      #
+      # * What went wrong:
+      # Could not determine the dependencies of task ':app:compileReleaseJavaWithJavac'.
+      # > Failed to install the following SDK components:
+      #       platforms;android-32 Android SDK Platform 32
+      #   The SDK directory is not writable (/nix/store/46214a16f22rd7q8vkrhsa907ra0405l-androidsdk/libexec/android-sdk)
+
       cmakeVersion = "3.10.2";
+      buildToolsVersion = "30.0.3";
+      # Check out pkgs/development/mobile/androidenv/repo.json for
+      # nixpkgs-supported versions.
+      ndkVersion = "23.0.7123448-rc1";
 
       # Also includes ndk
-      androidComposition = pkgs.callPackage ./android.nix { inherit cmakeVersion; };
+      androidComposition = pkgs.callPackage ./android.nix {
+        inherit cmakeVersion buildToolsVersion ndkVersion;
+      };
 
       getBuildInputs = getInputs: xs: builtins.foldl' (accum: drv: (getInputs drv) ++ accum) [] xs;
 
@@ -79,12 +97,12 @@
       };
     in {
 
-      packages.default = pkgs.androidenv.buildApp {
+      packages.apk = pkgs.androidenv.buildApp {
         name = "PrivateStorage Mobile";
         src = ./app;
         release = false;
 
-        platformVersions = [ "27" ];
+        platformVersions = [ "31" ];
         includeNDK = false;
       };
 
@@ -93,7 +111,7 @@
         program = let
           emulator = pkgs.androidenv.emulateApp {
             name = "PrivateStorage Mobile";
-            platformVersion = "27";
+            platformVersion = "31";
             abiVersion = "x86_64";
             systemImageType = "default";
             app = ./app/app/build/outputs/apk/debug/app-debug.apk;