Nixpkgs: Nixos android sdk license

Created on 15 Mar 2017  路  15Comments  路  Source: NixOS/nixpkgs

Issue description

Hi,

How do I accept the sdk license on nixos? Thanks!

Steps to reproduce

$ ANDROID_HOME=~/.nix-profile/libexec/ LD_LIBRARY_PATH=/nix/store/23cqmxnpr8
pdg1ivirb399g6ahh3dwlg-ncurses-5.9/lib/ gradle build
...
You have not accepted the license agreements of the following SDK components:
  [Android SDK Platform 25].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html

Technical details

  • System: (NixOS: nixos-version, Ubuntu/Fedora: lsb_release -a, ...)
  • Nix version: (run nix-env --version)
  • Nixpkgs version: (run nix-instantiate --eval '<nixpkgs>' -A lib.nixpkgsVersion)
question

Most helpful comment

Updated https://github.com/NixOS/nixpkgs/pull/89775 - finally some time to make progress.

@Abdillah I'm adding an option to write out the android-sdk-preview-license file too

All 15 comments

Running into the same problem trying to build a react-native project on NixOS. In an imperative world, we could just run this:

yes | $ANDROID_HOME/tools/bin/sdkmanager "platforms;android-25"

However, this fails because /nix/store is not writable

I have read elsewhere, that the ANDROID_HOME should be set to a directory in $HOME to allow the SDK to manage its software on its own, but I'm not sure how to work with that setup exactly.

This is not a solution, but I hacked my way though a setup that at least lets me get work done in react-native for now, and maybe it will unblock someone else until the right way to do this is shared/documented/fixed:

https://github.com/uniphil/nix-for-devs/blob/bf3612f8635d05426161eae49ec478bb07df8730/README.md#react-native

I see many Travis-CI scripts just do

mkdir -p "$ANDROID_SDK/licenses"
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_SDK/licenses/android-sdk-preview-license"

Does it possible to run echo yes | $PATH/bin/sdkmanager --update in postInsstall hooks? As if the user run the sdk after install. Since user able to install the SDK, it must have accept the license through the expression.

I'm using nixos-20.03pre-git and my $HOME/.config/nixpkgs/config.nix already contained:

{ android_sdk.accept_license = true;
}

But when I run nix-shell inside my android project, I still get an error:

You must accept the Android Software Development Kit License Agreement at
https://developer.android.com/studio/terms
by setting nixpkgs config option 'android_sdk.accept_license = true;'

I try to use @uniphil hack, but still I got the android sdk license issue.

So what I gather from the issues and doing some testing is that the nixos packaged android sdks cannot actually be used for building android apps, because of those missing license files. Is that right? Am I missing something here?

It seems like that explanation makes no sense. But there are several people scrambling to figure this out with various workarounds, and I haven't seen anyone say "no, it's working as intended, here's how you do it."

Could someone please shed some light on this? @svanderburg?

@Valodim - I'm not sure exactly how it is supposed to work, but for some reason the licenses are successfully accepted for me if I do config.android_sdk.accept_license = true; and use androidenv.buildApp. Now it doesn't work if I merely depend on the sdk, I actually have to use the androidenv.buildApp. I don't use ant to build my app, so I can't actually build my app this way, but by making the androidenv.buildApp package and then invoking nix-shell, I end up in a shell where the licenses are accepted and the tools work.

In order to get some of the newer platform version 29 / JetPack stuff to work with the new aapt2, I've additionally had to build a FHSUserEnv so the new aapt2 downloaded through google's maven can run unpatched. This might be a bit of overkill for you (and I'm sure this could be made way better) but here's the default.nix that I'm using to build my current app (and note that I just use with nix-shell and call gradlew manually)

https://github.com/Limvot/slate/blob/ebc51922db33ee79c5848fb56ecbebd0ac76400e/default.nix

@Limvot are you sure the SDK that's used for you is the packaged one? I was fooled there for a while, because I had a local.properties that pointed to a (writable) path in my home directory and between gradlew and android studio stuff worked - but not actually using the nix-provided SDKs.

@Valodim Yep, I'm pretty positive. I've developed with on NixOS with android studio in the past, but I've uninstalled it and deleted all of the various android directories out of my home folder, and my default.nix works great. It prints out some warnings as it builds showing that the SDK's path is in the nix store as well.

interesting to know, I'll give that a shot. but man, information about this all over the place :( I imagine the 98% thing to be done for android developers that look at the android sdk packaging is "I have a gradlew, how do I build stuff". I've been looking at this stuff for days and couldn't find an answer that didn't feel like a huge hack.

@Limvot Here's a trick to make gradle use the sdk-provided aapt2, might get around the fhs that way:

  # override the aapt2 that gradle uses with the nix-shipped version
  GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/28.0.3/aapt2";

@Valodim - I'm not sure exactly how it is supposed to work, but for some reason the licenses are successfully accepted for me if I do config.android_sdk.accept_license = true; and use androidenv.buildApp. Now it doesn't work if I merely depend on the sdk, I actually have to use the androidenv.buildApp. I don't use ant to build my app, so I can't actually build my app this way, but by making the androidenv.buildApp package and then invoking nix-shell, I end up in a shell where the licenses are accepted and the tools work.

In order to get some of the newer platform version 29 / JetPack stuff to work with the new aapt2, I've additionally had to build a FHSUserEnv so the new aapt2 downloaded through google's maven can run unpatched. This might be a bit of overkill for you (and I'm sure this could be made way better) but here's the default.nix that I'm using to build my current app (and note that I just use with nix-shell and call gradlew manually)

https://github.com/Limvot/slate/blob/ebc51922db33ee79c5848fb56ecbebd0ac76400e/default.nix

@Limvot thank you for this description. the first part about the android_sdk.accept_license = true; only being valid if you build your app with the SDK androidenv.buildApp is particularly telling to why I wasnt able to get it working with flutter.

The changes in #89775 might be relevant here.

Has anyone got this working yet? I'm completely stuck :-1:

I think I'm halfway through setup an sdk with license accepted. The missing part would be the content of licenses/ directory (I've copied @volth's comment and didn't work). But, you can copy the license fromanother machine.

{ pkgs ? import <nixpkgs> { 
  config.android_sdk.accept_license = true;
  overlays = [
    (self: super: rec {
      androidPkgs_5_0 = (super.androidenv.composeAndroidPackages {
        platformVersions = [ "21" ];
        abiVersions = [ "x86" "x86_64"];
      });
      androidsdk = androidPkgs_5_0.androidsdk.overrideAttrs (oldAttrs: {
        installPhase = oldAttrs.installPhase + ''
            mkdir -p "$out/licenses";
            echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$out/licenses/android-sdk-license";
            echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$out/licenses/android-sdk-preview-license";
        '';
      });
    })
  ];
} }:

(pkgs.buildFHSUserEnv {
  name = "android-sdk-env";
  targetPkgs = pkgs: (with pkgs;
    [
      jdk
      androidsdk
      glibc
    ]);
  runScript = "bash";
}).env

Updated https://github.com/NixOS/nixpkgs/pull/89775 - finally some time to make progress.

@Abdillah I'm adding an option to write out the android-sdk-preview-license file too

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rzetterberg picture rzetterberg  路  3Comments

grahamc picture grahamc  路  3Comments

ghost picture ghost  路  3Comments

yawnt picture yawnt  路  3Comments

vaibhavsagar picture vaibhavsagar  路  3Comments