Android

Synchronization

There are various applications to transfer files, synchronize notifications and more.

All-in-one

  • KDE Connect (kdeconnect) – integrates your Android device with the KDE or Gnome desktop (featuring synced notifications & clipboard, multimedia control, and file/URL sharing).

Synchronized notifications

  • a2lnAUR – provides notification synchronization over LAN featuring authentication, encryption and more

Transferring files

App development

The officially supported way to build Android apps is to use #Android Studio.

Android Studio

Android Studio is the official Android development environment based on IntelliJ IDEA. It provides integrated Android developer tools for development and debugging.

You can install it with the android-studioAUR package.

Android Studio creates a .android directory in home directory. To reset Android Studio, this directory can be removed.

Note:

The Android Studio Setup Wizard installs the required #SDK packages and places the SDK by default in .

To build apps from the command-line (using e.g. ) set the ANDROID_HOME environment variable to your SDK location.

SDK packages

Android SDK packages can be installed directly from upstream using #Android Studio's SDK Manager or the sdkmanager command line tool (part of the Android SDK Tools). Some Android SDK packages are also available as AUR packages, they generally install to .

The required SDK packages are:

Android SDK PackageSDK-style pathAUR packageAUR dummyCLI tools
Command-Line Toolstoolsandroid-sdk-cmdline-tools-latest-dummyAURapkanalyzer, avdmanager, lint, retrace, screenshot2, sdkmanager
SDK Build-Toolsbuild-tools;versionaapt, aapt2, aidl, apksigner, bcc_compat, d8, dexdump, dx, lld, llvm-rs-cc, mainDexClases, split-select, zipalign
SDK Platform-Toolsplatform-toolsadb, dmtracedump, e2fsdroid, etc1tool, #fastboot, hprof-conv, make_f2fs, make_f2fs_casefold, mke2fs, sload_f2fs, sqlite3, systrace
SDK Platformplatforms;android-level, older versionsandroid-platform-dummyAUR (unnecessary)

The package provides adb, #fastboot, and from the SDK Platform-Tools along with mkbootimg and .

Android Emulator

The Android Emulator is available as the SDK package, the package, and there is also a dummy package for it: .

To run the Android Emulator you need an Intel or ARM System Image. You can install them through the AUR, with the sdkmanager or using Android Studio's AVD Manager.

Other SDK packages in the AUR

The Android Support Library is now available online from Google's Maven repository. You can also install it offline through the SDK package (also available as android-support-repositoryAUR).

Making /opt/android-sdk group-writeable

The AUR packages install the SDK in . This directory has root permissions, so keep in mind to run sdk manager as root. If you intend to use it as a regular user, create the android-sdk users group, add your user.

# groupadd android-sdk
# gpasswd -a <user> android-sdk

Set an access control list to let members of the newly created group write into the android-sdk folder. As running sdkmanager can also create new files, set the ACL as default ACL. the X in the default group entry means "allow execution if executable by the owner (or anyone else)"

# setfacl -R -m g:android-sdk:rwx /opt/android-sdk
# setfacl -d -m g:android-sdk:rwX /opt/android-sdk  

Re-login or as <user> log your terminal in to the newly created group:

$ newgrp android-sdk

Other IDEs

Android Studio is the official Android development environment based on IntelliJ IDEA. Alternatively, you can use Netbeans with the NBAndroid-V2. All are described below.

Netbeans

If you prefer using Netbeans as your IDE and want to develop Android applications, use NBAndroid-V2 .

Install package and follow the instructions from the NBANDROID README.

Vim / Neovim

It is possible to write applications for Android and iOS using (Neo)vim like an IDE. Install coc using a Vim plugin manager. Also install the coc-flutter extension for autocompletion (like in Android Studio) and to load the code into an Android emulator.

Emacs

To develop a mobile application using Emacs, as the the official instruction at flutter.dev suggests, install lsp-dart.

Marvin

Marvin is a tool which helps beginners set up an Android development environment. Installing marvin_dscAUR helps you set up the following things: JDK, Android SDK, IDE(s), and AVD.

Building

Please note that these instructions are based on the official AOSP build instructions. Other Android-derived systems such as LineageOS will often require extra steps.

Required packages

To build either AOSP 10 or LineageOS 17.1 you need a TTF font installed (e.g. ) and the dependencies of the metapackage.

Additionally, LineageOS requires the following dependencies of the metapackage.

Note: Installing both maven and gradle to build LineageOS may result in a build speed improvement as the build process will prefer the system's.

Java Development Kit

The required JDK version depends on the Android version you are building:

  • For Android 9 (Pie) and up, Java is included with the Android source and no separate installation is needed.
  • For Android 7 and 8 (Nougat and Oreo), OpenJDK 8 is required, which is available with the package.

Setting up the build environment

Install the package.

Create a directory to build.

$ mkdir ~/android
$ cd ~/android

The Android build process expects python to be python2. Prepend it to the :

$ mkdir bin
$ ln -s /bin/python2 bin/python
$ export PATH=$PWD/bin:$PATH

Alternatively, create a python2 virtual environment and activate it:

$ virtualenv2 --system-site-packages venv
$ source venv/bin/activate

Downloading the source code

This will clone the repositories. You only need to do this the first time you build Android, or if you want to switch branches.

  • The has a switch that operates similarly to the one used with . Since it controls the number of simultaneous downloads, you should adjust the value depending on downstream network bandwidth.
  • You will need to specify a branch (list of branches) to check out with the switch. If you leave the switch out, you will get the so-called master branch.
$ repo init -u https://android.googlesource.com/platform/manifest -b master
$ repo sync -j4

Wait a long time. Just the uncompiled source code, along with the and directories that are used to keep track of it, are very large. As of Android 10, at least 250 GB of free disk space is required.

Note: If you want to update your local copy of the Android source, at a later time, simply enter the build directory, load the Virtualenv, and re-sync:
$ repo sync

Building the code

This should do what you need for AOSP:

$ source build/envsetup.sh
$ lunch full-eng
$ make -j4

If you run lunch without arguments, it will ask what build you want to create. Use -j with a number between one and two times number of cores/threads.

The build takes a very long time.

Testing the build

When finished, run/test the final image(s).

$ emulator

Creating a flashable Image

To create an image that can be flashed it is necessary to:

make -j8 updatepackage

This will create a zip image under (hammerhead being the device name) that can be flashed.

Flashing

In some cases, you want to return to the stock Android after flashing custom ROMs to your Android mobile device. For flashing instructions of your device, please use XDA forums.

Fastboot

Fastboot (as well as ADB) is included in the package.

Samsung devices

Samsung devices cannot be flashed using Fastboot tool. Alternatives are Heimdall and Odin (by using Windows and VirtualBox).

samloader

To download original Samsung firmware, a platform independent script, samloader can be used.

Heimdall

Heimdall is a cross-platform open-source tool suite used to flash firmware (also known as ROMs) onto Samsung mobile devices and is also known as an alternative to Odin. It can be installed as .

The flashing instructions can be found on Heimdall's GitHub repository or on XDA forums.

Odin (Virtualbox)

It is also possible to restore firmware (Android) on the Samsung devices using Odin, but inside the VirtualBox.

Arch Linux (host) preparation:

  1. Install VirtualBox together with its extension pack and guest additions.
  2. Install your preferred, but compatible with Odin, Windows operating system (with VirtualBox guest additions) into a virtual hard drive using VirtualBox.
  3. Open VirtualBox settings of your Windows operating system, navigate to USB, then tick (or make sure it is ticked) Enable USB 2.0 (EHCI) Controller.
  4. At VirtualBox running Windows operating system, click in the menu bar Devices > USB Devices, then click on your Samsung mobile device from the list, which is connected to your computer via USB.

Windows (guest) preparation:

  1. Install Samsung drivers.
  2. Install Odin.
  3. Download required Samsung firmware (Android) for your smartphone model.

Check if configuration is working:

  1. Turn your device into Download mode and connect to your Linux machine.
  2. In virtual machine toolbar, select Devices > USB > ...Samsung... device.
  3. Open Odin. The white box (a big one at the bottom-left side) named Message, should print a line similar to this:
<ID:0/003> Added!!

which means that your device is visible to Odin & Windows operating system and is ready to be flashed.

Run Android apps on Arch Linux

There are several projects and methods which support running Android on Arch Linux (or other distributions). As listed below:

  • Container-based solutions tend to be the most popular. They are the closest you can get to run Android app natively on a non-Android Linux kernel. They tend to be the best integrated with your system and have good performance. Notable ones are:
    • Anbox is probably the most famous android container solution for Linux. It runs an Android 7.1 image based on Lineageos and is completely open source.
    • Waydroid is a fork of Anbox, and it is gaining popularity. It is more performant, because it runs closer to the hardware. It is based on a newer Lineageos 17.1 (Android 10) based image with the option to install the Google Play Store and other Open Gapps. Beside running apps in standalone windows, it can also run a full Android UI.
  • There are also a few Chromium extensions that can run android apps:
    • Arc Welder was an extension by google to test how apps would run on Chrome OS, but is now discontinued.
    • ARChon is an open source extension to run android apps on Chomium-based browsers.
  • Of course it is also possible to run a full android emulator. One upside to this is that you can run arm apps on x86. A downside is worse performance. Examples are:
Tip: If you just want to be able to use Android apps on x86 and do not mind a separate OS you can also use Android-x86: a direct port of Android for the x86 architecture.

Troubleshooting

Android Studio: Android Virtual Devices show 'failed to load'.

Make sure you have exported the variable as explained in #Android Studio.

Android Studio: 'failed to create the SD card'

If you try to run an AVD (Android Virtual Device) under x86_64 Arch and get the error above, install the package from the multilib repository.

Eclipse: During Debugging "Source not found"

Most probably the debugger wants to step into the Java code. As the source code of Android does not come with the Android SDK, this leads to an error. The best solution is to use step filters to not jump into the Java source code. Step filters are not activated by default. To activate them: Window > Preferences > Java > Debug > Step Filtering. Consider to select them all. If appropriate you can add the android.* package. See Use Step Filters.

ValueError: unsupported pickle protocol

One fix is to issue:

$ rm ~/.repopickle_.gitconfig

If that does not work, then try this:

$ find /path/to/android-root -name .repopickle_config -delete

libGL error: failed to load driver: swrast OR AVD does not load and no error message displayed

Sometimes, beginning to load an AVD will cause an error message similar to this to be displayed, or the loading process will appear to finish but no AVD will load and no error message will be displayed.

The AVD loads an incorrect version of libstdc++, you can remove the folder libstdc++ from (for 64-bit) or (for 32-bit) , e.g.:

$ rm -r ~/.android-sdk/emulator/lib64/libstdc++

Note that in versions before Android Studio 3.0, this directory was in a different location:

$ rm -r ~/Android/Sdk/emulator/lib64/libstdc++

Alternatively you can set and export ANDROID_EMULATOR_USE_SYSTEM_LIBS in ~/.profile as:

export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1

Reference: Android Studio user guide

Fix for the .desktop file might be achieved by using env command, prefixing the Exec line Desktop entries#Modify environment variables

env ANDROID_EMULATOR_USE_SYSTEM_LIBS=1

sh: glxinfo: command not found

Here is the full error:

Cannot launch AVD in emulator.
Output:
sh: glxinfo: command not found
sh: glxinfo: command not found
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  154 (GLX)
  Minor opcode of failed request:  24 (X_GLXCreateNewContext)
  Value in failed request:  0x0
  Serial number of failed request:  32
  Current serial number in output stream:  33
QObject::~QObject: Timers cannot be stopped from another thread

You can try to install glxinfo (mesa-utils) but if your computer has enough power you could simply use software to render graphics. To do so, go to Tools > Android > AVD Manager, edit the AVD (click the pencil icon), then select Software - GLES 2.0 for Emulated Performance > Graphics.

Android Emulator: no keyboard input in xfwm4

In xfwm4, the vertical toolbar buttons window that is on the right of the emulator takes focus from the emulator and consumes keyboard events. (bug report)

You can use the workaround described in :

  1. Open the xfwm4 settings.
  2. Switch to the Focus tab.
  3. Change the Focus Model to "Focus follow mouse".
  4. Disable Automatically raise windows when they receive focus option below.\

Android Emulator: Window is shaking and blinking when used in WM tiled mode

When using Tiled Window Manager like dwm, Android Emulator will shake and blink. You can use the workaround described in krohnkite issue 72 (window floating is induced by in dwm).

Android Emulator: Segmentation fault (core dumped)

When using Nouveau drivers try to disable gpu hardware acceleration.

In some devices it can only be done by editing .

  1. Set
  2. Set

adb: sideload connection failed: insufficient permissions for device

If you get the errors:

adb: sideload connection failed: insufficient permissions for device
See [https://developer.android.com/tools/device.html] for more information

or

adb: trying pre-KitKat sideload method...
adb: pre-KitKat sideload connection failed: insufficient permissions for device
See [https://developer.android.com/tools/device.html] for more information

You might be able to solve it by restarting the adb server:

 $ adb kill-server
 # adb start-server

Alternatively, make sure you have installed the Android udev rules. See #Fastboot.

gollark: There's a "foes vanquished" counter on the points page too.
gollark: Yeeees.
gollark: Also, got ideas for games to install on the offline page?
gollark: Aidan is working slowly on Emu War Online (multiplayer) which is currently a bizarre Haskell program.
gollark: But then you don't vanquish many foes.
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.