https://wiki.archlinux.org/api.php?action=feedcontributions&user=Zorlin&feedformat=atomArchWiki - User contributions [en]2024-03-29T06:16:36ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Android&diff=349214Android2014-12-09T00:51:08Z<p>Zorlin: /* Development environment */</p>
<hr />
<div>[[Category:Development]]<br />
[[Category:Mobile devices]]<br />
[[it:Android]]<br />
[[ja:Android]]<br />
[[ru:Android]]<br />
[[zh-CN:Android]]<br />
{{Related articles start}}<br />
{{Related|Android notifier}}<br />
{{Related|Android tethering}}<br />
{{Related articles end}}<br />
<br />
== Exploring Android device ==<br />
<br />
To view the contents of your Android device's storage via [[MTP]] over USB, and have integration with file manager, please refer to [[MTP#Installation]].<br />
<br />
If you're interested in connecting to your Android device via '''adb''' or '''fastboot''' over USB, for development or flashing purposes, skip to [[#Connecting to a real device - Android Debug Bridge (ADB)]].<br />
<br />
For alternative ways to connect to your Android device from Arch Linux, e.g. over the Internet using FTP or SSH, see [[#Alternative connection methods]].<br />
<br />
== Android development ==<br />
<br />
There are 3 steps that need to be performed before you can develop Android applications on your Arch Linux box:<br />
<br />
# Install the Android SDK core component,<br />
# Install one or several Android SDK Platform packages,<br />
# Install one of the IDEs compatible with the Android SDK.<br />
<br />
=== Android SDK core components ===<br />
<br />
{{Note|First, if you are running a 64-bit system, make sure the [[multilib]] repository is enabled in [[Pacman#Repositories|pacman.conf]].}}<br />
<br />
Before developing Android applications, you need to install the Android SDK, which is made of 3 distinct packages, all installable from [[Arch User Repository|AUR]]:<br />
<br />
# {{AUR|android-sdk}}<br />
# {{AUR|android-sdk-platform-tools}}<br />
# {{AUR|android-sdk-build-tools}}<br />
<br />
Android-sdk will be installed on {{ic|/opt/android-sdk}}. This folder has root permissions, so keep in mind to run sdk manager as root, otherwise you won't be able to install/update/modify anything on /opt/android-sdk. However, if you intend to use it as a regular user, please follow the instructions below.<br />
<br />
<br />
Create an Android sdk users group (use any name you want):<br />
# groupadd sdkusers<br />
<br />
Add your user into this group:<br />
# gpasswd -a <user> sdkusers<br />
<br />
Change folder's owner and group.<br />
# chown -R <user>:sdkusers /opt/android-sdk/<br />
<br />
Change permissions of the folder so you will be able to read/write/execute in it:<br />
# chmod -R 0774 /opt/android-sdk/<br />
<br />
{{Note|As an alternative to a global install with the [[AUR]] packages, the SDK can be installed to a user's home directory via [https://developer.android.com/sdk/index.html the upstream instructions].}}<br />
<br />
=== Android SDK platform API ===<br />
<br />
Install the desired Android SDK Platform package from the [[AUR]]:<br />
<br />
* {{aur|android-platform}} (latest)<br />
* {{aur|android-platform-21}}<br />
* {{aur|android-platform-20}}<br />
* {{aur|android-platform-19}}<br />
* {{aur|android-platform-18}}<br />
* {{aur|android-platform-17}}<br />
* {{aur|android-platform-16}}<br />
* {{aur|android-platform-15}}<br />
* {{aur|android-platform-14}}<br />
* {{aur|android-platform-13}}<br />
* {{aur|android-platform-12}}<br />
* {{aur|android-platform-11}}<br />
* {{aur|android-platform-10}}<br />
* {{aur|android-platform-9}}<br />
* {{aur|android-platform-8}}<br />
* {{aur|android-platform-7}}<br />
* {{aur|android-platform-7}}<br />
* {{aur|android-platform-6}}<br />
* {{aur|android-platform-5}}<br />
* {{aur|android-platform-4}}<br />
* {{aur|android-platform-3}}<br />
* {{aur|android-platform-2}}<br />
<br />
=== Development environment ===<br />
<br />
Android Studio is the new Android development environment based on IntelliJ IDEA. The more traditional IDE is [[Eclipse]] with the ADT plugin and related packages, but as of 2014-12-08 the ADT plugin is officially considered deprecated and Android Studio is now the official IDE. Alternatively you can use [[Netbeans]] for development after installing the plugin as described below.<br />
<br />
==== Android Studio ====<br />
<br />
[http://developer.android.com/sdk/installing/studio.html Android Studio] is a new (and still experimental!) Android development environment based on IntelliJ IDEA. Similar to Eclipse with the ADT Plugin, Android Studio provides integrated Android developer tools for development and debugging.<br />
<br />
You can download and install it with the {{AUR|android-studio}} package from the AUR. If you get an error about a missing SDK, refer to the section Getting Android SDK platform API above.<br />
<br />
If you are using a tiling window manager, you will need to apply one of the fixes mentioned in [https://code.google.com/p/android/issues/detail?id=57675 this] issue page.<br />
<br />
==== Eclipse ====<br />
<br />
Most stuff required for Android development in Eclipse is already packaged in AUR:<br />
<br />
Official plugin by Google &ndash; [http://developer.android.com/sdk/eclipse-adt.html Eclipse ADT]:<br />
# {{AUR|eclipse-android}}<br />
<br />
Dependencies:<br />
# {{AUR|eclipse-emf}}<br />
# {{AUR|eclipse-gef}}<br />
# {{AUR|eclipse-wtp}}<br />
<br />
{{Note|<br />
* if you get a message about unresolvable dependencies, install [[Java]] manually and try again.<br />
* as an alternative, you can install the ADT via eclipse's built in "add new software" command (see instructions on ADT site).<br />
* if you are in real trouble, it is also possible to download Android SDK and use the bundled Eclipse. This usually works without problems.<br />
* if you need to install extra SDK plugins not found in the AUR, you must change the file ownership of /opt/android-sdk first. You can do this with {{ic|# chgrp -R users /opt/android-sdk ; chmod -R 0775 /opt/android-sdk}} (see [[File Permissions]] for more details).<br />
}}<br />
<br />
Enter the path to the Android SDK Location in<br />
<br />
Windows -> Preferences -> Android<br />
<br />
{{Note|<br />
If the plugins don't show up in Eclipse after the AUR package has been upgraded, then eclipse probably has out-of-date caches. Running {{ic|sudo eclipse -clean}} once should clear them. If the problem persists, uninstall eclipse and all the plugins, delete {{ic|/usr/share/eclipse}}, and reinstall everything.<br />
}}<br />
<br />
==== Netbeans ====<br />
<br />
If you prefer using [[Netbeans]] as your IDE and want to develop Android applications, download the [http://www.nbandroid.org nbandroid] by going to:<br />
<br />
Tools -> Plugins -> Settings<br />
<br />
Add the following URL: http://nbandroid.org/updates/updates.xml<br />
<br />
Then go to '''Available Plugins''' and install the '''Android''' and '''JUnit''' plugins. Once you have installed go to:<br />
<br />
Tools -> Options -> Miscellaneous -> Android<br />
<br />
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.<br />
<br />
=== Connecting to a real device - Android Debug Bridge (ADB) ===<br />
<br />
{{Tip|For some devices, you may have to enable MTP on the device, before ADB will work.}}<br />
<br />
To get ADB to connect to a real device or phone under Arch, you must:<br />
<br />
* Install {{Pkg|android-tools}}.<br />
* Enable USB Debugging on your phone or device:<br />
** Jelly Bean (4.2) and newer: Go to {{ic|Settings --> About Phone}} tap “Build Number” until you get a popup that you have become a developer (about 10 times). Then go to {{ic|Settings --> Developer --> USB debugging}} and enable it.<br />
** Older versions: This is usually done from {{ic|Settings --> Applications --> Development --> USB debugging}}. Reboot the phone after checking this option to make sure USB debugging is enabled.<br />
* install {{Pkg|android-udev}} to connect the device to the proper {{ic|/dev/}} entries.<br />
* Add yourself to the ''adbusers'' group. ({{ic|gpasswd -a ''username'' adbusers}})<br />
<br />
<br />
If [[#Does it work?|ADB recognizes your device]] (it is visible and accessible in IDE), you are done. Otherwise see instructions below.<br />
<br />
==== Figure out device IDs ====<br />
<br />
Each Android device has a USB vendor/product ID. An example for HTC Evo is:<br />
<br />
vendor id: 0bb4<br />
product id: 0c8d<br />
<br />
Plug in your device and execute:<br />
<br />
$ lsusb<br />
<br />
It should come up something like this:<br />
<br />
Bus 002 Device 006: ID 0bb4:0c8d High Tech Computer Corp.<br />
<br />
==== Adding udev Rules ====<br />
<br />
Use the rules from [http://source.android.com/source/initializing.html#configuring-usb-access 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 {{ic|/etc/udev/rules.d/51-android.rules}}:<br />
<br />
{{hc|/etc/udev/rules.d/51-android.rules|2=<nowiki>SUBSYSTEM=="usb", ATTR{idVendor}=="[VENDOR ID]", MODE="0666"<br />
SUBSYSTEM=="usb",ATTR{idVendor}=="[VENDOR ID]",ATTR{idProduct}=="[PRODUCT ID]",SYMLINK+="android_adb"<br />
SUBSYSTEM=="usb",ATTR{idVendor}=="[VENDOR ID]",ATTR{idProduct}=="[PRODUCT ID]",SYMLINK+="android_fastboot"</nowiki>}}<br />
<br />
Then, to reload your new udev rules, execute:<br />
# udevadm control --reload-rules<br />
<br />
==== Configuring adb ====<br />
<br />
Instead of using udev rules you may create/edit ~/.android/adb_usb.ini which contains list of vendor ids.<br />
<br />
$ cat ~/.android/adb_usb.ini <br />
0x27e8<br />
<br />
==== Does it work? ====<br />
<br />
After you have setup the udev rules, unplug your device and replug it.<br />
<br />
After running:<br />
<br />
$ adb devices<br />
<br />
you should see something like:<br />
<br />
List of devices attached <br />
HT07VHL00676 device<br />
<br />
You can now use adb to transfer files between the device and your computer. To transfer files to the device, use<br />
$ adb push ''<what-to-copy>'' ''<where-to-place>''<br />
<br />
To transfer files from the device, use<br />
$ adb pull ''<what-to-pull>'' ''<where-to-place>''<br />
<br />
If you do not have the '''adb''' program (usually available in {{Ic|/opt/android-sdk/platform-tools/}}), it means you have not installed the platform tools.<br />
<br />
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.<br />
<br />
If there are still problems such as ''adb'' displaying {{ic|???????? no permissions}} under devices, try restarting the adb server as root.<br />
# adb kill-server<br />
# adb start-server<br />
<br />
=== NVIDIA Tegra platform ===<br />
<br />
If you target your application at NVIDIA Tegra platform, you might also want to install tools, samples and documentation provided by NVIDIA. In [http://developer.nvidia.com/category/zone/mobile-development NVIDIA Developer Zone for Mobile] there are two tools: <br />
<br />
# The [http://developer.nvidia.com/tegra-resources Tegra Android Development Pack] provides tools (NVIDIA Debug Manager) related to [http://developer.android.com/sdk/eclipse-adt.html Eclipse ADT] and their documentation. <br />
# The [http://developer.nvidia.com/tegra-resources Tegra Toolkit] provides tools (mostly CPU and GPU optimization related), samples and documentation. <br />
<br />
Both are currently not available in the [[AUR]] anymore, because NVIDIA requires a registration/login for the download.<br />
<br />
== Building android ==<br />
<br />
Please note that these instructions are based on the [http://source.android.com/source/building.html official AOSP build instructions]. Other Android-derived systems such as CyanogenMod will often require extra steps.<br />
<br />
=== OS bitness ===<br />
<br />
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. <br />
<br />
=== Required packages ===<br />
<br />
To build any version of Android, you need to install these packages:<br />
<br />
* 32-bit and 64-bit systems: {{Pkg|gcc}} {{Pkg|git}} {{Pkg|gnupg}} {{Pkg|flex}} {{Pkg|bison}} {{Pkg|gperf}} {{Pkg|sdl}} {{Pkg|wxgtk}} {{Pkg|squashfs-tools}} {{Pkg|curl}} {{Pkg|ncurses}} {{Pkg|zlib}} {{Pkg|schedtool}} {{Pkg|perl-switch}} {{Pkg|zip}} {{Pkg|unzip}} {{Pkg|libxslt}} {{Pkg|python2-virtualenv}}<br />
<br />
* 64-bit systems only: {{Pkg|gcc-multilib}} {{Pkg|lib32-zlib}} {{Pkg|lib32-ncurses}} {{Pkg|lib32-readline}}<br />
<br />
=== Java Development Kit ===<br />
<br />
Android 5 (Lollipop) can be built with {{Pkg|jdk7-openjdk}}.<br />
<br />
Older versions [http://source.android.com/source/initializing.html require] a working '''Oracle JDK''' installed on your build system. It '''will not''' work with OpenJDK.<br />
*For Gingerbread through KitKat (2.3 - 4.4), install {{AUR|jdk6}} if you do not develop on the JVM, or {{AUR|jdk6-compat}}, if you do have a preferred JVM for other tasks.<br />
*For Cupcake through Froyo (1.5 - 2.2), Java 5 is required, which is no longer available for Arch Linux.<br />
<br />
Note that, if you choose to install {{AUR|jdk6-compat}} (Android before 5), you will need to set the {{ic|JAVA_HOME}} environment variable to the location of the JDK6:<br />
<br />
$ export JAVA_HOME=/opt/java6<br />
<br />
Otherwise, {{ic|PATH}} will be reset to the location of the JDK7 by the build scripts, and all your AOSP builds will abort, complaining about the wrong version of {{ic|javac}} (the Java Compiler.)<br />
<br />
To set {{ic|JAVA_HOME}} on the system level, see the files in '''/etc/profile.d''' named '''jdk.sh''', '''jdk.csh''', '''jre.csh''', and '''jre.sh'''.<br />
<br />
For Android 5 set {{ic|JAVA_HOME}} to '''/usr/lib/jvm/java-7-openjdk/''' and ensure that '''/usr/lib/jvm/java-7-openjdk/bin''' is the first on the path.<br />
<br />
=== Setting up the build environment ===<br />
<br />
Download the {{ic|repo}} utility.<br />
<br />
$ mkdir ~/bin<br />
$ export PATH=~/bin:$PATH<br />
$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo<br />
$ chmod a+x ~/bin/repo<br />
<br />
Create a directory to build.<br />
<br />
$ mkdir ~/android<br />
$ cd ~/android<br />
<br />
You will need to change the default Python from version 3 to version 2:<br />
<br />
$ virtualenv2 venv # Creates a directory, venv/, containing the Virtualenv<br />
<br />
{{Note|During build you may receive error pertaining to missing python modules. A quick and dirty fix is to symlink /usr/lib/python2.7/* to ~/android/venv/python2.7/ (Change ~/android to reflect your build directory if different than above).<br />
Example:<br />
$ ln -s /usr/lib/python2.7/* /Data/Android_Build/venv/lib/python2.7/<br />
}}<br />
Activate the Virtualenv, which will update $PATH to point at Python 2.<br />
<br />
{{Note|this activation is only active for the current terminal session.<br />
}}<br />
<br />
$ source venv/bin/activate<br />
<br />
=== Downloading the source code ===<br />
<br />
This will clone the repositories. You '''only''' need to do this the first time you build Android, or if you want to switch branches.<br />
<br />
* The {{ic|repo}} has a {{ic|-j}} switch that operates similarly to the one used with {{ic|make}}. Since it controls the number of simultaneous downloads, you should adjust the value depending on downstream network bandwidth.<br />
<br />
* You will need to specify a '''branch''' (release of Android) to check out with the {{ic|-b}} switch. If you leave the switch out, you will get the so-called '''master branch'''.<br />
<br />
$ repo init -u https://android.googlesource.com/platform/manifest -b master<br />
$ repo sync -j4<br />
<br />
Wait a long time. Just the uncompiled source code, along with the {{ic|.repo}} and {{ic|.git}} directories that are used to keep track of it, are well over 10 GB.<br />
<br />
{{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:<br />
$ repo sync<br />
}}<br />
<br />
=== Building the code ===<br />
<br />
This should do what you need for AOSP:<br />
<br />
$ source build/envsetup.sh<br />
$ lunch full-eng<br />
$ make -j4<br />
<br />
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.<br />
<br />
The build takes a very long time.<br />
<br />
{{Note|Make sure you have enough RAM.<br />
Android will use the /tmp directory heavily. By default the size of the partition the /tmp folder is mounted on is half the size of your RAM. If it fills up, the build will fail. 4GB of RAM or more is recommended.<br />
* Alternatively, you can get rid of the tmpfs from [[Fstab|fstab]] all together. <br />
}}<br />
<br />
=== Testing the build ===<br />
<br />
When finished, run/test the final image(s).<br />
<br />
$ emulator<br />
<br />
=== Creating a Flashable Image ===<br />
To create an image that can be flashed it's necessary to:<br />
<br />
make -j8 updatepackage<br />
<br />
This will create a zip image under '''out/target/product/hammerhead''' (hammerhead being the device name) that can be flashed.<br />
<br />
== Alternative connection methods ==<br />
<br />
=== AirDroid ===<br />
<br />
AirDroid is an Android app to access files from your web browser.<br />
<br />
=== FTP ===<br />
<br />
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.<br />
<br />
See [[List of applications/Internet#FTP]]. There are a lot of FTP clients/servers available for Android.<br />
<br />
=== SSH Server ===<br />
<br />
There are many SSH servers available for Android, it allows you to transfer files using {{ic|scp}} command. See also [[SSH]].<br />
<br />
=== Samba ===<br />
<br />
See [[Samba]].<br />
<br />
== Tips & Tricks ==<br />
<br />
=== During Debugging "Source not found" ===<br />
<br />
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: <br />
Window -> Preferences -> Java -> Debug -> Step Filtering<br />
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<br />
<br />
=== Linux distribution on the sdcard ===<br />
<br />
You can install Debian like in this [http://forum.xda-developers.com/showthread.php?t=631389 thread]. Excellent guide to installing Arch in chroot (in parallel with Android) can be found on [http://archlinuxarm.org/forum/viewtopic.php?f=27&t=1361&start=40 archlinuxarm.org forum].</div>Zorlin