Accepting AndroidSDK license does not work for me inside nix-shell

Hi everyone,

I downloaded the sources of an existing Android app and am trying to compile it on my NixOS system (19.09 stable) with the scripts shipping in the repository.

For this, I created the following default.nix file that I use with nix-shell:

with import <nixpkgs> {};
{
    appEnv = stdenv.mkDerivation {
        name = "app";
        buildInputs = [openjdk androidenv.androidPkgs_9_0.androidsdk];
        ANDROID_HOME = "/home/my-user/.android";
    };
}

In order to be able to invoke nix-shell default.nix, I needed to add the following lines to ~/.config/nixpkgs/config.nix:

{
    allowUnfree = true;
    android_sdk.accept_license = true;
}

Afterwards, creating the nix-shell worked, but when I run the application’s build script, I get the following error:

Building and installing the app on the device (cd android && ./gradlew installDebug)...
Checking the license for package Android SDK Build-Tools 25.0.1 in /nix/store/69zj7qfqqnh2w8xzkasf6263rh4r2hz9-androidsdk/libexec/licenses
Warning: License for package Android SDK Build-Tools 25.0.1 not accepted.
Checking the license for package Android SDK Platform 25 in /nix/store/69zj7qfqqnh2w8xzkasf6263rh4r2hz9-androidsdk/libexec/licenses
Warning: License for package Android SDK Platform 25 not accepted.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Build-Tools 25.0.1, 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

After some searching, I found that this issue could be resolved by running sdkmanager --update, which prints the license and ask Accept? (y/N): .
After entering y the following output appears

Warning: Failed to read or create install properties file.
done

and the build command produces the same error message as above.

I also tried adding the package and the accept_license to /etc/nixos/configuration.nix but it did not help as well.

Since I hit a roadblock there, I was wondering, if someone in the forum might have an idea on what may be wrong with my configuration, or what I could do to get the license accepted.

1 Like

instead of accepting the licenses globally, I accept them in shell.nix like:

{ pkgs ? import <nixpkgs> { config.android_sdk.accept_license = true; } }:
2 Likes

@raboof thank you very much for the reply.

I tried it with the following shell.nix:

{ pkgs ? import <nixpkgs> { config.android_sdk.accept_license = true; } }:
let
    sdk = pkgs.androidenv.androidPkgs_9_0.androidsdk;
    jdk = pkgs.openjdk;
in
pkgs.stdenv.mkDerivation {
    name = "datinstaller";
    buildInputs = [ jdk sdk ];
    #ANDROID_HOME = "${sdk}/libexec";
    ANDROID_HOME = "/home/user/.android";
}

However, I still get license errors:

Building and installing the app on the device (cd android && ./gradlew installDebug)...
Checking the license for package Android SDK Build-Tools 25.0.1 in /home/user/.android/licenses
Warning: License for package Android SDK Build-Tools 25.0.1 not accepted.
Checking the license for package Android SDK Platform 25 in /home/user/.android/licenses
Warning: License for package Android SDK Platform 25 not accepted.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Build-Tools 25.0.1, 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

I did more reading and since it somehow looks like it could be a permission issue, I checked that /home/user/.android belongs to the current user and has rwx access rights for the current user.
Removing the directory /home/user/.android lead to its re-creation but writing the license file failed again.
Also using the commented out version of ANDROID_HOME showed the same error.

Not setting ANDROID_HOME leads to an error that says that the SDK could not be found and the variable should be set.

Hey,

I don’t have time to look in detail, but I use the following:

{ pkgs ? import <nixpkgs> { config.android_sdk.accept_license = true; } }:

pkgs.androidenv.buildApp {
  name = "Alarmio";
  platformVersions = [ "28" ];
}

This didn’t work fully though: I remember have to pull a dirty hack because gradle downloaded a binary and executed it without first patchelf’ing.

@raboof thanks for the example.

Unfortunately, I can not use this method, since I try to compile a react-native app, that has its own build tooling.
To compile, you have to run npx react-native-cli run-android which I have not looked into what it is doing internally.

Anyone else having ideas on this topic?
Otherwise there doesn’t seem to be a way for me to build a react-native Android apps on Nixos.

found this thread when i was looking to fix it for myself

  pkgs = import <nixpkgs> { config.android_sdk.accept_license = true; };

solves it for me.

Still doesn’t work for me, have spent a few hours on this now. I’m trying to use cordova instead of react, and the default accept license config does nothing.

3 Likes