Android: Difference between revisions
imported>Raboof |
imported>Charlycoste Seems that androidenv.platformTools is not available anymore |
||
Line 95: | Line 95: | ||
gnumake | gnumake | ||
nettools | nettools | ||
androidenv.platformTools | # For nixos < 19.03, use `androidenv.platformTools` | ||
androidenv.androidPkgs_9_0.platform-tools | |||
jdk | jdk | ||
schedtool | schedtool |
Revision as of 13:24, 22 April 2020
adb setup
To enable adb
in NixOS for unprivileged users
add these lines to your configuration.nix
.
This is mandatory for all further interactions with your android device.
{
programs.adb.enable = true;
users.users.<your-user>.extraGroups = ["adbusers"];
}
This will add additional udev rules for unprivileged access as well as add adb to your $PATH
.
Alternatively, if you don't want to install adb globally but do want to configure the udev rules, you can:
{
services.udev.packages = [
pkgs.android-udev-rules
];
}
Interaction with your Android device
adb shell on device
First open a nix-shell with the platform tools and connect your device:
$ # For nixos < 19.03
$ # nix-shell -p androidenv.platformTools
$ nix-shell -p androidenv.androidPkgs_9_0.platform-tools
% adb devices
List of devices attached
* daemon not running; starting now at tcp:5037
* daemon started successfully
BH90272JCU unauthorized
A popup appears on your phone to allow your computer access to it. After allowing, you can:
% adb devices
List of devices attached
BH90272JCU device
% adb shell
You can also connect to an already-running adb server:
$ # For nixos < 19.03
$ # nix-shell -p androidenv.platformTools
$ nix-shell -p androidenv.androidPkgs_9_0.platform-tools
% adb connect 192.168.1.10
% adb shell
Transferring files from/to an Android device
There are two main methods for newer devices:
adb push
andadb pull
: see above.- via MTP, see the corresponding page
Android Development
Android Studio
To develop apps using Android Studio
$ nix-shell -p android-studio --run android-studio
Building Android on NixOS
It's possible to use nix-shell with buildFHSUserEnv to set up an environment in which it's viable to build Android without huge amounts of editing. This is an example shell.nix file.
{ pkgs ? import <nixpkgs> {} }:
let fhs = pkgs.buildFHSUserEnv {
name = "android-env";
targetPkgs = pkgs: with pkgs;
[ git
gitRepo
gnupg
python2
curl
procps
openssl
gnumake
nettools
# For nixos < 19.03, use `androidenv.platformTools`
androidenv.androidPkgs_9_0.platform-tools
jdk
schedtool
utillinux
m4
gperf
perl
libxml2
zip
unzip
bison
flex
lzop
];
multiPkgs = pkgs: with pkgs;
[ zlib
];
runScript = "bash";
profile = ''
export USE_CCACHE=1
export ANDROID_JAVA_HOME=${pkgs.jdk.home}
'';
};
in pkgs.stdenv.mkDerivation {
name = "android-env-shell";
nativeBuildInputs = [ fhs ];
shellHook = "exec android-env";
}
- more information on that snippet
- A shell.nix to build LineageOS
- NixDroid, building aosp roms (e.g. LineageOS) with nix. ( not very well documented and requires patches to nix )
- LineageOS build setup using terranix and hcloud, based on the shell.nix to build LineageOS. Useful if you are in a rush and don't have to much CPU power on your hand.
Using the nixpkgs androidenv
User Sander van der Burg created two awesome blog posts as well as a number of test cases usable as examples on how to use the nixpkgs androidenv and the emulator provideded: