Using androidenv, error: 'functionArgs' requires a function

I have a small android application (made with gradle) and would like to build and test it in gitlab CI. Many other components are built with Nix already, so it’s okay to use Nix for that. The documentation suggests pkgs.androidenv.buildApp, but I cannot figure out how to use it correctly. I am trying the following flake:

{
  description = "example";
  inputs.nixpkgs.url = "nixpkgs/nixos-23.05";
  outputs = { self, nixpkgs }: {
    packages.x86_64-linux.default = let
        pkgs = import nixpkgs {
          system = "x86_64-linux";
          config.android_sdk.accept_license = true;
          config.allowUnfree = true;
        };
        androidenv = pkgs.androidenv;
    in androidenv.buildApp {
      name = "example watches";
      src = ./app;
      platformVersion = [ "28" ];
    };
  };
}

nix build fails fast with a message:

error: 'functionArgs' requires a function

       at /nix/store/93i8f7404djndcryp55cvpcydjgbnxhg-source/pkgs/development/mobile/androidenv/build-app.nix:12:26:

           11| let
           12|   androidSdkFormalArgs = builtins.functionArgs composeAndroidPackages;
             |                          ^
           13|   androidArgs = builtins.intersectAttrs androidSdkFormalArgs args;

What am I missing?

I would be also glad to see a complete example, it’s hard to find such one.

Maybe I broke this in https://github.com/nixos/nixpkgs/commit/a2f85e0fa8d22a8ab42173344ce8a96b028e018a
Looking in to it…

@SergeK already made a PR fixing it but i missed it androidenv.buildApp: make it work with the overridable composeAndroidPackages by SomeoneSerge · Pull Request #224415 · NixOS/nixpkgs · GitHub Will merge

1 Like

Thank you, using the master branch (with this PR being merged) of nixpkgs I can at least to evaluate nix expression and begin a build.

The build fails with a message Buildfile: build.xml does not exist!. It’s true, there is only build.gradle, proguard-rules.pro and src/ in the app folder.
Could you help, is it possible to build gradle-based project with Nix at all?

It should be possible somehow, but i do not use androidenv.

I found that we used to have androidenv.buildGradleApp init androidenv.buildGradleApp by matthewbauer · Pull Request #41855 · NixOS/nixpkgs · GitHub
but it was removed in Mobile updates by svanderburg · Pull Request #50596 · NixOS/nixpkgs · GitHub which has
Readd androidenv.buildGradleApp in Still to do:

perhaps we could readd it using https://github.com/reflex-frp/reflex-platform/blob/7e35474f01e70500ea5c0d903a4e7df92068aee6/android/build-gradle-app.nix (which was where the original implementation was from) as a base

Please test android.env.buildGradleApp: Reinit by Artturin · Pull Request #254082 · NixOS/nixpkgs · GitHub

Still cannot make it working, gradle starts and fails with

...
* What went wrong:
Plugin [id: 'com.android.application'] was not found in any of the following sources:
...

build.gradle of my application does really contain com.android.application in the list of plugins, but idk how to enable it inside a Nix. (And I had never have a deal with gradle and building android applications until this case…)