https://wiki.archlinux.org/api.php?action=feedcontributions&user=Chief-detektor&feedformat=atomArchWiki - User contributions [en]2024-03-28T21:51:24ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Android&diff=268743Android2013-07-30T00:56:39Z<p>Chief-detektor: The URL for the plugins changed as discribed here: https://kenai.com/projects/nbandroid/pages/Install</p>
<hr />
<div>[[Category:Development]]<br />
[[it:Android]]<br />
[[ru:Android]]<br />
[[zh-CN:Android]]<br />
== Android Development on Arch ==<br />
<br />
There are three parts to set up: <br />
# Android SDK core component,<br />
# Android SDK Platform packages<br />
# Development environment<br />
<br />
=== Install Android SDK core components ===<br />
Before developing android applications, you need to install at least one Android platform. Install core SDK components from [[Arch User Repository|AUR]]:<br />
<br />
# {{AUR|android-sdk}}<br />
# {{AUR|android-sdk-platform-tools}}<br />
<br />
Typical installation location is {{Ic|/opt/android-sdk}}.<br />
<br />
{{Note|If you are running a 64-bit system, you will have to enable the [[multilib]] repository, to be able to to install the required dependencies using [[pacman]].}}<br />
<br />
=== Getting Android SDK Platform packages ===<br />
And then install the Android SDK Platform packages which can be done either automatically, from the [[Arch User Repository|AUR]], or manually.<br />
<br />
==== Automatic installation ====<br />
{{accuracy|This involves very bad practices. Giving users write access to directories in the PATH of root and other users breaks down any difference between them.}}<br />
Automatic installation is done via the Android SDK and device manager, which is accessible by invoking (assuming that the {{Ic|$PATH}} [[Environment Variables|variable]] contains the path to the Android SDK {{ic|tools}} directory):<br />
$ android<br />
or alternatively:<br />
$ <path_to_android-sdk>/tools/android<br />
<br />
If you get this error 'Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: peer not authenticated' you need to go into the options and make sure to check 'Force https:// sources to be fetched using http://'<br />
<br />
If the automatic installation errors out, then you must do '''one''' of the following:<br />
<br />
* run the android tool with heightened privileges<br />
# android<br />
<br />
* set your user account as the owner of the directory. To change the owner ID for all SDK directories, run the following command as root:<br />
# chown -R USER /opt/android-sdk<br />
<br />
* change the group ID instead (recommended for multiple users), first create the group, perhaps called ''android'', and add your user account to it:<br />
# groupadd android<br />
# gpasswd -a USER android<br />
Next, change the directory permissions:<br />
# chgrp -R android /opt/android-sdk<br />
# chmod -R g+w /opt/android-sdk<br />
# find /opt/android-sdk -type d -exec chmod g+s {} \;<br />
The final command sets the ''setgid'' bit on all subdirectories so that any new files created within them will inherit the proper group ID.<br />
Then rerun <br />
$ android<br />
<br />
For step-by-step automatic installation, see: [http://developer.android.com/sdk/adding-components.html Installing SDK Components].<br />
<br />
==== Getting from AUR ====<br />
AUR currently contains multiple packages with Android platforms sometimes duplicating each other and/or having incorrect file permissions set. <br />
<br />
==== Manual installation ====<br />
For manual installation:<br />
# Download the platform you want to develop on. [http://qdevarena.blogspot.com/2010/05/download-android-sdk-standalone-for.html This site] provides online links to several Android SDK components.<br />
# Extract the tarball to {{ic|/<path_to_android-sdk>/platforms}}.<br />
<br />
Now, you should see the platform of your choice installed in the Installed Packages window of the Android SDK and device manager.<br />
<br />
=== Setting up Development Environment ===<br />
<br />
Android Studio is a new (and still experimental!) Android development environment based on IntelliJ IDEA. The more traditional IDE is [[Eclipse]] with the ADT plugin and related packages. Alternatively you can use [[Netbeans]] for development after installing the plugin as described below.<br />
<br />
==== Android Studio ====<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.<br />
<br />
==== Eclipse ====<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 />
<br />
Enter the path to the Android SDK Location in<br />
<br />
Windows -> Preferences -> Android<br />
<br />
==== Netbeans ====<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/release72/updates/updates.xml<br />
<br />
Then go to '''Available Plugins''' and install the '''Android''' and '''Android Test Runner''' plugins for your IDE version. Once you have installed go to:<br />
<br />
if you have problem with netbeans 7.2 "org.netbeans.modules.gsf.testrunner was needed and not found." Please remove the the '''Android''' and '''Android Test Runner''' , then change the url of nbandroid to: http://nbandroid.org/release72/updates/updates.xml , update the sources and you just need to install the '''Android''' only.<br />
<br />
Tools -> Options -> Miscellaneous -> Android<br />
<br />
and select the path where the SDK is installed. That's 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 />
To get ADB to connect to a real device or phone under Arch, you must install the [[udev]] rules to connect the device to the proper {{Ic|/dev/}} entries.<br />
<br />
==== Using existing rules ====<br />
Install the AUR package {{AUR|android-udev}} to get a common list of vendor IDs. 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 Your Device Ids ====<br />
Each Android device has a USB vendor/product ID. An example for HTC Evo is:<br />
vendor id: 0bb4<br />
product id: 0c8d<br />
<br />
Plug in your device and execute:<br />
$ lsusb<br />
<br />
It should come up something like this:<br />
Bus 002 Device 006: ID 0bb4:0c8d High Tech Computer Corp.<br />
<br />
==== Adding udev Rules ====<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 />
Note: reloading udev rules under systemd should not be required, as any rule changes should be picked up automatically.<br />
<br />
==== Configuring adb ====<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 />
$ adb devices<br />
<br />
you should see something like:<br />
List of devices attached <br />
HT07VHL00676 device<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 isn't 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 />
{{Tip|Make sure that your user is added to the group:<br />
# gpasswd -a ''username'' adbusers<br />
}}<br />
<br />
If there are still problems such as '''adb''' displaying "???????? no permissions" under devices, try restarting the adb server as root.<br />
# adb kill-server<br />
# adb start-server<br />
<br />
=== Tools specific to 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 packages - [http://developer.nvidia.com/tegra-resources Tegra Android Development Pack], available from AUR as {{AUR|tegra-devpack}} and [http://developer.nvidia.com/tegra-resources Tegra Toolkit], available from AUR as {{AUR|tegra-toolkit}}.<br />
<br />
The {{AUR|tegra-toolkit}} package provides tools (mostly CPU and GPU optimization related), samples and documentation, while the {{AUR|tegra-devpack}} provides tools (NVIDIA Debug Manager) related to [http://developer.android.com/sdk/eclipse-adt.html Eclipse ADT] and their documentation.<br />
<br />
=== Tethering ===<br />
See [[Android Tethering]]<br />
<br />
== Building Android ==<br />
<br />
To build android, you need to install these packages.<br />
<br />
*For all 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|openjdk6}} {{Pkg|perl-switch}} {{Pkg|zip}} {{Pkg|unzip}} {{Pkg|libxslt}}<br />
<br />
*Additional packages, only required on 64-bit systems: {{Pkg|gcc-multilib}} {{Pkg|lib32-zlib}} {{Pkg|lib32-ncurses}} {{Pkg|lib32-readline}}<br />
<br />
And you need to change the default python from version 3 to version 2:<br />
<br />
# rm /usr/bin/python<br />
# ln -s /usr/bin/python2 /usr/bin/python<br />
<br />
Download the '''repo''' utility.<br />
<br />
$ mkdir ~/bin<br />
$ export PATH=~/bin:$PATH<br />
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/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 />
Synchronize the repositories.<br />
<br />
$ repo init -u https://android.googlesource.com/platform/manifest (checkout the master)<br />
$ repo sync<br />
<br />
Wait a lot. <br />
<br />
When finished, start building.<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 the number of cores and 2 * number of cores.<br />
<br />
The build takes a lot of 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 [https://wiki.archlinux.org/index.php/Fstab fstab] all together. <br />
}}<br />
<br />
When finished, run the final image.<br />
<br />
$ emulator<br />
<br />
== Tips & Tricks ==<br />
=== During Debugging "Source not found" ===<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 />
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].<br />
<br />
=== Android SDK on Arch 64 ===<br />
When using the Android SDK and the Eclipse plugin on a 64 bit system, and the 'emulator' always crashes with a segfault, do the following:<br />
Provide a localtime file in /usr/share/zoneinfo/localtime e.g.: <br />
# cp /usr/share/zoneinfo/Europe/Berlin /usr/share/zoneinfo/localtime<br />
<br />
=== Better MTP support ===<br />
If you have an Android device that doesn't support UMS and you find mtpfs to be extremely slow you can install {{AUR|jmtpfs}} from the AUR. See [[MTP]] for more options.</div>Chief-detektor