This is the current documentation:
|
If you are running the Android Gradle plugin, you need to export GRADLE_OPTS to override aapt2 |
|
to point to the aapt2 binary in the Nix store as well, or use a FHS environment so the packaged |
|
aapt2 can run. If you don't want to use a FHS environment, something like this should work: |
|
|
|
```nix |
|
let |
|
buildToolsVersion = "30.0.3"; |
|
|
|
# Use buildToolsVersion when you define androidComposition |
|
androidComposition = <...>; |
|
in |
|
pkgs.mkShell rec { |
|
ANDROID_HOME = "${androidComposition.androidsdk}/libexec/android-sdk"; |
|
ANDROID_NDK_ROOT = "${ANDROID_HOME}/ndk-bundle"; |
|
|
|
# Use the same buildToolsVersion here |
|
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_HOME}/build-tools/${buildToolsVersion}/aapt2"; |
|
} |
|
``` |
However, when I try to run gradle with GRADLE_OPTS=-Dorg.gradle.project.android.aapt2FromMavenOverride=/nix/store/k8spr2mqms0xdbk1gc9ychx2avh66c7g-androidsdk/libexec/android-sdk/build-tools/35.0.0/aapt2, gradle still attempts to use the FHS-assuming binary it downloaded to the gradle cache which predictably fails:
> Could not resolve all files for configuration ':app:premiumDebugRuntimeClasspath'.
> Failed to transform biometric-1.2.0-alpha05.aar (androidx.biometric:biometric:1.2.0-alpha05) to match attributes {artifactType=android-compiled-dependencies-resources, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
> Execution failed for AarResourcesCompilerTransform: /Users/atemu/.gradle/caches/8.13/transforms/a203d07b82655c0b98705869af96ec4f/transformed/biometric-1.2.0-alpha05.
> AAPT2 aapt2-8.9.1-12782657-linux Daemon #0: Daemon startup failed
This should not happen under normal circumstances, please file an issue if it does.
--scan to get any sort of useful information out of gradle (why doesn't it just print the stderr of the failing command by default?!) confirms what it's doing:
AAPT2 aapt2-8.9.1-12782657-linux Daemon #1: Unexpected error output: Could not start dynamically linked executable: /Users/atemu/.gradle/caches/8.13/transforms/d828a5b8de1e37f81feb90173f16523e/transformed/aapt2-8.9.1-12782657-linux/aapt2
AAPT2 aapt2-8.9.1-12782657-linux Daemon #1: Unexpected error output: NixOS cannot run dynamically linked executables intended for generic
AAPT2 aapt2-8.9.1-12782657-linux Daemon #1: Unexpected error output: linux environments out of the box. For more information, see:
AAPT2 aapt2-8.9.1-12782657-linux Daemon #1: Unexpected error output: https://nix.dev/permalink/stub-ld
According to this, this env var apparently isn't about gradle cmd line opts at all and only concerns JVM options. This does not strike me as sane design in any way shape or form. There does not appear to be an environment variable documented which does what we want it to do.
I think we should instead solve this using a gradle wrapper (as in our own wrapping, not gradlew). Perhaps that would be a better design anyways given how easy it is to accidentally override env vars.
cc @numinit who authored this in 5b91d4a
This is the current documentation:
nixpkgs/doc/languages-frameworks/android.section.md
Lines 262 to 280 in 83e07f6
However, when I try to run gradle with
GRADLE_OPTS=-Dorg.gradle.project.android.aapt2FromMavenOverride=/nix/store/k8spr2mqms0xdbk1gc9ychx2avh66c7g-androidsdk/libexec/android-sdk/build-tools/35.0.0/aapt2, gradle still attempts to use the FHS-assuming binary it downloaded to the gradle cache which predictably fails:--scanto get any sort of useful information out of gradle (why doesn't it just print the stderr of the failing command by default?!) confirms what it's doing:According to this, this env var apparently isn't about gradle cmd line opts at all and only concerns JVM options. This does not strike me as sane design in any way shape or form. There does not appear to be an environment variable documented which does what we want it to do.
I think we should instead solve this using a gradle wrapper (as in our own wrapping, not gradlew). Perhaps that would be a better design anyways given how easy it is to accidentally override env vars.
cc @numinit who authored this in 5b91d4a