Android
Related articles
Contents
- 1 Exploring Android device
- 2 Android development
- 3 Building Android
- 4 Restoring Android
- 5 Alternative connection methods
- 6 Tips & Tricks
- 7 Troubleshooting
Exploring Android device
There are few methods of exploring your device:
- MTP over USB for files transferring.
- Alternative methods (such as FTP, SSH).
For more advanced usage, development, flashing and restore:
- ADB mostly for development purposes.
- Restoring Android for flashing and restoring Android firmwares (includes fastboot).
Android development
There are 3 steps that need to be performed before you can develop Android applications on your Arch Linux box:
- Install the Android SDK core component,
- Install one or several Android SDK Platform packages,
- Install one of the IDEs compatible with the Android SDK.
Android SDK core components
Before developing Android applications, you need to install the Android SDK, which is made of 3 distinct packages, all installable from AUR:
Android-sdk will be installed on /opt/android-sdk
. This folder has root permissions, so keep in mind to run sdk manager as root, otherwise you will not be able to install/update/modify anything on /opt/android-sdk. However, if you intend to use it as a regular user, create an android sdk users group (or use any group name you want):
# groupadd sdkusers
Add your user into this group:
# gpasswd -a <user> sdkusers
Change folder's group.
# chown -R :sdkusers /opt/android-sdk/
Change permissions of the folder so the user that was just added to the group will be able to write in it:
# chmod -R g+w /opt/android-sdk/
Android SDK platform API
Install the desired Android SDK Platform package from the AUR:
- android-platformAUR (latest)
- android-platform-22AUR
- android-platform-21AUR
- android-platform-20AUR
- android-platform-19AUR
- android-platform-18AUR
- android-platform-17AUR
- android-platform-16AUR
- android-platform-15AUR
- android-platform-14AUR
- android-platform-13AUR
- android-platform-12AUR
- android-platform-11AUR
- android-platform-10AUR
- android-platform-9AUR
- android-platform-8AUR
- android-platform-7AUR
- android-platform-6AUR
- android-platform-5AUR
- android-platform-4AUR
- android-platform-3AUR
- android-platform-2AUR
Development environment
Android Studio is the new official Android development environment based on IntelliJ IDEA. Alternatively, you can use Eclipse with the official but deprecated ADT plugin, or Netbeans with the NBAndroid plugin. All are described below.
Android Studio
Android Studio is the official Android development environment based on IntelliJ Idea. Android Studio replaces the older Eclipse Android Developer Tools and provides integrated Android developer tools for development and debugging.
You can download and install it with the android-studioAUR package from the AUR. If you get an error about a missing SDK, refer to the section Getting Android SDK platform API above.
Normally, apps are built through the Android Studio GUI. To build apps from the commandline (using e.g. ./gradlew assembleDebug
), add the following to your ~/.bashrc
:
export ANDROID_HOME=/opt/android-sdk
Eclipse
Most stuff required for Android development in Eclipse is already packaged in AUR:
Official plugin by Google – Eclipse ADT:
Dependencies:
- eclipse-emfAUR
- eclipse-gefAUR
- eclipse-wtpAUR
Enter the path to the Android SDK Location in
Windows -> Preferences -> Android
Netbeans
If you prefer using Netbeans as your IDE and want to develop Android applications, download the NBAndroid by going to:
Tools -> Plugins -> Settings
Add the following URL: http://nbandroid.org/updates/updates.xml
Then go to Available Plugins and install the Android and JUnit plugins. Once you have installed go to:
Tools -> Options -> Miscellaneous -> Android
and select the path where the SDK is installed (/opt/android-sdk by default). That is it, now you can create a new Android project and start developing using Netbeans.
Connecting to a real device - Android Debug Bridge (ADB)
To get ADB to connect to a real device or phone under Arch, you must:
- Install android-tools.
- Enable USB Debugging on your phone or device:
- Jelly Bean (4.2) and newer: Go to
Settings --> About Phone
tap “Build Number” until you get a popup that you have become a developer (about 10 times). Then go toSettings --> Developer --> USB debugging
and enable it. - Older versions: This is usually done from
Settings --> Applications --> Development --> USB debugging
. Reboot the phone after checking this option to make sure USB debugging is enabled.
- Jelly Bean (4.2) and newer: Go to
- install android-udev to connect the device to the proper
/dev/
entries. - Add yourself to the adbusers group. (
gpasswd -a username adbusers
)
If ADB recognizes your device (it is visible and accessible in IDE), you are done. Otherwise see instructions below.
Figure out device IDs
Each Android device has a USB vendor/product ID. An example for HTC Evo is:
vendor id: 0bb4 product id: 0c8d
Plug in your device and execute:
$ lsusb
It should come up something like this:
Bus 002 Device 006: ID 0bb4:0c8d High Tech Computer Corp.
Adding udev Rules
Use the rules from Android developer or you can use the following template for your udev rules, just replace [VENDOR ID] and [PRODUCT ID] with yours. Copy these rules into /etc/udev/rules.d/51-android.rules
:
/etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="[VENDOR ID]", MODE="0666", GROUP="adbusers" SUBSYSTEM=="usb",ATTR{idVendor}=="[VENDOR ID]",ATTR{idProduct}=="[PRODUCT ID]",SYMLINK+="android_adb" SUBSYSTEM=="usb",ATTR{idVendor}=="[VENDOR ID]",ATTR{idProduct}=="[PRODUCT ID]",SYMLINK+="android_fastboot"
Then, to reload your new udev rules, execute:
# udevadm control --reload-rules
Configuring adb
Instead of using udev rules, you may create/edit ~/.android/adb_usb.ini
which contains a list of vendor IDs.
$ cat ~/.android/adb_usb.ini 0x27e8
Does it work?
After you have setup the udev rules, unplug your device and replug it.
After running:
$ adb devices
you should see something like:
List of devices attached HT07VHL00676 device
You can now use adb to transfer files between the device and your computer. To transfer files to the device, use
$ adb push <what-to-copy> <where-to-place>
To transfer files from the device, use
$ adb pull <what-to-pull> <where-to-place>
If you do not have the adb program, it means you have installed neither platform tools(usually available in /opt/android-sdk/platform-tools/
) nor android-tools(available in /usr/bin/
).
If you are getting an empty list (your device is not there), it may be because you have not enabled USB debugging on your device. You can do that by going to Settings => Applications => Development and enabling USB debugging. On Android 4.2 (Jelly Bean) the Development menu is hidden; to enable it go to Settings => About phone and tap Build number 7 times.
If there are still problems such as adb displaying ???????? no permissions
under devices, try restarting the adb server as root.
# adb kill-server # adb start-server
NVIDIA Tegra platform
If you target your application at NVIDIA Tegra platform, you might also want to install tools, samples and documentation provided by NVIDIA. In NVIDIA Developer Zone for Mobile there are two tools:
- The Tegra Android Development Pack provides tools (NVIDIA Debug Manager) related to Eclipse ADT and their documentation.
- The Tegra Toolkit provides tools (mostly CPU and GPU optimization related), samples and documentation.
Both are currently not available in the AUR anymore, because NVIDIA requires a registration/login for the download.
Building Android
Please note that these instructions are based on the official AOSP build instructions. Other Android-derived systems such as CyanogenMod will often require extra steps.
OS bitness
Android 2.2.x (Froyo) and below are the only versions of Android that will build on a 32-bit system. For 2.3.x (Gingerbread) and above, you will need a 64-bit installation.
Required packages
To build any version of Android, you need to install these packages:
- 32-bit and 64-bit systems: gcc git gnupg flex bison gperf sdl wxgtk squashfs-tools curl ncurses zlib schedtool perl-switch zip unzip libxslt python2-virtualenv bc
- 64-bit systems only: gcc-multilib lib32-zlib lib32-ncurses lib32-readline
- AUR Packages: libtinfoAUR
Java Development Kit
Android 5 (Lollipop) can be built with jdk7-openjdk.
Older versions require a working Oracle JDK installed on your build system. It will not work with OpenJDK.
- For Gingerbread through KitKat (2.3 - 4.4), Java 6 is required, which is available as jdk6AUR from the AUR. See Java if you want to use it besides another (newer) JDK version.
- For Cupcake through Froyo (1.5 - 2.2), Java 5 is required, which is no longer available for Arch Linux.
Setting up the build environment
Download the repo
utility per Android Downloading the Source guide.
$ mkdir ~/bin $ export PATH=~/bin:$PATH $ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo $ chmod a+x ~/bin/repo
Create a directory to build.
$ mkdir ~/android $ cd ~/android
You will need to change the default Python from version 3 to version 2:
$ virtualenv2 venv # Creates a directory, venv/, containing the Virtualenv
Activate the Virtualenv, which will update $PATH to point at Python 2.
$ 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
repo
has a-j
switch that operates similarly to the one used withmake
. 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 (release of Android) to check out with the
-b
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 .repo
and .git
directories that are used to keep track of it, are well over 10 GB.
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 out/target/product/hammerhead (hammerhead being the device name) that can be flashed.
Restoring Android
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) comes together with a package android-tools from the official repositories.
Samsung
Samsung does not support fastboot in any way. Using Odin is safer, easier and more popular than Heimdall, but it's up to you.
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 heimdall or heimdall-gitAUR.
The flashing instructions can be found on Heimdall's GitHub page or on XDA forums.
Odin (Virtualbox)
It is also possible to restore stock Android on the Samsung devices using Odin, but inside the VirtualBox. For more information, see XDA thread.
Arch Linux related steps:
- Install VirtualBox together with it's extension pack. Optionally, install guest additions.
- Install your preferred, but compatible with Odin, Windows operating system into a virtual hard drive using VirtualBox. Optionally, install guest additions to the Windows operating system.
- Open VirtualBox settings of your Windows operating system, navigate to USB, then tick (or make sure it's ticked) Enable USB 2.0 (EHCI) Controller.
- At VirtualBox running Windows operating system, click in the menu bar Devices, then USB Devices, then click on your Samsung mobile device connected to your computer via USB.
Windows related links:
- Samsung drivers can be downloaded from here.
- Odin can be downloaded from here.
- Samsung Android firmwares can be downloaded from here.
If you want to make sure that everything is working and ready, connect your Samsung device turned on into a Download mode, and open Odin. The white box (a big one at the bottom-left) named Message, should print a line similar to this:
<ID:0/003> Added!!
which means that your device is visible to Odin and is ready to be flashed.
Alternative connection methods
AirDroid
AirDroid is an Android app to access files from your web browser.
FTP
You run a FTP server on Arch and connect to it from your phone, or the other way around: run a FTP server on your phone and connect to it from Arch.
See List of applications/Internet#FTP. There are a lot of FTP clients/servers available for Android.
SSH Server
There are many SSH servers available for Android, it allows you to transfer files using scp
command. See also SSH.
Samba
See Samba.
Tips & Tricks
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 the forum post for more information: http://www.eclipsezone.com/eclipse/forums/t83338.rhtml
Linux distribution on the sdcard
You can install Debian like in this thread. Excellent guide to installing Arch in chroot (in parallel with Android) can be found on archlinuxarm.org forum.
Troubleshooting
aapt: No such file or directory
The build tools include 32-bit binaries. For this reason they require 32-bit libraries. If you happened to install the SDK manually, you will additionally need to install multilib/lib32-libstdc++5 and multilib/lib32-zlib.
ValueError: unsupported pickle protocol
One fix is to issue:
rm ~/.repopickle_.gitconfig
If that does not work, then try this:
rm `find /path/to/android-root -name .repopickle_config`