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
First, I would like to thank you for pointing me in the right direction. I was trying to figure out how to build a react native app in NixOS and didn’t even think about using flakes.
I copied your flake and ran into the same problem, but I was able to solve it by defining my own android composition with the required versions.
This flake got me the closest to working from anything else I’ve read online, but now I’m encountering this error trying to build my react-native app with expo:
/nix/store/psvyy0kbz423j2apxlzrkwn2zj6iw347-androidsdk/libexec/android-sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/bin/ld.lld: error while loading shared libraries: libxml2.so.2: cannot open shared object file: No such file or directory
clang: error: unable to execute command: No such file or directory
clang: error: linker command failed due to signal (use -v to see invocation)
ninja: build stopped: subcommand failed.
I’ve tried explicitly adding libxml2.dev to the buildInputs, and setting LD_LIBRARY_PATH = "${pkgs.libxml2.dev}/include" but those don’t work.
Running pkg-config --cflags libxml-2.0 outputs -I/nix/store/37979sqc7yw9ps0c4xl9jjkhq0w1hw8b-libxml2-2.12.7-dev/include/libxml2 from my shell, so I’m not sure what’s going wrong.
After hours of trying I’ve finally managed to successfully build locally with expo on NixOS through distrobox
I used the Arch image (distrobox-create --name arch --image archlinux:latest), ran sudo pacman -Syu and didn’t do much else apart from the obvious npx expo run:android
I think the build ran successfully on the first try!