Open cheriimoya opened 2 years ago
@cheriimoya I was having a similar problem, changing to jdk8 solved it, but I'm using androidEnv.composeAndroidPackages
with this configuration:
{
pkgs ? import <nixos-unstable> {config.android_sdk.accept_license = true;},
pkgs_i686 ? import <nixos-unstable> { system = "i686-linux"; },
config ? pkgs.config
}:
let
# Declaration of versions for everything. This is useful since these
# versions may be used in multiple places in this Nix expression.
android = {
versions = {
tools = "26.1.1";
platformTools = "31.0.3";
buildTools = "30.0.2";
ndk = [
"22.1.7171670"
"21.3.6528147" # LTS NDK
];
cmake = "3.18.1";
emulator = "30.9.0";
};
platforms = ["23" "24" "25" "26" "27" "28" "29" "30"];
abis = ["armeabi-v7a" "arm64-v8a"];
extras = ["extras;google;gcm"];
};
androidEnv = pkgs.androidenv;
androidComposition = androidEnv.composeAndroidPackages {
toolsVersion = android.versions.tools;
platformToolsVersion = android.versions.platformTools;
buildToolsVersions = [android.versions.buildTools];
platformVersions = android.platforms;
abiVersions = android.abis;
includeSources = true;
includeSystemImages = true;
includeEmulator = true;
emulatorVersion = android.versions.emulator;
includeNDK = true;
ndkVersions = android.versions.ndk;
cmakeVersions = [android.versions.cmake];
useGoogleAPIs = true;
includeExtras = android.extras;
# Accepting more licenses declaratively:
extraLicenses = [
"android-sdk-preview-license"
"android-googletv-license"
"android-sdk-arm-dbt-license"
"google-gdk-license"
"intel-android-extra-license"
"intel-android-sysimage-license"
"mips-android-sysimage-license"
];
};
androidSdk = androidComposition.androidsdk;
platformTools = androidComposition.platform-tools;
jdk = pkgs.jdk8;
in
pkgs.mkShell rec {
name = "androidenv-demo";
packages = [ androidSdk platformTools jdk pkgs.android-studio pkgs.flutter ];
LANG = "C.UTF-8";
LC_ALL = "C.UTF-8";
JAVA_HOME = jdk.home;
# Note: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT.
ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle";
# Ensures that we don't have to use a FHS env by using the nix store's aapt2.
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_SDK_ROOT}/build-tools/${android.versions.buildTools}/aapt2";
shellHook = ''
# Add cmake to the path.
cmake_root="$(echo "$ANDROID_SDK_ROOT/cmake/${android.versions.cmake}"*/)"
export PATH="$cmake_root/bin:$PATH"
# Write out local.properties for Android Studio.
cat <<EOF > local.properties
# This file was automatically generated by nix-shell.
sdk.dir=$ANDROID_SDK_ROOT
ndk.dir=$ANDROID_NDK_ROOT
cmake.dir=$cmake_root
EOF
'';
}
(Change the nixos-unstable to your unstable channel)
Then I can run avdmanager create avd -n test -k "system-images;android-30;google_apis_playstore;arm64-v8a"
without any problems
But now I'm stuck in another problem, after doing
cd $ANDROID_SDK_ROOT/tools/
QT_QPA_PLATFORM=xcb emulator -avd test -qemu -machine virt
I'm having the same issue of https://github.com/NixOS/nixpkgs/issues/121146 :disappointed:
But I hope this can help you in any way
@cheriimoya @shiryel Hello there. I do know if helps, but I want share my steps to run the android emulator from nix.
with import <nixpkgs>{
config.android_sdk.accept_license = true;
config.allowUnfree = true;
};
androidenv.emulateApp { name = "emulate-MyAndroidApp"; platformVersion = "24"; abiVersion = "x86"; # mips, x86 or x86_64 systemImageType = "google_apis_playstore"; avdHomeDir = "/home/rodrigo/.avd"; enableGPU = true; }
2. I run `nix-build shell.nix`
3. I run `./result/bin/run-test-emulator` and doesn't work, so google it and fall in this page and I try RUN like this: `QT_QPA_PLATFORM=xcb ./result/bin/run-test-emulator` and the emulator starts running.
I guess that the android section is missing some important parts talking about important configs about the emutator.
Credits:
[https://nixos.wiki/wiki/Android](https://nixos.wiki/wiki/Android)
[https://sandervanderburg.blogspot.com/2012/11/building-android-applications-with-nix.html](https://sandervanderburg.blogspot.com/2012/11/building-android-applications-with-nix.html)
[https://sandervanderburg.blogspot.com/2014/02/reproducing-android-app-deployments-or.html](https://sandervanderburg.blogspot.com/2014/02/reproducing-android-app-deployments-or.html)
Describe the bug
avdmanager fails to create new avds from the command line.
avd = android virtual device
I can provide more information if needed.
Steps To Reproduce
avdmanager create avd -n test -k "system-images;android-25;google_apis;x86"
Expected behavior
The avd gets created because the sdk/avd can write to the package.xml files somehow (maybe in a temp directory?)
Additional context
the package.xml are not inside the path, so i assume the android sdk expects to be running in
~/.android/sdk
or something alike. i don't know much about the android sdk (and android in general) but i assume these files are being generated by the sdk manager on startup.https://developer.android.com/studio/command-line/avdmanager
Another interesting thing/workaround is, that i am able to create an avd by using android-studio. Here i can simply enter the avdmanager and create an avd. Difference here is, that android-studio downloads and stores an android sdk to
~/Android/Sdk/
with all tools running there.There is also #19452, but i am not sure if thats connected to this issue.
Maybe it is possible to simply render those files to the specified locations, but i am not that skilled with nix as of now.
Here is the `build-tools/32.0.0/package.xml` file from the mutable sdk location
```xmlHere is the diff between the `package.xml` file above and `platform-tools/package.xml`
```diff 141c141 < January 16, 2019diff build-tools/32.0.0/package.xml platforms/android-32/package.xml
```diff 141c141 < January 16, 2019diff build-tools/32.0.0/package.xml tools/package.xml
```diff 141c141 < January 16, 2019Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.