Difference between revisions of "Android"
m (→Getting Android SDK Platform packages) |
m (→Exploring Android device: reference MTP article using full name) |
||
(309 intermediate revisions by more than 100 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:Development]] | [[Category:Development]] | ||
+ | [[Category:Mobile devices]] | ||
[[it:Android]] | [[it:Android]] | ||
+ | [[ja:Android]] | ||
[[ru:Android]] | [[ru:Android]] | ||
− | [[zh- | + | [[zh-hans:Android]] |
− | + | {{Related articles start}} | |
+ | {{Related|Android tethering}} | ||
+ | {{Related articles end}} | ||
− | + | == Exploring Android device == | |
− | |||
− | |||
− | |||
− | + | When you connect a modern Android device via USB to a computer you can use the [[Media Transfer Protocol]] to transfer files and [[#Android Debug Bridge]] to debug it. | |
− | |||
+ | Files can generally be transferred with various protocols ([[SSH]], [[:Category:File Transfer Protocol|FTP]], [[Samba]], HTTP). You just need to setup a client and a server (via apps Android can act as either one). | ||
+ | |||
+ | For flashing and restoring Android firmware see [[#Restoring Android]]. | ||
+ | |||
+ | See [[#Connection software]] for software available for Arch Linux that can be used to connect to Android. | ||
+ | |||
+ | == Android development == | ||
+ | |||
+ | To develop Android applications you need three things: | ||
+ | |||
+ | * the Android SDK core component | ||
+ | * one or several Android SDK Platform packages | ||
+ | * an IDE | ||
+ | |||
+ | The official IDE for Android is [[#Android Studio]], which comes with its own SDK manager. | ||
+ | |||
+ | === Android Studio === | ||
+ | |||
+ | [https://developer.android.com/studio/index.html Android Studio] is the official Android development environment based on [https://www.jetbrains.com/idea/ IntelliJ Idea]. It provides integrated Android developer tools for development and debugging. | ||
+ | |||
+ | You can [[install]] it with the {{AUR|android-studio}} package. If you get an error about a missing SDK, refer to [[#Android SDK platform API]]. | ||
+ | |||
+ | {{Note|1=<nowiki></nowiki> | ||
+ | * If you are using a tiling window manager other than [[i3]], you may need to apply one of the fixes mentioned in [https://code.google.com/p/android/issues/detail?id=57675 this] issue page. | ||
+ | * Make sure you properly [[Java#Change_default_Java_environment|set the Java environment]] otherwise android-studio will not start. | ||
+ | }} | ||
+ | |||
+ | Normally, apps are built through the Android Studio GUI. To build apps from the commandline (using e.g. {{ic|./gradlew assembleDebug}}), add the following to your {{ic|~/.bashrc}}: | ||
+ | |||
+ | export ANDROID_HOME=/opt/android-sdk | ||
+ | |||
+ | === Manual SDK installation === | ||
+ | |||
+ | If you are using [[#Android Studio]] and want the IDE to manage your SDK installation, you can skip this section. | ||
+ | |||
+ | ==== Android SDK core components ==== | ||
+ | |||
+ | {{Note|Since the Android SDK contains 32-bit binaries, you must enable the [[multilib]] repository. Otherwise you will get {{ic|error: target not found: lib32-*}} error messages.}} | ||
+ | |||
+ | Before developing Android applications, you need to install the Android SDK, which is made of 4 distinct packages, all installable from [[AUR]]: | ||
+ | |||
+ | # {{AUR|android-platform}} | ||
# {{AUR|android-sdk}} | # {{AUR|android-sdk}} | ||
# {{AUR|android-sdk-platform-tools}} | # {{AUR|android-sdk-platform-tools}} | ||
# {{AUR|android-sdk-build-tools}} | # {{AUR|android-sdk-build-tools}} | ||
− | + | If supporting older devices, or working with older code, {{AUR|android-support}} and {{AUR|android-support-repository}} might be required. | |
− | {{ | + | 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 will not be able to modify anything in this directory. If you intend to use it as a regular user, create the Android sdk users group: |
− | + | # groupadd sdkusers | |
− | |||
− | + | Add your user into this group: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | # gpasswd -a <user> sdkusers | |
− | + | Change folder's group. | |
− | + | # chown -R :sdkusers /opt/android-sdk/ | |
− | # android | ||
− | + | 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/ | |
− | |||
− | |||
− | |||
− | |||
− | # chmod -R g+w /opt/android-sdk | ||
− | |||
− | |||
− | |||
− | |||
− | + | Re-login or as <user> log your terminal in to the newly created group: | |
− | + | $ newgrp sdkusers | |
− | |||
− | + | {{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]. You may also use the android-*-dummy packages in the [[AUR]] to handle the system dependencies.}} | |
− | |||
− | |||
− | |||
− | + | ==== Android SDK platform API ==== | |
+ | |||
+ | Install the desired Android SDK Platform package from the [[AUR]]: | ||
+ | |||
+ | * {{aur|android-platform}} – the latest API | ||
+ | * the [[AUR]] also contains older APIs[https://aur.archlinux.org/packages/?K=android-platform-] | ||
+ | |||
+ | ==== Android System Images ==== | ||
+ | |||
+ | Install the desired [https://aur.archlinux.org/packages/?K=android-+system+image Android system image] package from the [[AUR]]. The Images are needed for emulating a specific android device. They are not needed if you want to develop with an android phone. | ||
+ | |||
+ | === Other IDEs === | ||
+ | |||
+ | Android Studio is the official Android development environment based on IntelliJ IDEA. Alternatively, you can use [[Netbeans]] with the NBAndroid plugin. All are described below. | ||
+ | |||
+ | ==== Netbeans ==== | ||
− | + | If you prefer using [[Netbeans]] as your IDE and want to develop Android applications, download the [http://www.nbandroid.org NBAndroid] by going to ''Tools > Plugins > Settings''. | |
− | + | Add the following URL: http://nbandroid.org/release81/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 ({{ic|/opt/android-sdk}} by default). That is it, now you can create a new Android project and start developing using Netbeans. | |
==== Eclipse ==== | ==== Eclipse ==== | ||
− | |||
− | + | {{Note|The Eclipse ADT plugin is no longer supported. Google recommends to use Android Studio instead.[https://android-developers.googleblog.com/2016/11/support-ended-for-eclipse-android.html]}} | |
− | |||
− | + | The official, but deprecated, [http://developer.android.com/sdk/eclipse-adt.html Eclipse ADT] plugin can be installed with the {{AUR|eclipse-android}} package. | |
− | |||
− | |||
− | |||
{{Note| | {{Note| | ||
Line 88: | Line 118: | ||
* as an alternative, you can install the ADT via eclipse's built in "add new software" command (see instructions on ADT site). | * as an alternative, you can install the ADT via eclipse's built in "add new software" command (see instructions on ADT site). | ||
* if you are in real trouble, it is also possible to download Android SDK and use the bundled Eclipse. This usually works without problems. | * if you are in real trouble, it is also possible to download Android SDK and use the bundled Eclipse. This usually works without problems. | ||
− | * if you need to install extra SDK plugins not found in the AUR, you must change the file ownership of /opt/ | + | * 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). |
}} | }} | ||
− | Enter the path to the Android SDK Location in | + | Enter the path to the Android SDK Location in ''Windows > Preferences > Android''. |
− | + | {{Note|If the plugins do not 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.}} | |
− | === | + | === Android Debug Bridge === |
− | |||
− | + | {{Tip| | |
+ | * For some devices, you may have to enable MTP on the device, before ADB will work. Some other devices require enable PTP mode to work. | ||
+ | * Many devices' udev rules are included in {{Pkg|libmtp}}, so if you have this installed, the following steps may not be necessary. | ||
+ | * Make sure your USB cable is capable of both charge and data. Many USB cables bundled with mobile devices do not include the USB data pin. | ||
+ | }} | ||
− | + | ==== Connect device ==== | |
− | + | To connect to a real device or phone via ADB under Arch, you must: | |
− | if you | + | # Install {{Pkg|android-tools}}. In addition, you might want to install {{Pkg|android-udev}} if you wish to connect the device to the proper {{ic|/dev/}} entries. |
+ | # plug in your android device via USB. | ||
+ | # Enable USB Debugging on your phone or device: | ||
+ | #* Jelly Bean (4.2) and newer: Go to ''Settings > About Phone'' tap ''Build Number'' 7 times until you get a popup that you have become a developer. Then go to ''Settings > Developer > USB debugging'' and enable it. The device will ask to allow the computer with its fingerprint to connect. allowing it permanent will copy {{ic|$HOME/.android/adbkey.pub}} onto the devices {{ic|/data/misc/adb/adb_keys}} folder. | ||
+ | #* 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. | ||
− | + | If [[#Detect the device|ADB recognizes your device]] ({{ic|adb devices}} shows it as {{ic|"device" and not as "unauthorized"}}, or 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 | vendor id: 0bb4 | ||
product id: 0c8d | product id: 0c8d | ||
Plug in your device and execute: | Plug in your device and execute: | ||
+ | |||
$ lsusb | $ lsusb | ||
It should come up something like this: | It should come up something like this: | ||
+ | |||
Bus 002 Device 006: ID 0bb4:0c8d High Tech Computer Corp. | Bus 002 Device 006: ID 0bb4:0c8d High Tech Computer Corp. | ||
==== Adding udev Rules ==== | ==== Adding udev Rules ==== | ||
− | |||
− | {{hc|/etc/udev/rules.d/51-android.rules|2=<nowiki>SUBSYSTEM=="usb", ATTR{idVendor}=="[VENDOR ID]", MODE=" | + | Use the rules from {{Pkg|android-udev}} (or {{Aur|android-udev-git}}), install them manually from [https://source.android.com/source/initializing#configuring-usb-access Android developer], or use the following template for your [[udev rules]], just replace {{ic|[VENDOR ID]}} and {{ic|[PRODUCT ID]}} with yours. Copy these rules into {{ic|/etc/udev/rules.d/51-android.rules}}: |
+ | |||
+ | {{hc|/etc/udev/rules.d/51-android.rules|2=<nowiki> | ||
+ | SUBSYSTEM=="usb", ATTR{idVendor}=="[VENDOR ID]", MODE="0660", 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_adb" | ||
− | SUBSYSTEM=="usb",ATTR{idVendor}=="[VENDOR ID]",ATTR{idProduct}=="[PRODUCT ID]",SYMLINK+="android_fastboot"</nowiki>}} | + | SUBSYSTEM=="usb",ATTR{idVendor}=="[VENDOR ID]",ATTR{idProduct}=="[PRODUCT ID]",SYMLINK+="android_fastboot" |
+ | </nowiki>}} | ||
Then, to reload your new udev rules, execute: | Then, to reload your new udev rules, execute: | ||
+ | |||
# udevadm control --reload-rules | # udevadm control --reload-rules | ||
+ | |||
+ | Make sure you are member of {{ic|adbusers}} [[group]] to access {{ic|adb}} devices. | ||
==== Configuring adb ==== | ==== Configuring adb ==== | ||
− | |||
− | + | Instead of using udev rules, you may create/edit {{ic|~/.android/adb_usb.ini}} which contains a list of vendor IDs. | |
− | |||
− | ==== | + | {{hc|~/.android/adb_usb.ini| |
+ | 0x27e8 | ||
+ | }} | ||
+ | |||
+ | ==== Detect the device ==== | ||
After you have setup the udev rules, unplug your device and replug it. | After you have setup the udev rules, unplug your device and replug it. | ||
After running: | After running: | ||
+ | |||
$ adb devices | $ adb devices | ||
you should see something like: | you should see something like: | ||
+ | |||
List of devices attached | List of devices attached | ||
HT07VHL00676 device | HT07VHL00676 device | ||
− | + | ==== General usage ==== | |
+ | |||
+ | 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>'' | ||
+ | |||
+ | ==== Notes & Troubleshooting ==== | ||
− | + | * '''ADB''' can also be installed via [[#Android SDK platform API|platform tools]] (usually available in {{ic|/opt/android-sdk/platform-tools/}}), so it might not be necessary to install {{Pkg|android-tools}} (available in {{ic|/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 {{ic|???????? no permissions}} under devices, try restarting the adb server as root. |
− | |||
# adb kill-server | # adb kill-server | ||
# adb start-server | # adb start-server | ||
− | + | * On Moto E, the device could have a different vendor/product ID in the sideload and fastboot modes; if you get the "no permission" error, verify the device's ID with {{ic|lsusb}}. | |
− | + | === 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 [http://developer.nvidia.com/category/zone/mobile-development NVIDIA Developer Zone for Mobile] there are two tools: | |
− | + | # 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. | |
− | + | # The [http://developer.nvidia.com/tegra-resources 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 == | == Building Android == | ||
− | To build | + | Please note that these instructions are based on the [https://source.android.com/source/building official AOSP build instructions]. Other Android-derived systems such as LineageOS will often require extra steps. |
+ | |||
+ | === Required packages === | ||
+ | |||
+ | To build any version of Android, you need to install these packages: | ||
+ | |||
+ | * {{Pkg|lib32-gcc-libs}} {{Pkg|git}} {{Pkg|gnupg}} {{Pkg|flex}} {{Pkg|bison}} {{Pkg|gperf}} {{Pkg|sdl}} {{Pkg|wxgtk2}} {{Pkg|squashfs-tools}} {{Pkg|curl}} {{Pkg|ncurses}} {{Pkg|zlib}} {{Pkg|schedtool}} {{Pkg|perl-switch}} {{Pkg|zip}} {{Pkg|unzip}} {{Pkg|libxslt}} {{Pkg|python2-virtualenv}} {{Pkg|bc}} {{Pkg|rsync}} {{Aur|ncurses5-compat-libs}} {{Pkg|lib32-zlib}} {{Pkg|lib32-ncurses}} {{Pkg|lib32-readline}} {{Aur|lib32-ncurses5-compat-libs}} | ||
+ | |||
+ | The {{Aur|aosp-devel}} metapackage provides them all for simple installation. | ||
+ | |||
+ | {{Note|The PGP signatures for {{Aur|ncurses5-compat-libs}} and {{Aur|lib32-ncurses5-compat-libs}} may cause errors, that can be solved by manually importing the needed signature: | ||
+ | |||
+ | $ gpg --recv-keys 702353E0F7E48EDB | ||
+ | |||
+ | }} | ||
+ | |||
+ | Additionally, LineageOS requires the following packages: {{AUR|xml2}}, {{Pkg|lzop}}, {{Pkg|pngcrush}}, {{Pkg|imagemagick}} | ||
+ | |||
+ | They can be installed with the {{Aur|lineageos-devel}} metapackage. | ||
+ | |||
+ | {{Accuracy|The note below is not clear and probably incomplete.}} | ||
+ | {{Note|1=Installing both {{Pkg|maven}} and {{Pkg|gradle}} to build LineageOS may result in a build speed improvement as the build process will prefer the system's }} | ||
+ | |||
+ | === Java Development Kit === | ||
+ | |||
+ | The [https://source.android.com/source/requirements required JDK version] depends on the Android version you are building: | ||
+ | |||
+ | * For Android 7 and 8 (Nougat and Oreo), OpenJDK 8 is required, which is available with the {{Pkg|jdk8-openjdk}} package. | ||
+ | * For Android 5 and 6 (Lollipop and Marshmallow), OpenJDK 7 is required, which is available with the {{Pkg|jdk7-openjdk}} package. | ||
− | + | 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 {{AUR|jdk6}} from the AUR. |
+ | * For Cupcake through Froyo (1.5 - 2.2), Java 5 is required, which is available as {{AUR|jdk5}} from the AUR. | ||
− | + | {{Note|1= | |
+ | Android expects Java in {{ic|/usr/lib/jvm/java-''version''-openjdk-amd64}}. | ||
+ | Set JAVA_HOME to avoid this requirement and match the Arch Linux installation path. | ||
+ | Example: | ||
− | + | $ export JAVA_HOME=/usr/lib/jvm/java-''version''-openjdk | |
− | + | This change will be valid only for the current terminal session. | |
− | + | }} | |
− | + | === Setting up the build environment === | |
− | + | [[Install]] the {{Pkg|repo}} package. | |
− | |||
− | |||
− | |||
Create a directory to build. | Create a directory to build. | ||
Line 202: | Line 285: | ||
$ cd ~/android | $ cd ~/android | ||
− | + | The Android build process expects {{ic|python}} to be python2. Create a python2 virtual environment and activate it: | |
+ | |||
+ | $ virtualenv2 venv | ||
+ | $ source venv/bin/activate | ||
+ | |||
+ | {{Note| | ||
+ | * This activation is only active for the current terminal session. The virtual env will be kept in the {{ic|venv}} folder. | ||
+ | * 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/lib/python2.7/ (Change ~/android to reflect your build directory if different than above). | ||
+ | Example: | ||
+ | |||
+ | $ ln -s /usr/lib/python2.7/* ~/android/venv/lib/python2.7/ | ||
+ | |||
+ | or (assuming build directory Data/Android_Build): | ||
+ | |||
+ | $ ln -s /usr/lib/python2.7/* /Data/Android_Build/venv/lib/python2.7/ | ||
+ | |||
+ | }} | ||
+ | |||
+ | === 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 {{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. | ||
+ | |||
+ | * 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'''. | ||
+ | |||
+ | <pre> | ||
+ | $ repo init -u https://android.googlesource.com/platform/manifest -b master | ||
+ | $ repo sync -j4 | ||
+ | </pre> | ||
+ | |||
+ | {{Note|To further decrease sync times, you can utilize the -c switch with the repo command as such: | ||
+ | |||
+ | $ repo sync -j8 -c | ||
+ | |||
+ | The {{ic|-c}} switch will only sync the branch which is specified in the manifest, which in turn is determined by the branch specified with the {{ic|-b}} switch, or the default branch set by the repository maintainer. | ||
+ | }} | ||
+ | |||
+ | 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. As of Android 6.0.1, the entire codebase totals 40 GB. | ||
+ | |||
+ | {{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 | $ repo sync | ||
− | + | }} | |
− | + | === Building the code === | |
+ | |||
+ | This should do what you need for AOSP: | ||
$ source build/envsetup.sh | $ source build/envsetup.sh | ||
Line 215: | Line 339: | ||
$ make -j4 | $ make -j4 | ||
− | If you run '''lunch''' without arguments, it will ask what build you want to create. Use -j with a number between | + | 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 | + | The build takes a very long time. |
− | {{Note|Make sure you have enough RAM. | + | {{Note| |
− | 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. | + | * Make sure you have enough RAM. Android will use the {{ic|/tmp}} directory heavily. By default the size of the partition the {{ic|/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. Alternatively, you can get rid of the tmpfs from [[fstab]] all together. |
− | + | * From the [https://source.android.com/source/building#build-the-code Android Building and Running guide]: | |
+ | "GNU make can handle parallel tasks with a {{ic|-jN}} argument, and it's common to use a number of tasks N that's between 1 and 2 times the number of hardware threads on the computer being used for the build. E.g. on a dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core), the fastest builds are made with commands between {{ic|make -j16}} and {{ic|make -j32}}." | ||
}} | }} | ||
− | When finished, run the final image. | + | === Testing the build === |
+ | |||
+ | When finished, run/test the final image(s). | ||
$ emulator | $ 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 {{ic|'''out/target/product/hammerhead'''}} (hammerhead being the device name) that can be flashed. | ||
+ | |||
+ | == Restoring Android == | ||
+ | |||
+ | {{Expansion}} | ||
+ | |||
+ | 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 [http://forum.xda-developers.com/ XDA forums]. | ||
+ | |||
+ | === Fastboot === | ||
+ | |||
+ | Fastboot (as well as [[#Android Debug Bridge|ADB]]) is included in the {{Pkg|android-tools}} package. | ||
+ | |||
+ | {{Note|Restoring firmwares using {{ic|fastboot}} can be quite tricky, but you might want to browse [http://www.xda-developers.com/ XDA developers forums] for a stock firmware, which is mostly a {{ic|*.zip}} file, but inside of it, comes with the firmware files and {{ic|flash-all.sh}} script. For example, [https://developers.google.com/android/nexus/images Google Nexus] firmwares include {{ic|flash-all.sh}} script or another example could be for OnePlus One - [http://forum.xda-developers.com/oneplus-one/general/guide-return-opo-to-100-stock-t2826541 XDA thread], where you can find firmwares with included {{ic|flash-all.sh}} script.}} | ||
+ | |||
+ | === Samsung devices === | ||
+ | |||
+ | Samsung devices can't be flashed using '''Fastboot''' tool. Alternatives are only '''Heimdall''' and '''Odin''' (by using Windows and VirtualBox). | ||
+ | |||
+ | ==== Heimdall ==== | ||
+ | |||
+ | [http://glassechidna.com.au/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 [http://odindownload.com/ Odin]. It can be installed as {{AUR|heimdall}}. | ||
+ | |||
+ | The flashing instructions can be found on Heimdall's [https://github.com/Benjamin-Dobell/Heimdall/tree/master/Linux GitHub page] or on [http://forum.xda-developers.com/showthread.php?t=1922461 XDA forums]. | ||
+ | |||
+ | ==== Odin (Virtualbox) ==== | ||
+ | |||
+ | {{Note|1=This section only covers preparation and '''not''' flashing instructions. Search [http://www.xda-developers.com XDA developers forums] to find a flashing instructions for specific device. For example, [https://forum.xda-developers.com/showthread.php?t=2265477 Samsung Galaxy S4].}} | ||
+ | |||
+ | It is also possible to restore [http://www.sammobile.com/firmwares/ firmware (Android)] on the Samsung devices using [http://odindownload.com/ Odin], but inside the [[VirtualBox]]. | ||
+ | |||
+ | Arch Linux (host) preparation: | ||
+ | |||
+ | # Install [[VirtualBox]] together with its [[VirtualBox#Extension_pack|extension pack]] and [[VirtualBox#Guest_additions_disc|guest additions]]. | ||
+ | # Install your preferred, but compatible with Odin, Windows operating system (with VirtualBox guest additions) into a virtual hard drive using VirtualBox. | ||
+ | # 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'''. | ||
+ | # 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: | ||
+ | |||
+ | # Install [http://androidxda.com/download-samsung-usb-drivers Samsung drivers]. | ||
+ | # Install [http://odindownload.com/ Odin]. | ||
+ | # Download required [http://www.sammobile.com/firmwares/ Samsung firmware (Android)] for your smartphone model. | ||
+ | |||
+ | Check if configuration is working: | ||
+ | |||
+ | # Turn your device into Download mode and connect to your Linux machine. | ||
+ | # In virtual machine toolbar, select ''Devices > USB > ...Samsung...'' device. | ||
+ | # 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. | ||
+ | |||
+ | == Connection software == | ||
+ | |||
+ | * [https://github.com/google/adb-sync adb-sync] (available as {{AUR|adb-sync-git}}) – a tool to synchronize files between a PC and an Android device using the ADB protocol. | ||
+ | * [http://xsavikx.github.io/AndroidScreencast AndroidScreencast] (available as {{aur|androidscreencast-bin}}) – view and control your Android device from a PC (via ADB). | ||
+ | * {{Pkg|kdeconnect}} – integrates your Android device with the KDE desktop (featuring synced notifications & clipboard, multimedia control, and file/URL sharing). | ||
+ | * {{AUR|sendanywhere}} – cross-platform file sharing | ||
== Tips & Tricks == | == Tips & Tricks == | ||
+ | |||
=== During Debugging "Source not found" === | === 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: | + | |
− | + | 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 | 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 === | === Linux distribution on the sdcard === | ||
+ | |||
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]. | 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]. | ||
− | === Android | + | == Troubleshooting == |
− | + | ||
− | + | === Android Studio: Android Virtual Devices show 'failed to load'. === | |
− | + | ||
+ | Make sure you've exported the variable {{ic|ANDROID_HOME}} 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 {{Pkg|lib32-gcc-libs}} package from the [[Multilib]] repository. | ||
+ | |||
+ | === 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 -exec rm {} + | ||
+ | |||
+ | === libGL error: failed to load driver: swrast OR AVD doesn't 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 {{ic|~/.android-sdk/emulator/lib64}} (for 64-bit) or {{ic|~/.android-sdk/emulator/lib}} (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: [https://developer.android.com/studio/command-line/variables.html#studio_jdk 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's 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 ({{Pkg|mesa-demos}}) 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. | ||
+ | ([https://issuetracker.google.com/issues/37094173 bug report]) | ||
− | + | You can use the workaround described in [https://stackoverflow.com/a/42720450/1366471 this Stack Overflow answer]: | |
− | |||
− | + | # Open the xfwm4 settings. | |
− | + | # Switch to the Focus tab. | |
+ | # Change the Focus Model to "Focus follow mouse". | ||
+ | # Disable ''Automatically raise windows when they receive focus'' option below. |
Latest revision as of 04:38, 25 March 2018
Contents
- 1 Exploring Android device
- 2 Android development
- 3 Building Android
- 4 Restoring Android
- 5 Connection software
- 6 Tips & Tricks
- 7 Troubleshooting
- 7.1 Android Studio: Android Virtual Devices show 'failed to load'.
- 7.2 Android Studio: 'failed to create the SD card'
- 7.3 ValueError: unsupported pickle protocol
- 7.4 libGL error: failed to load driver: swrast OR AVD doesn't load and no error message displayed
- 7.5 sh: glxinfo: command not found
- 7.6 Android Emulator: no keyboard input in xfwm4
Exploring Android device
When you connect a modern Android device via USB to a computer you can use the Media Transfer Protocol to transfer files and #Android Debug Bridge to debug it.
Files can generally be transferred with various protocols (SSH, FTP, Samba, HTTP). You just need to setup a client and a server (via apps Android can act as either one).
For flashing and restoring Android firmware see #Restoring Android.
See #Connection software for software available for Arch Linux that can be used to connect to Android.
Android development
To develop Android applications you need three things:
- the Android SDK core component
- one or several Android SDK Platform packages
- an IDE
The official IDE for Android is #Android Studio, which comes with its own SDK manager.
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. If you get an error about a missing SDK, refer to #Android SDK platform API.
- If you are using a tiling window manager other than i3, you may need to apply one of the fixes mentioned in this issue page.
- Make sure you properly set the Java environment otherwise android-studio will not start.
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
Manual SDK installation
If you are using #Android Studio and want the IDE to manage your SDK installation, you can skip this section.
Android SDK core components
error: target not found: lib32-*
error messages.Before developing Android applications, you need to install the Android SDK, which is made of 4 distinct packages, all installable from AUR:
If supporting older devices, or working with older code, android-supportAUR and android-support-repositoryAUR might be required.
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 modify anything in this directory. If you intend to use it as a regular user, create the Android sdk users group:
# 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/
Re-login or as <user> log your terminal in to the newly created group:
$ newgrp sdkusers
Android SDK platform API
Install the desired Android SDK Platform package from the AUR:
- android-platformAUR – the latest API
- the AUR also contains older APIs[1]
Android System Images
Install the desired Android system image package from the AUR. The Images are needed for emulating a specific android device. They are not needed if you want to develop with an android phone.
Other IDEs
Android Studio is the official Android development environment based on IntelliJ IDEA. Alternatively, you can use Netbeans with the NBAndroid plugin. All are described below.
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/release81/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.
Eclipse
The official, but deprecated, Eclipse ADT plugin can be installed with the eclipse-androidAUR package.
- if you get a message about unresolvable dependencies, install Java manually and try again.
- as an alternative, you can install the ADT via eclipse's built in "add new software" command (see instructions on ADT site).
- if you are in real trouble, it is also possible to download Android SDK and use the bundled Eclipse. This usually works without problems.
- 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
# chgrp -R users /opt/android-sdk ; chmod -R 0775 /opt/android-sdk
(see File Permissions for more details).
Enter the path to the Android SDK Location in Windows > Preferences > Android.
sudo eclipse -clean
once should clear them. If the problem persists, uninstall eclipse and all the plugins, delete /usr/share/eclipse
, and reinstall everything.Android Debug Bridge
- For some devices, you may have to enable MTP on the device, before ADB will work. Some other devices require enable PTP mode to work.
- Many devices' udev rules are included in libmtp, so if you have this installed, the following steps may not be necessary.
- Make sure your USB cable is capable of both charge and data. Many USB cables bundled with mobile devices do not include the USB data pin.
Connect device
To connect to a real device or phone via ADB under Arch, you must:
- Install android-tools. In addition, you might want to install android-udev if you wish to connect the device to the proper
/dev/
entries. - plug in your android device via USB.
- Enable USB Debugging on your phone or device:
- Jelly Bean (4.2) and newer: Go to Settings > About Phone tap Build Number 7 times until you get a popup that you have become a developer. Then go to Settings > Developer > USB debugging and enable it. The device will ask to allow the computer with its fingerprint to connect. allowing it permanent will copy
$HOME/.android/adbkey.pub
onto the devices/data/misc/adb/adb_keys
folder. - 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 Settings > About Phone tap Build Number 7 times until you get a popup that you have become a developer. Then go to Settings > Developer > USB debugging and enable it. The device will ask to allow the computer with its fingerprint to connect. allowing it permanent will copy
If ADB recognizes your device (adb devices
shows it as "device" and not as "unauthorized"
, or 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-udev (or android-udev-gitAUR), install them manually from Android developer, or 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="0660", 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
Make sure you are member of adbusers
group to access adb
devices.
Configuring adb
Instead of using udev rules, you may create/edit ~/.android/adb_usb.ini
which contains a list of vendor IDs.
~/.android/adb_usb.ini
0x27e8
Detect the device
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
General usage
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>
Notes & Troubleshooting
- ADB can also be installed via platform tools (usually available in
/opt/android-sdk/platform-tools/
), so it might not be necessary to install 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
- On Moto E, the device could have a different vendor/product ID in the sideload and fastboot modes; if you get the "no permission" error, verify the device's ID with
lsusb
.
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 LineageOS will often require extra steps.
Required packages
To build any version of Android, you need to install these packages:
- lib32-gcc-libs git gnupg flex bison gperf sdl wxgtk2 squashfs-tools curl ncurses zlib schedtool perl-switch zip unzip libxslt python2-virtualenv bc rsync ncurses5-compat-libsAUR lib32-zlib lib32-ncurses lib32-readline lib32-ncurses5-compat-libsAUR
The aosp-develAUR metapackage provides them all for simple installation.
$ gpg --recv-keys 702353E0F7E48EDB
Additionally, LineageOS requires the following packages: xml2AUR, lzop, pngcrush, imagemagick
They can be installed with the lineageos-develAUR metapackage.
Java Development Kit
The required JDK version depends on the Android version you are building:
- For Android 7 and 8 (Nougat and Oreo), OpenJDK 8 is required, which is available with the jdk8-openjdk package.
- For Android 5 and 6 (Lollipop and Marshmallow), OpenJDK 7 is required, which is available with the jdk7-openjdk package.
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.
- For Cupcake through Froyo (1.5 - 2.2), Java 5 is required, which is available as jdk5AUR from the AUR.
/usr/lib/jvm/java-version-openjdk-amd64
.
Set JAVA_HOME to avoid this requirement and match the Arch Linux installation path. Example:
$ export JAVA_HOME=/usr/lib/jvm/java-version-openjdkThis change will be valid only for the current terminal session.
Setting up the build environment
Create a directory to build.
$ mkdir ~/android $ cd ~/android
The Android build process expects python
to be python2. Create a python2 virtual environment and activate it:
$ virtualenv2 venv $ source venv/bin/activate
- This activation is only active for the current terminal session. The virtual env will be kept in the
venv
folder. - 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/lib/python2.7/ (Change ~/android to reflect your build directory if different than above).
Example:
$ ln -s /usr/lib/python2.7/* ~/android/venv/lib/python2.7/
or (assuming build directory Data/Android_Build):
$ ln -s /usr/lib/python2.7/* /Data/Android_Build/venv/lib/python2.7/
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
$ repo sync -j8 -c
The -c
switch will only sync the branch which is specified in the manifest, which in turn is determined by the branch specified with the -b
switch, or the default branch set by the repository maintainer.
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. As of Android 6.0.1, the entire codebase totals 40 GB.
$ 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.
- Make sure you have enough RAM. 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. Alternatively, you can get rid of the tmpfs from fstab all together. - From the Android Building and Running guide:
"GNU make can handle parallel tasks with a -jN
argument, and it's common to use a number of tasks N that's between 1 and 2 times the number of hardware threads on the computer being used for the build. E.g. on a dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core), the fastest builds are made with commands between make -j16
and make -j32
."
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) is included in the android-tools package.
fastboot
can be quite tricky, but you might want to browse XDA developers forums for a stock firmware, which is mostly a *.zip
file, but inside of it, comes with the firmware files and flash-all.sh
script. For example, Google Nexus firmwares include flash-all.sh
script or another example could be for OnePlus One - XDA thread, where you can find firmwares with included flash-all.sh
script.Samsung devices
Samsung devices can't be flashed using Fastboot tool. Alternatives are only Heimdall and Odin (by using Windows and VirtualBox).
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 heimdallAUR.
The flashing instructions can be found on Heimdall's GitHub page 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:
- Install VirtualBox together with its extension pack and guest additions.
- Install your preferred, but compatible with Odin, Windows operating system (with VirtualBox guest additions) into a virtual hard drive using VirtualBox.
- 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.
- 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:
- Install Samsung drivers.
- Install Odin.
- Download required Samsung firmware (Android) for your smartphone model.
Check if configuration is working:
- Turn your device into Download mode and connect to your Linux machine.
- In virtual machine toolbar, select Devices > USB > ...Samsung... device.
- 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.
Connection software
- adb-sync (available as adb-sync-gitAUR) – a tool to synchronize files between a PC and an Android device using the ADB protocol.
- AndroidScreencast (available as androidscreencast-binAUR) – view and control your Android device from a PC (via ADB).
- kdeconnect – integrates your Android device with the KDE desktop (featuring synced notifications & clipboard, multimedia control, and file/URL sharing).
- sendanywhereAUR – cross-platform file sharing
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
Android Studio: Android Virtual Devices show 'failed to load'.
Make sure you've exported the variable ANDROID_HOME
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 lib32-gcc-libs package from the Multilib repository.
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 -exec rm {} +
libGL error: failed to load driver: swrast OR AVD doesn't 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 ~/.android-sdk/emulator/lib64
(for 64-bit) or ~/.android-sdk/emulator/lib
(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's 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-demos) 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 this Stack Overflow answer:
- Open the xfwm4 settings.
- Switch to the Focus tab.
- Change the Focus Model to "Focus follow mouse".
- Disable Automatically raise windows when they receive focus option below.