Getting code and setting up system, as well as writing code - android

I need help on setting up my system to develop the Android OS (not apps the OS). I have an Ubuntu machine running 10.10, but I'm stuck on preparing my system and actually getting the code. What programs do I use? And what kind of things do I need to type to write the code?

This handy guide will walk you through setting up your system.
In general, you will need to install:
Git
Python 2.4
JDK 5 (froyo or older) or JDK 6 (gingerbread or newer)
What programs do I use?
Eclipse seems to be the most popular IDE for working with Android. Personally, I like using a plain old editor (emacs, vi, kate, etc.) and a terminal window.

Here is my setup:
Android SDK unzipped to ~/sdk/
Add ~/sdk/android-sdk-linux_x86/tools and ~/sdk/android-sdk-linux_x86/platform-tools to your path:
echo "PATH=$PATH:~/sdk/android-sdk-linux_x86/tools:~/sdk/android-sdk-linux_x86/platform-tools" >> ~/.profile
install sun-java6-jdk. first enable the partner repository.
sudo apt-get install sun-java6-jdk
install ant
sudo apt-get install ant
you'll have to choose an editor. if you like gedit, I suggest adding the ubuntu-on-rails ppa (http://www.webupd8.org/2010/12/get-textmate-features-and-styles-in.html) and installing gedit-gmate. if you're a vim person, I suggest install vim-scripts
To support your real phone you may need to create a udev rules file. Google 'android ubuntu udev your-phone-model' for help. For instance, for a nexus one you would:
- add /etc/udev/rules.d/51-android.rules with one line:
SUBSYSTEM=="usb", SYSFS{idVendor}=="18D1", MODE="0666"
After all of that, http://android.developer.com is your best friend.

Related

Android emulator no sound in ubuntu

I am running android emulator in ubuntu-19.10 and I have attempted following solutions with no results,
Link-1
Link-2
Link-3
Error,
1:10 PM Emulator: pulseaudio: pa_context_connect() failed
1:10 PM Emulator: pulseaudio: Reason: Connection refused
1:10 PM Emulator: pulseaudio: Failed to initialize PA contextaudio: Could not init `pa' audio driver
Some notes on solution I tried,
When trying Link-1 i don't see "Qemu-system" in settings. Also created many different versions of AVDs but does seem to work.
After trying Link-2 pulseaudio -D command errors out.
I have also tried Link-3 which looks like widely suggested solution in multiple blog posts. But still I find the same error on emulator startup. I would like to note that I am not smart enough understand this solution.
Thanks in advance for helping out.
Same problem in Ubuntu 20.04, with Android Studio installed from Ubuntu Software. Tried everything (paprefs, this), nothing worked. Uninstall Android Studio Snap and reinstall from tar package downloaded from Android Studio website, works perfect.
I was having a similar issue on Ubuntu 20.04 but I fixed it by uninstalling the store version of Android Studio and following the installation instructions on the Official Android Studio website here: https://developer.android.com/studio/install
If you are running a 64-bit version of Ubuntu, you need to install some 32-bit libraries with the following command:
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
lib32z1 libbz2-1.0:i386
To install Android Studio on Linux, proceed as follows:
Unpack the .zip file you downloaded to an appropriate location for your applications, such as within /usr/local/ for your user profile, or /opt/ for shared users.
If you're using a 64-bit version of Linux, make sure you first install the required libraries for 64-bit machines.
To launch Android Studio, open a terminal, navigate to the android-studio/bin/ directory, and execute studio.sh.
Select whether you want to import previous Android Studio settings or not, then click OK.
The Android Studio Setup Wizard guides you through the rest of the setup, which includes downloading Android SDK components that are required for development.
I had the same issue, runing Intellij on Ubuntu 20.04. I solved it by adapting a solution from this link
I run this:
sudo ln -s /run/user/1000/pulse/native /run/user/1000/snap.intellij-idea-community/pulse
If you're using Android studio, just try to find "snap.intellij-idea-community" will be named differently, referring to your android studio installation.
On Ubuntu, is possible open the emulator with terminal and change the sound in System Preferences. Works with the instant version of Android Studio. It works with the snap version of Android Studio.
First is needed to add the emulator command to the PATH.
This can be done by editing .bashrc or .zshrc. Preferably these lines should be placed at the end of the file.
export ANDROID_SDK_PATH=$HOME/Android/Sdk
export ANDROID_NDK_PATH=$HOME/Android/Sdk/ndk
export PATH="$PATH:$HOME/Android/Sdk/platform-tools"
export PATH="$PATH:$HOME/Android/Sdk/emulator"
The PATH variable needs to be reloaded. This can be done manually, as shown below, or simply by opening another terminal:
source ~/.bashrc
# OR
source ~/.zshrc
Another way is to add adb and android-sdk-platform-tools-common packages to have the emulator command available. Package names may vary depending on the Ubuntu version.
After that, the emulator command can be used to list available emulators:
emulator -list-avds
Example of output:
Pixel_4_API_30
Pixel_C_API_30
Then can be opened one of the available emulators:
emulator #Pixel_4_API_30
Finally, the emulator probably will appear at the System Preferences:
If this is a Snap it's got strict requirements as far as i/o; that said, if the requirements are similar to those of running Androidx86 using Vbox on Debian (I realize Qemu is a different environment, however, this may be of use for both Jbaba as well as future reference. Step one: make sure that you belong to the group Qemu (or the equivalent for Ubuntu/Snap?). Step two: make sure you belong to the group pulseaudio. Step three: make sure that Qemu is explicitly permitted to access whatever your audio output device is and that it's the device that pulseaudio is configured to output to. There should be a fairly intuitive way of seeing this using Qemu (it's been awhile, so I am not able to tell you where to find it). As for pulseaudio; its GUI will show you.
I got crazy while trying to solve this issue but finally, it was solved. I figured out that we have to enable multiple simultaneous audio outputs in order to hear both sounds the emulator and the OS.
The solution is by installing paprefs small app as the following.
1- Install it:
$ sudo apt install paprefs
2- Open it:
$ paprefs
3- Go to the last tab Simultaneous Output and click on the only option there in order to enable the Simultaneous Output.
4- Restart it:
$ pulseaudio -k
5- If it fails then you have to restart the daemon
$ pulseaudio -D
6- Almost finished, go to the system settings and navigate to Sounds options and change the output sounds to the newly added one as below.
OS : Ubuntu 20.04.
Android studio (snap).
I tried all the methods, none worked for me.
By installing these libs, the sound works now.
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
as Gigi mentionned before

Emulator on Android Studio doesn't start after SDK tools update to 25.3.1

After updating my Android SDK tools today to 25.3.1, the emulator won't run anymore.
I can open the AVD Manager. When I hit "Play" on one of the emulators on the list, I see the bar below on Android Studio
But then after the progress bar reaches the end, nothing happens.
I see in the release notes that the latest update brought changes to the emulator so I'm wondering if that's a bug or I'm missing something about that.
I'm using Android Studio 2.3.
Any ideas?
I ran into the same problem after upgrading. I can't figure out what's causing the configuration problem but I did figure out a workaround.
First, I tried to launch the emulator from the command line:
$ emulator #<name_avd_image>
emulator: ERROR: This AVD's configuration is missing a kernel file! Please ensure the file "kernel-ranchu" is in the same location as your system image.
emulator: ERROR: ANDROID_SDK_ROOT is defined (<android>/sdk) but cannot find kernel file in <android>/sdk/system-images/ sub directories
You can get more information if you run emulator with the -verbose flag. I tried re-installing the system image (e.g. Android API 25 x86 w/ Google APIs), Android Emulator 25.3.1, and re-creating the AVD but nothing worked.
Finally as a workaround, I just copied all of the system files from the SDK system images directory into the AVD directory:
Example: Pixel XL (Android API 25 x86 w/ Google APIs)
SOURCE: <android>/sdk/system-images/android-25/google_apis/x86/
DESTINATION: ~/.android/avd/Pixel_XL_API_25.avd/
After that the emulator started right up. It's not ideal, but this was blocking my development so I had to get the emulator up and running again. I hope someone else will be able to figure out what broke in the configuration.
UPDATE: Figured out the configuration problem!
I noticed I periodically was seeing the console error "Your emulator is out of date, please update by launching Android Studio:" so I decided to check:
$ which emulator
<$ANDROID_SDK_ROOT>/tools/emulator
With help from this thread:
The problem is there are two emulators: one in
$ANDROID_SDK_ROOT/tools, another one in
$ANDROID_SDK_ROOT/emulator. The one in $ANDROID_SDK_ROOT/tools
cannot start. Place $ANDROID_SDK_ROOT/emulator before
$ANDROID_SDK_ROOT/tools in your $PATH variable, it should fix the
problem.
NOTE: For most Mac users, you can edit your ~/.bash_profile to change these settings and then run $source ~/.bash_profile to load the updates. In my particular case, I also had old values for $ANDROID_HOME that I had to clear out.
The real problem, at least over Ubuntu 16.10 and 17.04 and Andoid Studio 2.4 Preview 7 (but could happen with any Debian derivative and previous versions of Android Studio), is that Google is distributing a non working libstdc++ library with the emulator tools. They're distributing 6.0.18 version, but i found that the working one is 6.0.22.
EDIT: There are reports that 6.0.21 version of libstdc++ works as well as 6.0.22.
So, you have 2 options:
Option 1
rm the previous non working Google's libs in /yoursdkpàth/emulator/lib64/libstdc++
Download and extract libs from libstdc++ official package in /yoursdkpàth/emulator/lib64/libstdc++
Don't try to install the .deb, extract the files/binaries from inside it (the 2 binaries are in a folder named "lib") and manuallly copy them on the recommended path.
Option 2
Create a simlink to the lib distributed with Ubuntu, which already is 6.0.22 version
cd ~/Android/Sdk/emulator/lib64/libstdc++/
mv libstdc++.so.6 libstdc++.so.6.bak
mv libstdc++.so.6.0.18 libstdc++.so.6.0.18.bak
ln -sf /usr/lib/x86_64-linux-gnu/libstdc++.so.6 ~/Android/Sdk/emulator/lib64/libstdc++/libstdc++.so.6
ln -sf /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 ~/Android/Sdk/emulator/lib64/libstdc++/libstdc++.so.6.0.22
IMPORTANT 1: As Google seems to be not aware of the problem, on every update they make to the Android Emulator package in Android Studio, they break the funcionality replacing your working SDK C++ libs with the broken/older ones. The solution is to repeat any of the above procedures.
IMPORTANT 2: This is only valid if your AVDs are configured for use your PC GPU as host for video accelaration (Hardware GLES 2.0). Selecting Sofware GLES 2.0 on your AVD will work without any of the suggested changes, but your emulator will turn painfully slow.
Have you check the Android emulator installed in the **SDK Tools?
Go to Setting-> sdk-tools.
See whether Android is installed or not.
I have face same problem. when I checked the SDK Tools, I found that the Android emulator was not installed.
The libstdc++.so.6 is the cause (as pointed out by #doruMarinau); Android Studio 2.3 moved the file to a new folder your_sdk/emulator/lib64.
If using Linux, create a symlink for it:
$ ln -sf /usr/lib/libstdc++.so.6 /your_sdk/emulator/lib64/libstdc++/libstdc++.so.6
The solution is:
Tools - Android - Sdk manager
tab Sdk tools
install emulator 25.3.1
This worked for me:
Go to AVD Manager, then, in the Actions column, click on the arrow that points dawn and select "Wipe Data".
After this, try to run the emulator.
It’s a libGL error and libstdc++ issue. Cannot launch AVD in emulator.
It’s a know bug and you can easily beat it with some simple steps.
I have tested this solution on a Ubuntu 16.10 64bit
Solution:
$adb kill-server
$adb start-server
After this start your emulator from the Android studio. If this doesn't work then go ahead for the next solution.
Alternative solution:
First, install some packages and libs:
$sudo apt-get install lib64stdc++6:i386
$sudo apt-get install mesa-utils
Second, tweak some links:
$ cd YOURPATH/Android/Sdk/tools/lib64
$ mv libstdc++/ libstdc++.bak
$ ln -s /usr/lib64/libstdc++.so.6 libstdc++
Third, relaunch your AVD device and test it.
Go to Sdk/emulator/lib64/libstdc++ move libstdc++.so.6 and libstdc++.so.6.0.18 to myfolder (I created this) (or any other location) as backup and copy libstdc++.so.6, libstdc++.so.6.0.21 from usr/lib64; try again to launch your virtual device.
It's been driving me nuts for the last few days. Here's what worked for me:
ANDROID_HOME, ANDROID_SDK_ROOT variables in "System Environment Variables" were different from Android Studio -> Settings -> Android SDK Location. So when I changed the environment variables, AVD started!
(After changed the environment variable, you should restart the Android Studio)
The only solution which worked for me, was to install following missing libraries:
$sudo apt-get install lib64stdc++6:i386
$sudo apt-get install mesa-utils
Once you have them, update the one there in sdk's emulator with these as following:
$ ln -sf /usr/lib/libstdc++.so.6 /home/[YOUR_SYSTEM_USERNAME]/emulator/lib64/libstdc++/libstdc++.so.6
Launch your emulator again and it will work just fine.
As of this release, the Android Emulator will be released separately from the SDK Tools.
so just install android Emulator using sdk tools in your android studio
My problem was ANDROID_SDK_HOME pointing to d:\.android instead of d:\. Could not find the images anymore.

Genymotion does not find VirtualBox when run from Android Studio

Using Ubuntu 16.04, Android Studio and Genymotion (latest versions).
Genymotion works perfectly when run directly, but does not work from Android Studio with the Genymotion plug-in installed. The error I get from Genymotion is "In order to work, Genymotion requires VirtualBox to be installed on your computer. You can download the latest version of VirtualBox from www.virtualbox.org/wiki/Downloads.".
Of course VirtualBox is installed. Even tried removing it and installing again (v. 5.1).
There is an odd issue with the Genymotion Android Studio plugin, which makes it impossible to start a device. This often manifests with genymotion.log containing error messages such as:
Output command: "/usr/lib/virtualbox/VBoxManage: ./libssl.so.1.0.0: version 'OPENSSL_1.0.2' not found (required by /usr/lib/x86_64-linux-gnu/libcurl.so.4)"
It comes from the fact that Android Studio defines LD_LIBRARY_PATH to be /android/studio/install/dir/bin:$LD_LIBRARY_PATH which becomes /android/studio/install/dir/bin: if LD_LIBRARY_PATH is not set. This causes VBoxManage to try to load the libssl.so shipped by Genymotion, which is too old for Ubuntu 16.04 (because when LD_LIBRARY_PATH ends with ":", the linker looks for libraries in the current directory)
You can do one of the following:
Edit studio.sh to stop adding a trailing ":" at the end of LD_LIBRARY_PATH (I can provide more details if needed)
Remove libssl.so and libcrypto.so from Genymotion install directory
Define LD_LIBRARY_PATH to some random value before starting Android Studio so that the LD_LIBRARY_PATH defined by studio.sh does end with ":"
Note that this has been fixed in Android Studio 3.1.
After visiting the Genymotion site, it might have something to do with the dkms package:
Make sure that the dkms package is installed and that it compiles VirtualBox kernel modules each time a new kernel update is available.
To do so, run sudo /etc/init.d/vboxdrv status.
You should get the message "VirtualBox kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) are loaded".
If not, force VirtualBox kernel modules compilation by running sudo /etc/init.d/vboxdrv setup.
Make also sure that you are part of the vboxusers group.
If not, run sudo usermod -a -G vboxusers <login>.
Maybe it is caused because of the dkms package is not updated, so you are not able to use Genymotion from Android Studio but only running it directly.
ok this took me some quality time to figure out take this step
locate your etc folder
cd into init.d
run virtualbox status:
if it tells you that you need to install dkms package. then on a new terminal
sudo apt-get install linux-headers-uname -r
sudo dpkg-reconfigure virtualbox-dkms
6.enter a password and renenter
then reboot and load to MOK(Your will get a blue screen that will ask to reload to MOK before rebooting)
Ok
your machine by now is rebooted
start your terminal go to etc/init.d
run virtualbox staus
I believe no errors
on a new terminal cd to your directory with genymotion
13.cd into genymotion
run ./genymotion
congrats

Android Studio: How to integrate Git from Windows 10 Ubuntu bash?

Yesterday I installed bash on Windows 10 and also installed Git on it. It works perfectly fine. Following that, I changed the path of the Terminal in Android Studio from "cmd.exe" to "bash.exe" so I can have the bash shell instead of the cmd shell. But now Android Studio cannot find Git (because on Windows it expects a Git.exe) and I would like to know if it is possible to integrate the bash git into Android Studio (just as it does with the Windows .exe version).
According to this article you are running a kind-of version of Linux. The article says it is a Windows Subsystem for Linux which is like the opposite of Wine.
Because of this, you might have more success trying to install the Linux version of everything from the bash shell - including Android Studio.
This way you will not be mixing and matching two System Environments more than what you already have.
Try GitWrap
https://github.com/ardevd/gitwrap/releases
This wrapper pipes output from WSL to windows and also works on android studio claimed by the developer

Installing R on Android

I am trying to install it on an Android operating system (I have a Samsung Galaxy tablet). I would like to install both R and RStudio.
I've been online to try and find out about this but most of the articles are quite old (going back to 2013) and don't make much sense to me.
I have both R and R studio installed on my personal laptop (with a windows OS) and found these both very straightforward to set up, but having some trouble figuring out how to do this on a tablet.
If anyone has done it recently and been successful please let me know.
Install GNURoot from Google Play
Install Gnuroot Wheezy from Google Play. See http://www.linux-magazine.com/
Online/Blogs/Productivity-Sauce/GNURoot-Linux-on-Android-No-Root-Required
for more help.
Update the package repositories (twice!):
apt-get update
apt-get update
Block updates to system Perl:
apt-mark hold perl-base
Install R:
apt-get install r-base
Install all available cran packages from the Debian repositories:
apt-get install r-cran*
Start R from the command line:
R
source
http://www.r-ohjelmointi.org/?p=1434
Rstudio-server didn't work in a non-rooted device, installed in ubuntu in termux. Related links: rstudio in android - rooted, non-root rstudio discussion.
I found two workarounds in a non-rooted device. Working on browser or VNC Viewer.
1. The browser (jupyter) approach
(tested in yoga book with Android 7.1 and Huawei phone with Android 8 - size with ggplot 1.66 Gb)
install termux (google play) (As termux didn't run jupyter-IRkernel, I had to install ubuntu)
install ubuntu in termux (MFDGaming or Neo-Oli).
run this in ubuntu:
apt update && apt upgrade
apt-get install apt-transport-https software-properties-common
# add R repository
add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu disco-cran35/'
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
apt update && apt upgrade
apt install nodejs
apt install npm # absence of this causes non-editable cells in jupyter
apt install gfortran
apt install liblapack-dev
apt install libopenblas-dev
# install R
apt install r-base-dev # or r-base or r-base-core
# install python package manager
apt-get install python3-pip
# install jupyter
pip3 install jupyterlab
# open R
R
Inside R:
# Package necessary for jupyter
install.packages("IRkernel")
IRkernel::installspec()
q()
In ubuntu, run the jupyter lab
jupyter lab --allow-root
# as you will see you have to paste something like this in your internet browser
http://127.0.0.1:8889/?token=1a0f9b3d472d155bb4d46df119b937646d6192f569c9d635
You would need to disable the automatic hibernation of termux in battery settings.
Note: In termux app (google play) is possible to install R, see Conor link; the important setupclang-gfort-8 step can be accomplished after installing make and gcc-8 and using the new package names in the output of the (outdated) Conor protocol. The problem appears if you want GUI. An option is the Rcmdr package, but as termux has not tcl-tk, as you can see inside R using capabilities(), I ended installing ubuntu in termux
2. The VNC approach
As in the browser approach install termux and ubuntu
In ubuntu install aterm
After installing R in ubuntu (see above), install R Commander GUI package:
#in R:
install.packages("Rcmdr")
In ubuntu install vnc4server
In Android install VNC Viewer (google play).
Launch the VNC server in ubuntu:
tigervncserver -xstartup aterm
In VNC Viewer connect to 127.0.0.1:5901 which corresponds to the :1 display (showing the aterm in white), open R in aterm, then library(Rcmdr).
After ploting, see ggplot example, I had to write (blindly) dev.off() because there is no other way to return to the script window.
require(ggplot2)
ggplot(diamonds) + geom_point(aes(x=carat, y=price, color=cut)) + geom_smooth(aes(x=carat, y=price, color=cut))
Notes:I also installed X11 in ubuntu, but didn't seem to improve the GUI experience of Rcmdr. In a yoga book with android the #Ajay answer didn't work.
Not exactly R Studio but still pretty cool... follow this Installing R on Android via Termux guide from Conor Anderson's blog.
Step 1: Install Termux from F-Droid (or Google Play Store)
Install from F-Droid
Step 2: Add the its-pointless package repository
Enter the commands below one at a time:
pkg install curl gnupg
mkdir -p "$PREFIX/etc/apt/sources.list.d/"
echo "deb https://its-pointless.github.io/files/24 termux extras" > "$PREFIX/etc/apt/sources.list.d/pointless.list"
curl "https://its-pointless.github.io/pointless.gpg" | apt-key add
Step 3: Install required .deb packages
Install the following packages. It might be wise to install each individually to monitor the warnings, I think some of these packages may be deprecated at this point in time.
pkg install r-base \
make \
clang \
gcc-9 \
libgfortran3 \
openssl \
libcurl \
libicu \
libxml2
Step 4: Configure your compiler
setupclang-gfort-9
Step 5: Launch R by typing an upper case R
R
Step 6: Further customize with Nvim-R or whatever else you like
Here is a summary of my experiments, as of October 2021. Long story short: I have a fully working R (complete with tidyverse) on my tablet, and I can access it from jupyter (which is not my first choice in general, but is probably appropriate for this platform and my use - I'm not planning to develop on Android, merely to try code snippets etc).
This draws mostly from the present article as well as from How do I install Jupyter notebook on an Android device? , and links therein.
Also, caveat reader: I'm not an expert in Linux, even less so on Android, and my understanding of Python is minimal. Sorry for any mistake or imprecise statement.
Including trial and errors, the whole process took me some 5 hours. Now I know what to do, I'd probably manage in 1 or 2.
Introduction
Android is a linux in disguise, so in principle it is possible to install all or most linux apps. There are, however, several caveats:
You normally do not have root access to your device (unless it is rooted, which is another can of worms);
When compiling binaries, they must be compiled for this specific architecture.
For these reasons, you can not always use ordinary .deb or .rpm packages and need to go through a somewhat convoluted route.
Also, it appears that R-studio cannot be installed without root privileges (either because it requires root itself, or because it relies on libraries that cannot be installed by a normal user).
Assuming you do not want to go the root route, you can still manage quite a few things.
You will need some basic familiarity with linux commands (cd, ls, chmod, ln...), and at least a basic idea of how packages are installed and managed in linux (apt-get or pkg), in R (install.packages() ) and in python (pip install). Also, it will not harm if you know what a compiler is (gcc), and if you realize that some R/python packages rely on compiled code (binaries) that typically resides somewhere else on the system.
Termux
Termux is "an Android terminal emulator and Linux environment app", a portable Linux distro running on Android (more or less).
Unfortunately the version currently on G-play is not the most recent one, so you want to use the f-droid version. So, install f-droid and then, from f-droid, install termux.
Configure termux
You will need basic tools (compiler etc) up and running on termux. This will require installing packages and in turn, you need packages compiled for this platform. In termux, many packages are maintained by "its-pointless" who also runs the relevant repository. So, in termux :
# basic utilities
pkg install curl gnupg
# Configure its-pointless repo
mkdir -p "$PREFIX/etc/apt/sources.list.d/"
echo "deb https://its-pointless.github.io/files/24 termux extras" > "$PREFIX/etc/apt/sources.list.d/pointless.list"
curl "https://its-pointless.github.io/pointless.gpg" | apt-key add
Now you can install more utilities, from its-pointless repo:
pkg install make \
clang \
gcc-9 \
libgfortran3 \
openssl \
libcurl \
libicu \
libxml2
And configure your compiler
setupclang-gfort-9
R !
Still in termux, run
pkg install r-base
At that stage, you should have a working R on your system (although purely text-based, but you can still use an external editor and source() your scripts).
Something nicer ?
You maybe want a GUI, or more pakages (tidyverse). Shortly, the main problem you will face is that many R packages in linux rely on system libraries, that need to be installed from linux. In principle you should be able to install the full libraries (the binaries as well as the R code) from install.packages(), that launches gcc to compile whatever code is needed; but practically, the compilation seems to fail more often than not. Probably the Android gcc has its quirks...
So the general idea will be to install from termux (or its-pointless) repo the R packages you need, or at least the library they rely on. The same is true for python libs, by the way.
Installing R packages
From within R, try to install what you need with the usual install.packages() command. If something needs to be compiled, it will probably fail. Read carefully the error - eventually you will find a line that says something like "missing libpango.so". This tells you, in this case, that you need to install pango, which happens to belong to the pango package : in termux, run pkg install pango, then return to R and try again.
Also, updating your packages to the latest version (pkg upgrade all) will do no harm...
On stack overflow, you will find various references to zlib, libpng, etc... read and interpret the error message.
In one case (R package repr, that needed base64, itself relying on libicu) I had a version issue - one of the termux packages was (incorrectly) requiring an old version of libicuuc (libicuuc.so.68), whereas the same termux had installed libicuuc.so.69 on my system. In this case, the cure was to create a symbolic link in the approriate directory, as follows
ln -s libicuuc.so.69 libicuuc.so.68
.. and the system happily followed the link :-)
By playing around with this, I managed to install tidyverse, as well as IRkernel that is required to establish a connection between R and jupyter. IRkernel needs to be configured from within R: IRkernel::installspec()
VNC
One user at Installing R on Android refers to the possibility of installing VNC, to obtain Rcmdr. I haven't tried.
Jupyter
It is also possible to install jupyter or jupyter-labs (which is not my favourite IDE under normal circumstances, but is probably an appropriate platform on a Android device).
Jupyter is python based, so you will need to play the same game with Python and python packages. Python packages are installed using pip (from the linux command line), and you will have the same issue with compiled binaries. Fortunately the most tricky python packages are packaged by its-pointless for termux, so here too, you will end up installing quite a few things outside of pip.
Installing R on Android suggests installing ubuntu on top of termux, and then installing jupyter from within ubuntu. I found it unnecessary (How do I install Jupyter notebook on an Android device?)
Termux will need more packages:
pkg install python fftw libzmq freetype libpng pkg-config libcrypt
There are also references to modejs, liblapack-dev and libopenblas-dev, I cannot remember whether they were required or not in the end (or already installed by something else). Also sometimes the relevant code moved out of the dev package to a stable one (so it would be liblapack)
Then, you need to install python stuff. Web sources suggest
LDFLAGS="-lm -lcompiler_rt" pip install jupyter
or/and, depending on the version you want to use
LDFLAGS="-lm -lcompiler_rt" pip install jupyter-lab
and (not required but useful to have in jupyter) :
LDFLAGS="-lm -lcompiler_rt" pip install numpy matplotlib
I'm not sure why we need LDFLAGS...
As previously, some of the "hybrid" packages are best installed from termux, for instance scipy (technically a python package, should be installed with pip install scipy) is easier to install (or must be installed?) using the termux version, so pkg install scipy
Again, some debugging will be required. Read the pip output, try to find out which package failed to install, see what you can do from termux, try again. Sometimes I found that dropping the LMFLAGS helped (or installing packages one by one), for instance a plain pip install cffi and pip install pyzmq worked better than having them installed as dependencies to jupyter. No idea why.
In the end, I launched jupyter (type jupyter notebook, or jupyter lab in termux console, copy the url, open in a browser)... only to have R crash on the first command. Back in termux I could see that it was still missing a library somewhere, which I tracked down and installed from termux (I think it was pango, this time).
So in short: Read the Friendly Error Messages !

Categories

Resources