com.android.sdkmanager.toolsdir is unset, causing avdmanager to traverse the entire nix store
hazelweakly opened this issue · 1 comments
tl;dr at bottom.
I'm currently on x86_64-darwin
, but I don't suspect that changes things (wouldn't be the first time, though...). The error occurs with anything that gets the cmdline-tools-latest
, although I strongly suspect it will also trigger on the other cmdline- tools versions.
I noticed this first because avdmanager list --verbose avd
hangs for several minutes, finally spitting out multiple path collisions that indicate it has traversed the entire nix store looking for stuff.
The wrapper already sets JAVA_OPTS to include -Dcom.android.sdklib.toolsdir
in pkgs/android/cmdline-tools.nix
, but in line 31 of $out/share/android-sdk/cmdline-tools/latest/bin/avdmanager
, you can see that the default jvm opts is set to DEFAULT_JVM_OPTS='-Dcom.android.sdkmanager.toolsdir=$APP_HOME'
So since that is actually in an entirely separate directory, and the java wrapper tries very hard to chase all symlinks and then traverse up, it'll crawl the entire nix store looking for the right directory. Sigh. (It gets better: because it crawls the whole nix store, it eventually "works" but finds the first set of system images, which isn't necessarily the right one).
As an interesting aside, if you sit there and let things happen, because of how it traverses things and tries to find the right path, any avd created with avdmanager is going to end up with ~/.android/avd/${yourDevice}.avd/config.ini
containing a image.sysdir.1=store/$nix_store_hash-android-env/share/android-sdk/system-images/android-XX/...
prefix rather than the expected image.sysdir.1=system-images/android-XX/...
Long story short, this seems to completely resolve things on my system. avdmanager
no longer traverses the entire nix store and hangs for 5 minutes.
diff --git a/pkgs/android/cmdline-tools.nix b/pkgs/android/cmdline-tools.nix
index 0a91db3..7181200 100644
--- a/pkgs/android/cmdline-tools.nix
+++ b/pkgs/android/cmdline-tools.nix
@@ -9,7 +9,8 @@ mkGeneric
makeWrapper $script $out/bin/$(basename $script) \
--set-default JAVA_HOME "${jdk.home}" \
--set-default ANDROID_SDK_ROOT $ANDROID_SDK_ROOT \
- --prefix JAVA_OPTS ' ' "-Dcom.android.sdklib.toolsdir=$pkgBase"
+ --prefix JAVA_OPTS ' ' "-Dcom.android.sdklib.toolsdir=$pkgBase" \
+ --prefix JAVA_OPTS ' ' "-Dcom.android.sdkmanager.toolsdir=$pkgBase"
done
'';
}
Should I open up a PR for that?
PS: It's a good thing avdmanager
isn't written in rust. It might've been so performant I wouldn't have even noticed 😜
Yes please! This was a good catch.