Android: Difference between revisions
BurntVoxel (talk | contribs) →Android Studio: Added a note about how to indicate accepting the license, apparently that has to be in the config file. |
m Add category development |
||
| (6 intermediate revisions by 5 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. | |||
{{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> | 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 93: | Line 96: | ||
<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 123: | ||
<syntaxhighlight lang=console> | <syntaxhighlight lang=console> | ||
$ nix-shell -p androidenv.androidPkgs.platform-tools | |||
$ nix-shell -p androidenv. | |||
% adb connect 192.168.1.10 | % adb connect 192.168.1.10 | ||
% adb shell | % adb shell | ||
| Line 145: | Line 151: | ||
nixpkgs.config.android_sdk.accept_license = true; | nixpkgs.config.android_sdk.accept_license = true; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
To use the Android Emulator, you need to enable KVM virtualization (in your BIOS) and make sure your user has permission to use KVM (add yourself to the <code>kvm</code> group). | |||
=== gradlew === | === gradlew === | ||
| Line 157: | Line 165: | ||
targetPkgs = pkgs: (with pkgs; | targetPkgs = pkgs: (with pkgs; | ||
[ | [ | ||
androidenv. | androidenv.androidPkgs.androidsdk | ||
glibc | glibc | ||
]); | ]); | ||
| Line 170: | Line 178: | ||
let | let | ||
androidSdk = pkgs.androidenv. | androidSdk = pkgs.androidenv.androidPkgs.androidsdk; | ||
in | in | ||
pkgs.mkShell { | pkgs.mkShell { | ||
| Line 186: | Line 194: | ||
=== Building Android on NixOS === | === Building Android on NixOS === | ||
It's possible to use nix-shell with | It's possible to use nix-shell with buildFHSEnv 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. | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ pkgs ? import <nixpkgs> {} }: | { pkgs ? import <nixpkgs> {} }: | ||
let fhs = pkgs. | let fhs = pkgs.buildFHSEnv { | ||
name = "android-env"; | name = "android-env"; | ||
targetPkgs = pkgs: with pkgs; | targetPkgs = pkgs: with pkgs; | ||
| Line 203: | Line 211: | ||
gnumake | gnumake | ||
nettools | nettools | ||
androidenv. | androidenv.androidPkgs.platform-tools | ||
jdk | jdk | ||
schedtool | schedtool | ||
| Line 239: | Line 247: | ||
=== Android Debug Bridge === | === Android Debug Bridge === | ||
Run <code>nix-shell -p usbutils --run "lsusb"</code> on your terminal to get the list of USB devices connected to your computer. Sample output:<pre> | |||
... | |||
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub | |||
Bus 002 Device 007: ID 0fce:320d Sony Ericsson Mobile Communications AB Xperia 5 III | |||
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub | |||
... | |||
</pre> | |||
<code>ID 0fce:320d</code> can be seen as: <code>idVendor = 0fce</code> and <code>idProduct = 320d</code>. | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | { | ||
programs.adb.enable = true; | programs.adb.enable = true; | ||
services.udev.extraRules = | services.udev.extraRules = | ||
# | let | ||
SUBSYSTEM=="usb", ATTR{idVendor}==" | # nix-shell -p usbutils --run "lsusb" | ||
idVendor = "0fce"; # Change according to the guide above | |||
idProduct = "320d"; # Change according to the guide above | |||
in | |||
'' | |||
SUBSYSTEM=="usb", ATTR{idVendor}=="${idVendor}", MODE="[]", GROUP="adbusers", TAG+="uaccess" | |||
SUBSYSTEM=="usb", ATTR{idVendor}=="${idVendor}", ATTR{idProduct}=="${idProduct}", SYMLINK+="android_adb" | |||
SUBSYSTEM=="usb", ATTR{idVendor}=="${idVendor}", ATTR{idProduct}=="${idProduct}", SYMLINK+="android_fastboot" | |||
''; | |||
# add user to adbusers group | # add user to adbusers group | ||
| Line 257: | Line 280: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
# [https://nixos.org/nix-dev/2015-April/016881.html more information on that snippet] | # [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://gist.github.com/Nadrieril/d006c0d9784ba7eff0b092796d78eb2a A shell.nix to build LineageOS] | ||
| Line 262: | Line 286: | ||
# [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]] | |||