Android: Difference between revisions

buildFHSUserEnv → buildFHSEnv
Axka (talk | contribs)
Tags: Mobile edit Mobile web edit Visual edit
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== Using the Android SDK ==
== Using the Android SDK ==
NixOS uses the androidenv package for building android SDKs and manually creating emulators without the use of Android Studio. Example android sdk is <code>androidenv.androidPkgs_9_0.androidsdk</code>. They also include all of the SDK tools such as sdkmanager and avdmanager needed to create emulators.
 
{{Note|<code><small>androidenv.androidPkgs_9_0</small></code> has been replaced with <code><u><small>androidenv.androidPkgs</small></u></code> in nixos 24.11, see [https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2411.section.md#backward-incompatibilities-sec-release-2411-incompatibilities backward-incompatibilities-sec-release-2411-incompatibilities], so all the <code><small>androidPkgs_9_0</small></code> references below need be changed after 24.11 gets released.}}
NixOS uses the androidenv package for building android SDKs and manually creating emulators without the use of Android Studio. Example android sdk is <code>androidenv.androidPkgs.androidsdk</code>. They also include all of the SDK tools such as sdkmanager and avdmanager needed to create emulators.
 
{{Note|<code><small>androidenv.androidPkgs_9_0</small></code> has been replaced with <code><u><small>androidenv.androidPkgs</small></u></code> in nixos 24.11, see [https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2411.section.md#backward-incompatibilities-sec-release-2411-incompatibilities backward-incompatibilities-sec-release-2411-incompatibilities], so all the <code><small>androidPkgs</small></code> references below will be androidPkgs_9_0 if you are still using 24.05 or below.}}
 
The first link provides a guide for creating a custom android SDK, using a predefined SDK, and how to nixify an emulator. The second link is an extra guide that might have some helpful tips for improving your workflow.  
The first link provides a guide for creating a custom android SDK, using a predefined SDK, and how to nixify an emulator. The second link is an extra guide that might have some helpful tips for improving your workflow.  
# [https://nixos.org/manual/nixpkgs/unstable/#android Official Android SDK guide from NixOS.org]  
# [https://nixos.org/manual/nixpkgs/unstable/#android Official Android SDK guide from NixOS.org]  
Line 33: Line 36:
</syntaxhighlight>
</syntaxhighlight>


== adb setup ==
== 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>
 
This will add [https://github.com/M0Rf30/android-udev-rules additional udev rules] for unprivileged access as well as add adb to your <code>$PATH</code>.


Alternatively, if you don't want to install adb globally but do want to configure the udev rules, you can:
To use <code>adb</code>, you can just [[Adding programs to PATH|run it from]] the <code>android-tools</code> package.


<syntaxhighlight lang=nix>
{{Note|1=Previously you would need use <code>programs.adb.enable = true;</code> and <code>users.users.<your-user>.extraGroups = [ "adbusers" ];</code> to add ADB to your PATH and configure access rules. This option is no longer needed as systemd 258 handles uaccess rules for ADB and fastboot automatically. See the Nixpkgs pull request {{pull|454366}}.}}
{
  services.udev.packages = [
    pkgs.android-udev-rules
  ];
}
</syntaxhighlight>


=== Use Older Platform Version ===
=== Use Older Platform Version ===
Line 93: Line 77:


<syntaxhighlight lang=console>
<syntaxhighlight lang=console>
$ # For nixos < 19.03
$ # nix-shell -p androidenv.platformTools
$ # for nixos <= 24.05
$ nix-shell -p androidenv.androidPkgs_9_0.platform-tools
$ # For nixos >= 24.11
$ nix-shell -p androidenv.androidPkgs.platform-tools
$ nix-shell -p androidenv.androidPkgs.platform-tools
% adb devices
% adb devices
Line 115: Line 104:


<syntaxhighlight lang=console>
<syntaxhighlight lang=console>
$ # For nixos < 19.03
$ nix-shell -p androidenv.androidPkgs.platform-tools
$ # nix-shell -p androidenv.platformTools
$ nix-shell -p androidenv.androidPkgs_9_0.platform-tools
% adb connect 192.168.1.10
% adb connect 192.168.1.10
% adb shell
% adb shell
Line 159: Line 146:
   targetPkgs = pkgs: (with pkgs;
   targetPkgs = pkgs: (with pkgs;
     [
     [
       androidenv.androidPkgs_9_0.androidsdk
       androidenv.androidPkgs.androidsdk
       glibc
       glibc
     ]);
     ]);
Line 172: Line 159:


let
let
   androidSdk = pkgs.androidenv.androidPkgs_9_0.androidsdk;
   androidSdk = pkgs.androidenv.androidPkgs.androidsdk;
in
in
pkgs.mkShell {
pkgs.mkShell {
Line 205: Line 192:
       gnumake
       gnumake
       nettools
       nettools
       androidenv.androidPkgs_9_0.platform-tools
       androidenv.androidPkgs.platform-tools
       jdk
       jdk
       schedtool
       schedtool
Line 280: Line 267:
# [https://github.com/mrVanDalo/LineagoOS-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.
# [https://github.com/mrVanDalo/LineagoOS-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.
# [https://wiki.archlinux.org/title/Android_Debug_Bridge Archlinux Wiki to Android_Debug_Bridge]
# [https://wiki.archlinux.org/title/Android_Debug_Bridge Archlinux Wiki to Android_Debug_Bridge]
[[Category:Development]]