Building expo react native android app on nixos

Hi everyone,

I am trying to build a react native android application using the expo build tool

I am able to upload my app to my android device using the Expo go app, But I cannot build the apk outright as gradle attempts to write some files to a location in the nix store (which it can’t since the nix store is readonly)

here is my repo where I am trying to accomplish this

to reproduce the issue you can run the following commands after connecting an android device to your machine

nix develop
npm ci
npm run android

and here is the console output of running these commands

 npm run android

> nix-expo-attempt@1.0.0 android
> expo run:android

› Building app...
Configuration on demand is an incubating feature.
> Task :gradle-plugin:compileKotlin UP-TO-DATE
> Task :gradle-plugin:compileJava NO-SOURCE
> Task :gradle-plugin:pluginDescriptors UP-TO-DATE
> Task :gradle-plugin:processResources UP-TO-DATE
> Task :gradle-plugin:classes UP-TO-DATE
> Task :gradle-plugin:jar UP-TO-DATE
> Task :gradle-plugin:inspectClassesForKotlinIC UP-TO-DATE
Checking the license for package Android SDK Build-Tools 30.0.3 in /nix/store/vhpffskv3h1skfaa4vx2lak07fypjrpz-androidsdk/libexec/android-sdk/licenses
License for package Android SDK Build-Tools 30.0.3 accepted.
Preparing "Install Android SDK Build-Tools 30.0.3 (revision: 30.0.3)".
Warning: Failed to read or create install properties file.
Checking the license for package Android SDK Platform 33 in /nix/store/vhpffskv3h1skfaa4vx2lak07fypjrpz-androidsdk/libexec/android-sdk/licenses
License for package Android SDK Platform 33 accepted.
Preparing "Install Android SDK Platform 33 (revision: 3)".
Warning: Failed to read or create install properties file.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not determine the dependencies of null.
   > Failed to install the following SDK components:
         platforms;android-33 Android SDK Platform 33
         build-tools;30.0.3 Android SDK Build-Tools 30.0.3
     The SDK directory is not writable (/nix/store/vhpffskv3h1skfaa4vx2lak07fypjrpz-androidsdk/libexec/android-sdk)


* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s
5 actionable tasks: 5 up-to-date
Error: /home/jenkin/workspace/nix-expo-attempt/android/gradlew exited with non-zero code: 1
Error: /home/jenkin/workspace/nix-expo-attempt/android/gradlew exited with non-zero code: 1
    at ChildProcess.completionListener (/home/jenkin/workspace/nix-expo-attempt/node_modules/@expo/spawn-async/build/spawnAsync.js:52:23)
    at Object.onceWrapper (node:events:629:26)
    at ChildProcess.emit (node:events:514:28)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5)
    ...
    at Object.spawnAsync [as default] (/home/jenkin/workspace/nix-expo-attempt/node_modules/@expo/spawn-async/build/spawnAsync.js:17:21)
    at spawnGradleAsync (/home/jenkin/workspace/nix-expo-attempt/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:72:46)
    at Object.assembleAsync (/home/jenkin/workspace/nix-expo-attempt/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:52:18)
    at runAndroidAsync (/home/jenkin/workspace/nix-expo-attempt/node_modules/@expo/cli/build/src/run/android/runAndroidAsync.js:36:24)

any help solving this issue would be much appreciated

1 Like

Welll it seems Gradle is trying to download the and install the Android SDK and failing to do so, since the SDK is located on the read-only Nix store.

I guess there should be a way to tell Gradle not to install the SDK, and where to find it.