https://wiki.archlinux.org/api.php?action=feedcontributions&user=Iwtu&feedformat=atomArchWiki - User contributions [en]2024-03-28T12:35:38ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Android&diff=236765Android2012-11-25T15:46:05Z<p>Iwtu: /* Setting up Eclipse */</p>
<hr />
<div>[[Category:Development]]<br />
[[it:Android]]<br />
[[ru:Android]]<br />
[[zh-CN:Android]]<br />
== Android Development on Arch ==<br />
=== Getting SDK and IDE plugins ===<br />
<br />
(If you are running Arch64, you have to enable [[Arch64_FAQ#Multilib_Repository_-_Multilib_Project | the multilib repo]], to be able to to install the required dependencies using [[pacman]].)<br />
<br />
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 />
When using [[Eclipse]] as an IDE you need to install the ADT plugin and related packages. If you get a message about unresolvable dependencies, install [[Java]] manually and try again. Alternatively you can use [[Netbeans]] for development after installing living and usually up to date plugin according to [http://www.nbandroid.org/p/installation.html these instructions].<br />
<br />
==== Setting up 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 />
Enter the path to the Android SDK Location in<br />
<br />
Windows -> Preferences -> Android<br />
<br />
Note: as an alternative, you can install the ADT via eclipse's built in "add new software" command. This has the advantage of keeping the ADT always up to date, unlike the AUR approach which requires manually updating packages.<br />
<br />
Note: if you a trouble, it is also possible to download Android SDK and use the enclosed Eclipse. This should works without problems.<br />
<br />
==== Setting up 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://kenai.com/projects/nbandroid/downloads/download/updatecenter/updates.xml<br />
<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 />
=== Android platforms ===<br />
Before developing android applications, you need to install at least one Android platform, which can be done either automatically or manually.<br />
<br />
==== Automatic installation ====<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 />
<br />
or alternatively:<br />
./<path_to_android-sdk>/tools/android<br />
<br />
If the automatic installation errors out, then you must either run the android tool with heightened privileges or 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 />
To 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 />
<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. All are listed at <br />
{{AUR|android-sdk}} page (see dependent packages list).<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 />
=== Android Debug Bridge (ADB) - Connecting to a real device ===<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 />
==== 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.<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 32 bits or 64 bits systems<br />
<br />
git gnupg flex bison gperf sdl wxgtk squashfs-tools curl ncurses zlib schedtool openjdk6 perl-switch zip unzip<br />
<br />
Only for 64 bits systems<br />
<br />
lib32-zlib lib32-ncurses lib32-readline gcc-libs-multilib gcc-multilib lib32-gcc-libs<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 />
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 MTPFS 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.</div>Iwtu