This page documents running an old version (1.8.4) of mercurial but says
"(later versions need an unavaliable python module named grp)"
This is the way I did it (but am still interested to hear of alternative ways) using an Ubuntu 16.04 machine and a intel 64bit android emulator running on Windows 7, using mercurial 3.7.3
Using an Ubuntu system, follow these instructions for creating 2.7 version of python capable of running hg.
Copy python onto android device into an app files directory (so it can be executed)
on windows host
adb push python279.x86_64 /sdcard
adb -e shell
on android device
cd /data/user/0/$SOMEAPPDIR/files
cp -Rav /scard/python279.x86_64 .
make python excutable
chmod +x python279.x86_64/bin/python2.7
set some env vars need to make python run on android
export LD_LIBRARY_PATH=/data/user/0/$SOMEAPPDIR/files/python279.x86_64/lib
export LD_PRELOAD=libffi.so:libbz2.so
export PATH=$PATH:/data/user/0/$SOMEAPPDIR/files/python279.x86_64/bin
Python should now be able to be run with python2.7
Build mercurial on Ubuntu host.
download mercurial 3.7.3
uz mercurial-3.7.3.tar.gz
cd mercurial-3.7.3 && make all
HOME=$PWD/dist make install
Make minor modifications
cd dist/mercurial-3.7.3/dist/lib/python/mercurial
rm *.so
cp pure/*.py .
Edit posix.py and delete the "import grp" line.
copy mercurial onto android device
on windows host
adb push dist /sdcard
adb -e shell
on android device
cd /data/user/0/$SOMEAPPDIR/files
cp /sdcard/dist .
alias hg to make it easy to use
alias hg='python2.7 /data/user/0/$SOMEAPPDIR/files/dist/bin/hg'
Hg should now be possible to use on android device.
It's even possible to clone remote repos but I also had to pass the --insecure flag to bypass ssl errors.
The answer made on "Feb 15 '17" works fine however there is one fairly big drawback.
This answer address this drawback and is intended to be used in conjunction with the previous answer.
The problem
This procedure:
rm *.so
cp pure/*.py .
removes the native libraries and uses the python 'pure' implementation of these libraries instead. This causes major performance problem when working with large repositories, especially on slower android devices.
The solution
Cross compiling mercurial with android ndk, produces native libraries that can be used on android.
I've added some helper scripts to a mercurial 4.8.2 fork to make cross compiling easier.
Linux instructions:
Clone the repo
hg clone https://bitbucket.org/hindlemail/hg-stable-android/
update to 331892efe015
hg update -r 331892efe015
Set these for environment variables with appropriate values:
provide location of android NDK
ANDROID_NDK="$HOME/Android/android-ndk-r13b"
specify build arch - (armeabi, x86, x86_64, arm64)
ARCH="armeabi"
specify target android sdk verison
PLATFORM="android-22"
specify output of cross compiled python.
(see answer from Feb 15 '17" for more info )
PYTHONDIR="/usr/local/android/install/python279.arm22"
Run crosscompile.sh
Related
I haven't done Android development in a while, so my knowledge of modern Android development is spotty.
I'm trying to learn React Native. I use WSL as my primary development environment. Since it'll probably be a pain to set up the Android emulator in Linux/WSL, I want to run the emulator directly on Windows. However, I'd prefer to be able to run react-native run-android in WSL.
How would I set up React Native to be able to run react-native run-android in WSL and run the app in an Android emulator on Windows?
My ANDROID_HOME variable should be set up correctly, but I don't know enough about Android to know if this is doing anything:
export ANDROID_HOME=/mnt/c/Users/Leo/AppData/Local/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
It is possible to set it up so that the emulator runs in Windows while running react-native run-android in WSL. The benefits of doing it this way over #pscl's way is that this way supports autolinking. Here is what you need to do to get it working.
Windows
The only thing required on the Windows side is to install Android Studio and setup the emulator / virtual device. This is pretty straightforward so I'm not gonna walk you through that.
Windows Subsystem for Linux
There's a bit more to setting up this side of things, so bear with me. (My WSL is Ubuntu 18.04, this is untested on other flavors.)
Download and unzip the Android command line tools. (Currently found on the Android Studio download page, scroll down to "Command line tools only" and select the Linux download option.)
Look inside the unzipped folder and move the directory named tools to ~/Android/Sdk/tools. (Create the ~/Android/Sdk directories if they don't exist.)
Download and unzip JDK 8. (I recommend downloading from AdoptOpenJDK. Also, make sure to install OpenJDK 8 otherwise sdkmanager won't work, which we use later.)
Move the unzipped folder to /opt/jdk8u222-b10. (You can actually put this wherever you want, just make sure the JAVA_HOME environment variable points to this unzipped folder.)
Set the following environment variables in your ~/.bashrc file. (The paths could be different for you!)
export ANDROID_HOME=/home/your-name/Android/Sdk
export JAVA_HOME=/opt/jdk8u222-b10
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
Restart your bash terminal and execute the command sdkmanager "platform-tools" to download the latest platform tools. (The adb tool comes from here.)
React Native
Now that everything is setup, it's time to play!
Start the emulator in Windows.
Open your project directory in WSL and run react-native start. (Keep this terminal open).
Open your project directory in another WSL terminal and run react-native run-android. (The first time you run this, React Native will download a few other SDKs based on your virtual device. You can see all installed SDKs by running sdkmanager --list. See the docs for sdkmanager for more info.)
Running on Device
This is a quick note on making it so you can install your app to a physical device. The trick here is making sure both of your adb executables are on the same version. (They should be since we installed it through sdkmanager.)
C:\Users\your-name\AppData\Local\Android\Sdk\platform-tools\adb.exe version
/home/your-name/Android/Sdk/platform-tools/adb version
Once you've confirmed that they are on the same version, make sure you start the adb server from the windows executable (Run adb.exe kill-server && adb.exe start-server). Then you can test if it works by running adb devices in WSL and you should see your device that is plugged in.
AFAIK it is not possible to use react-native in WSL due to a number of issues.
e.g. https://github.com/Microsoft/BashOnWindows/issues/1523
However, I've found a workaround that combines a native windows android build with a npm stack in WSL. Realistically, you'll want to install the native Windows Android Studio/SDK to use the Intellij IDE and the emulator anyway. The trick is to separate out the Gradle based Android compile.
Workflow
All project setup and package management performed in WSL with npm/yarn. react-native-cli installed globally in WSL. No need for a duplicate windows binary node/npm stack.
Don't use react-native run-android, instead compile and deploy from cmd. From the /android directory inside your project, execute the gradle wrapper gradlew.bat installDebug, or with the Creator's Update, you can do this from inside the WSL bash shell /mnt/c/Windows/System32/cmd.exe /C gradlew.bat installDebug. Don't use the unix gradlew script.
Once the APK has been assembled and uploaded to your device or emulator, run the debug server from within WSL using the command react-native start.
I've tested this out with some fairly complex projects using multiple native Android components. Hope this helps.
Note: For this to work your project needs to be located in the native Windows file system i.e. /mnt/c.
For those who struggle to make Windows 10 Android Studio work with WSL2 located react-native project.
Inital setup
You need to install on your Windows 10 Android Studio.
Set user variable:
ANDROID_HOME=C:\Users\<YOUR_USER>\AppData\Local\Android\Sdk
Add to system variable PATH:
%ANDROID_HOME%\emulator
%ANDROID_HOME%\platform-tools
%ANDROID_HOME%\tools
%ANDROID_HOME%\cmdline-tools\latest (I'm not sure if this one is necessary)
Then go to your WSL2 and install:
sudo apt-get install unzip
get android studio Command Line Tools Only and unzip it into /home//Android
install jdk 8 with sudo apt-get install openjdk-8-jdk
add this to your .bashrc:
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
export PATH=$PATH:$JAVA_HOME/bin
export ADB_SERVER_SOCKET=tcp:<YOUR_WSL_IP_ADDRESS_FROM_POWERSHELL>:5037 (check your WSL adapter IP by running `ipconfig` in powershell.)
export ANDROID_HOME=$HOME/Android
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
restart bash and run sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools"
run adb version && adb.exe version check if versions match
Running on emulator
run adb kill-server (ps) / adb.exe kill-server (wsl2 bash)
run adb -a -P 5037 nodaemon server (ps) / adb.exe -a -P 5037 nodeamon server (wsl2 bash) - don't close terminal window!
run emulator -avd <YOUR_AVD_NAME> (ps) / emulator.exe -avd <YOUR_AVD_NAME> - don't close terminal window!
run adb kill-server (WSL2 bash)
run adb devices (WSL2 bash) - you should now see your emulated device pick up it's id
go to your react-native project directory in WSL2 and run react-native run-android --deviceId=<YOUR_DEVICE_ID>
you should be all set up now.
Same flow stays for USB connected devices. The only thing that is changing is that instead of step 4 you connect your developer enabled phone to PC and you should get in a terminal window with running adb server log that new device is connected.
NOTE:
You can run all commands in PowerShell by aliases without .exe and path only if you have defined environmental variables on windows 10 and extended PATH system variable. If you want to use
all commands from WSL2 bash you always need to add .exe when you want to execute something on windows side so WSL2 knows that it needs to
reach to windows executables.
This answer by steelbrain from here worked for me:
Add the following to your WSL bashrc or zshrc:
export WSL_HOST_IP="$(tail -1 /etc/resolv.conf | cut -d' ' -f2)"
export ADB_SERVER_SOCKET=tcp:$WSL_HOST_IP:5037
Then create a firewall entry, create a new "Inbound" Rule. Select "Port" then Specific TCP port "5037" then "Allow the connection" then check all of Domain, Private and Public and add a name. After the firewall entry is added, open up its properties, go to Scope -> Remote IP Addresses -> Add "172.16.0.0/12".
Now that we're covered in the WSL2 VM and through the Firewall, you have to start the adb server with specific arguments to make it listen on all addresses (don't worry we've only whitelisted our WSL2 VM IP range so no security issues).
Create a vbs script, call it whatever and put this in it
CreateObject("WScript.Shell").Run "%USERPROFILE%\AppData\Local\Android\Sdk\platform-tools\adb.exe kill-server", 0, True
CreateObject("WScript.Shell").Run "%USERPROFILE%\AppData\Local\Android\Sdk\platform-tools\adb.exe -a -P 5037 nodaemon server", 0, True
Now all you have to do is invoke the vbs script once per reboot and your WSL VM will connect to your host ADB instance
(I just invoked those two commands in a regular CMD.exe shell:
%USERPROFILE%\AppData\Local\Android\Sdk\platform-tools\adb.exe kill-server
%USERPROFILE%\AppData\Local\Android\Sdk\platform-tools\adb.exe -a -P 5037 nodaemon server
I guess he proposed vbs so it remains running, because if I were to put it in a .bat file the server would presumably die with the bat file, haven't tried)
ANDROID_HOME=/mnt/c/Users/<YOUR_USER>/AppData/Local/Android/Sdk
alias adb=$ANDROID_HOME"/platform-tools/adb.exe"
Firstly, I got two questions to ask. My first question is I've downloaded repo tool for Windows and within Cygwin terminal used the below command
repo init -u https://github.com/CyanogenMod/android.git -b cm-14.0 --depth=1
to get CyanogenMod android source files and later used the below command
repo sync .
Now I want to move my local repository and source files to another machine that runs on Ubuntu 14.04. How to achieve this? Does a simple simply copying of files will make the repo work on Ubuntu? I have very limited bandwidth for PC running ubuntu so I don't prefer to download the entire files again in Ubuntu.
Now my second question is, there is new branch cm-14.1 so how do I update my local branch on Ubuntu after moving the files?
Thanks a lot in advance.
(Before all, you should fetch all branches to local machine, this is steps-by-steps tutorial: https://stackoverflow.com/a/40318872/3728901)
Use git bundle (for backup all branches)
A real example: On Windows OS PC
git clone --mirror https://github.com/donhuvy/personal_finance.git
cd personal_finance.git/
git bundle create repo.bundle --all
repo.bundle is the file what you need (full back up) in the same directory.
How to restore from file repo.bundle (On Ubuntu OS PC):
git clone repo.bundle
Reference
https://git-scm.com/docs/git-bundle
http://rypress.com/tutorials/git/tips-and-tricks#bundle-the-repository
I am facing a problem. I have to add a PDF reader support to my Android App (now I'm using Mupdf but I need to change it).
I found PDFium project (https://code.google.com/p/pdfium/) and I think it is what I need for my needs.
I haven't too much experience in Android and I've not been able to build it for Android, I've followed the build instructions from here https://code.google.com/p/pdfium/wiki/Build with no good results.
Could you give some hint or advice to achieve build this tool in Android?
Thank you in advance!!!
How to build?
I recommend building on Linux (virtual machine will suffice),
because Windows is officially not supported and there are many problems on newer versions of OS X.
You will need about 60 GB of free space.
install OpenJDK 8
$ mkdir ~/android_src && cd ~/android_src or select any other path
$ repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.1_r28
(detailed description available here)
$ repo sync and wait...
clone this repo (or download zip with its content)
replace makefiles in ~/android_src with corresponding makefiles from this repo
$ cd ~/android_src
$ source build/envsetup.sh
$ cd external/pdfium/fpdfsdk
$ lunch and select architecture
$ mma and wait ~5 minutes
library is available in ~/android_src/out/target/product/generic*/obj/lib/libmod*.so, copy it somewhere
$ rm -r ~/android_src/out before next build
It worked for me, but if doesn't work for you, try installing additional packages listed here.
Source
Build it within the AOSP
https://android.googlesource.com/platform/external/pdfium/
Use mm or mma instructions to build only the pdfium module
I've only successfully built the shared library but haven't take it into practice.
I'm trying to compile ffmpeg for Android using this guy script (https://github.com/guardianproject/android-ffmpeg) because it looked like the simplest and the whole NDK is really not my area of expertise.
So let's see what I've done so far:
Downloaded and installed a fresh Ubuntu 12.04 LTS from: http://www.ubuntu.com/download/desktop in a VirtualBox. (had some little problems with video but a few updates later in the terminal ubuntu is up and running)
installed the Android SDk and downloded/unzipped the NDK into /Documents/ndk
I used those commands to install the compiler:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential
$ gcc -v
$ make -v
then sudo install git (or something like that to install git)
then git clone https://github.com/guardianproject/android-ffmpeg.git
then copied from the guys page building section
cd android-ffmpeg
git submodule init
git submodule update
NDK_BASE=/path/to/android-ndk ./configure_make_everything.sh
it mostly goes well until it says:
arm-linux-androideabi-gcc is unable to create an executable file C
compiler test failed
If you think configure made a mistake,.. blaah blahh blaah
I'm not sure what it means or where to go from here.
from this I did some chmod 777 on the folders to make sure stuff can be execute.
also from this I tried his script but without any luck.
help?
decompose what the script 'config_make_everything' is doing.. and run one step at a time...
https://github.com/guardianproject/android-ffmpeg/blob/master/configure_make_everything.sh
each step will create a file like 'config.log' where you can go to the tail and find more details about what went wrong finding the compiler.
When u start using the NDK, IMO, invest a bit of learn curve time going thru its ./doc directory and making sure that you have it integrated correctly. With NDK install, there are some samples. Build a few from CLI just to make sure that the ENV is correct and that the install is good, and that u have at least some idea of the build as a repeatable process. That will prove that you can do good 'cross compiles' with the build tools. Then you can return to guardian.ffmpeg stuff.
IMO - there is alot going on with an NDK build of this project and getting it all to build without understanding any of the underlying configuration / build stack would require lots of luck.
I work with older releases of Android (Gingerbread 2.3.4). To develop for these versions I use now Ubuntu 10.04. At the same time, I would like to use more recent version: 12.04 or maybe 12.10. It is written here:
Building on Ubuntu 12.04 is currently only experimentally supported
and is not guaranteed to work on branches other than master.
So here is my question, has anybody tried to build old versions of Android on Ubuntu 12.04? I do not like new unity interface so I also consider xfce or kde. That's why here is the second question, will I have any troubles with building if I change window system?
Yes, it is possible to build Gingerbread on Ubuntu 12.10.
Biggest problem is that Ubuntu 12.10 has newer gcc 4.7, which is very strict.
It is possible to fix it by patching Android source to be compliant with new gcc requirements. However, this can be difficult to do, especially when it involves patching older kernel sources.
You can bypass this by simply installing older gcc 4.4 (which is default version in Ubuntu 10.10).
sudo apt-get install gcc-4.4-multilib g++-4.4-multilib
After that, you need to make gcc 4.4 to be the default compiler for your Android compilation.
Easiest way is to simply symlink gcc, g++, cpp to point to older versions and add it to PATH:
mkdir ~/bin
cd ~/bin
ln -s /usr/bin/g++-4.4 g++
ln -s /usr/bin/gcc-4.4 gcc
ln -s /usr/bin/cpp-4.4 cpp
# you might want to add line below to ~/.bashrc:
export PATH=$HOME/bin:$PATH
Now, you need to have Java installed. Unlike newer Android 4, Gingerbread can be built using OpenJDK, so you should be able to simply
sudo apt-get install openjdk-6-jdk
to get working JDK.
Also see this thread.