Android: Difference between revisions
imported>Mickours update for last stable |
imported>MrVanDalo a bit of restructoring and I add a link to my lineage os cloud build setup |
||
Line 1: | Line 1: | ||
=== | |||
== adb setup == | |||
To enable <code>adb</code> in NixOS for unprivileged users | |||
add these lines to your <code>configuration.nix</code>. | |||
This is mandatory for all further interactions with your android device. | |||
<syntaxhighlight lang=nix> | |||
{ | |||
programs.adb.enable = true; | |||
users.users.<your-user>.extraGroups = ["adbusers"]; | |||
} | |||
</syntaxhighlight> | |||
== Interaction with your Android device == | |||
=== adb shell on device === | |||
<syntaxhighlight lang=console> | <syntaxhighlight lang=console> | ||
$ # For nixos < 19.03 | $ # For nixos < 19.03 | ||
Line 8: | Line 26: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== | === Transferring files from/to an Android device === | ||
There are two main methods for newer devices: | There are two main methods for newer devices: | ||
* <code>adb push</code> and <code>adb pull</code>: see above. | * <code>adb push</code> and <code>adb pull</code>: see above. | ||
* via [[MTP]], see [[MTP|the corresponding page]] | * via [[MTP]], see [[MTP|the corresponding page]] | ||
== | == Android Development == | ||
=== Android Studio === | |||
.. | To develop apps using [https://developer.android.com/studio/ Android Studio] | ||
<syntaxhighlight lang=console> | <syntaxhighlight lang=console> | ||
$ nix-shell -p android-studio --run android-studio | $ nix-shell -p android-studio --run android-studio | ||
Line 82: | Line 92: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[https://nixos.org/nix-dev/2015-April/016881.html | # [https://nixos.org/nix-dev/2015-April/016881.html more information on that snippet] | ||
# [https://gist.github.com/Nadrieril/d006c0d9784ba7eff0b092796d78eb2a A shell.nix to build LineageOS] | |||
# [https://github.com/ajs124/NixDroid NixDroid], building aosp roms (e.g. LineageOS) with nix. ( not very well documented and requires patches to nix ) | |||
# [https://github.com/mrVanDalo/LineagoaOS-build LineageOS build setup using terranix and hcloud], based on the [https://gist.github.com/Nadrieril/d006c0d9784ba7eff0b092796d78eb2a 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: | 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: | ||
# [https://sandervanderburg.blogspot.de/2012/11/building-android-applications-with-nix.html Building Android applications with the Nix package manager ] | # [https://sandervanderburg.blogspot.de/2012/11/building-android-applications-with-nix.html Building Android applications with the Nix package manager ] | ||
# [https://sandervanderburg.blogspot.de/2014/02/reproducing-android-app-deployments-or.html Reproducing Android app deployments (or playing Angry Birds on NixOS)] | # [https://sandervanderburg.blogspot.de/2014/02/reproducing-android-app-deployments-or.html Reproducing Android app deployments (or playing Angry Birds on NixOS)] | ||
# [https://github.com/svanderburg/nix-androidenvtests A set of androidenv test cases] | # [https://github.com/svanderburg/nix-androidenvtests A set of androidenv test cases] |
Revision as of 07:31, 23 December 2019
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"];
}
Interaction with your Android device
adb shell on device
$ # 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
androidenv.platformTools
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: