Is anyone using Nixos to build react-native projects?
The command ./gradlew build --stacktrace
fails with error
com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.1-5326820-linux
Daemon #0: Daemon startup failed
And a some lines below:
Caused by: java.io.IOException: Cannot run program "/home/federico/.gradle/caches/transforms-2/files-2.1/2df53a66e454f1abff0680fcd8c73763/aapt2-3.4.1-5326820-linux/aapt2": error=2, No such file or directory
However said file is there:
$ ls -lh ~/.gradle/caches/transforms-2/files-2.1/2df53a66e454f1abff0680fcd8c73763/aapt2-3.4.1-5326820-linux/
total 4.1M
-rwx-w---- 1 federico users 4.0M Oct 29 09:20 aapt2
drwx-w---- 2 federico users 4.0K Oct 29 09:20 META-INF
-rw--w---- 1 federico users 11K Oct 29 09:20 NOTICE
and
$ ldd /home/federico/.gradle/caches/transforms-2/files-2.1/2df53a66e454f1abff0680fcd8c73763/aapt2-3
.4.1-5326820-linux/aapt2
linux-vdso.so.1 (0x00007fffaf7b7000)
libdl.so.2 => /nix/store/qn76sklvyalzw9ilnxz6sh0020gl2qn6-glibc-2.27/lib/libdl.so.2 (0x00007f436aa01000)
libpthread.so.0 => /nix/store/qn76sklvyalzw9ilnxz6sh0020gl2qn6-glibc-2.27/lib/libpthread.so.0 (0x00007f436a9e0000)
libm.so.6 => /nix/store/qn76sklvyalzw9ilnxz6sh0020gl2qn6-glibc-2.27/lib/libm.so.6 (0x00007f436a84a000)
librt.so.1 => /nix/store/qn76sklvyalzw9ilnxz6sh0020gl2qn6-glibc-2.27/lib/librt.so.1 (0x00007f436a840000)
libgcc_s.so.1 => /nix/store/qn76sklvyalzw9ilnxz6sh0020gl2qn6-glibc-2.27/lib/libgcc_s.so.1 (0x00007f436a62a000)
libc.so.6 => /nix/store/qn76sklvyalzw9ilnxz6sh0020gl2qn6-glibc-2.27/lib/libc.so.6 (0x00007f436a474000)
/lib64/ld-linux-x86-64.so.2 => /nix/store/qn76sklvyalzw9ilnxz6sh0020gl2qn6-glibc-2.27/lib64/ld-linux-x86-64.so.2 (0x00007f436ad53000)
Running through ld-linux works
/nix/store/qn76sklvyalzw9ilnxz6sh0020gl2qn6-glibc-2.27/lib/ld-linux-x86-64.so.2 ./aapt2
error: no subcommand specified.
Am I missing something?
Having the same issue.
@PositronicBrain, I was able to work around this issue via this shell.nix
:
{ pkgs ? import <nixpkgs> {config.android_sdk.accept_license = true;} }:
(pkgs.buildFHSUserEnv {
name = "android-sdk-env";
targetPkgs = pkgs: (with pkgs;
[
androidenv.androidPkgs_9_0.androidsdk
glibc
]);
runScript = "bash";
}).env
Make sure you kill your gradle daemon before entering!
Having the same issue.
Gradle gets the aapt2 binary from maven by default. That one wont work on nix so you need to specify the patched one from the androidenv sdk.
androidSdk = androidenv.androidPkgs_9_0.androidsdk;
Then on you project's gradle.properties (through env variables or appending via echo):
android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/28.0.3/aapt2
That worked for me on a pure shell without having to use buildFHSUserEnv
this works for me:
{ pkgs ? import <nixpkgs> {config.android_sdk.accept_license = true;} }:
let
androidSdk = pkgs.androidenv.androidPkgs_9_0.androidsdk;
in
pkgs.mkShell {
buildInputs = with pkgs; [
androidSdk
glibc
];
# override the aapt2 binary that gradle uses with the patched one from the sdk
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/28.0.3/aapt2";
}
I documented this over at https://nixos.wiki/wiki/Android#gradlew
@dacevedo12, you are a lifesaver. I've been stuck on this particular error for 4 days.
Most helpful comment
this works for me: