Compiling Libretro Cores for Android on Ubuntu
*** Not saying this is THE way to do it, but it was MY way for getting cores working on the Nvidia Shield - probably an overkill at times ***
Pre-ramble
There is no one size fits all way to compile cores - different versions of NDK,Tools,etc. There is a recipes directory in libretro-super that “kinda” shows exactly whats needed to compile each core. As the guide below stands - I managed to compile 42 of the cores without any juggling - there are some more that compile by specifically naming it - so this guide covers the most part but the files below will allow you to compile more if you are prepared to change some paths later on.
Whats needed:
Ubuntu 16.04 running (dedicated or a virtual machine) other flavours do work but this is the goto build.
Android NDK r15c - https://developer.android.com/ndk/downloads/older_releases.html
Android NDK r13b - https://developer.android.com/ndk/downloads/older_releases.html
Android NDK r10e - https://developer.android.com/ndk/downloads/older_releases.html
Android SDK latest - https://developer.android.com/studio/index.html
Android SDK r25.2.5 - https://androidsdkoffline.blogspot.fr/p/android-sdk-tools.html
java-8-openjdk-amd64 - (from terminal) sudo apt install default-jdk
ant - (from terminal) sudo apt install ant
Preliminary steps:
-
Create a folder “android” in your home directory. <----THIS IS YOUR GOTO FOLDER EVERYTHING IS STORED IN HERE.
-
Extract Android NDK r15c into folder “android-ndk-r15c” in the android directory.
-
Extract Android NDK r13b into folder “android-ndk-r13b” in the android directory.
-
Extract Android NDK r10e into folder “android-ndk-r10e” in the android directory.
-
Extract Android SDK latest into folder “tools” in the android directory.
-
Extract Android SDK r25.2.5 into folder “tools_r25.2.5” in the android directory.
-
Make Standalone toolkit for android-ndk-r15c in folder “stdtc-r15c” and place in android directory.
- from the android-ndk-r15c/build/tools directory…
- make_standalone_toolchain.py --arch arm --api 21 --install-dir stdtc-r15c
-
Make Standalone toolkit for android-ndk-r13b in folder “stdtc-r13b” and place in android directory.
- from the android-ndk-r13b/build/tools directory…
- make_standalone_toolchain.py --arch arm --api 21 --install-dir stdtc-r13b
-
Make Standalone toolkit for android-ndk-r10e in folder “stdtc-r10e” and place in android directory.
- from the android-ndk-r10e directory…
- /build/tools/make-standalone-toolchain.sh --toolchain=arm-linux-androideabi-4.9 --platform=android-21 --install-dir=stdtc-r10e
-
In terminal run (from the android directory) git clone https://github.com/libretro/libretro-super to clone the libretro-super folder
-
From the newly created libretro-super directory run ./libretro-fetch.sh in terminal and go and grab a coffee (or 3). This will clone all the cores and retroarch and is a fair size.
-
Finally we need to add the paths to our compiling tools - run from terminal -sudo gedit ~/.bashrc (or your preferred text editor)
*** Add these lines your .bashrc at the end ***
export ANDROID_HOME=~/android/tools_r25.2.5
export NDK_ROOT=~/android/android-ndk-r15c
export ANDROID_NDK=~/android/android-ndk-r15c
export ANDROID_STANDALONE_TOOLCHAIN=~/android/stdtc-r15c
export ANDROID_NDK_ARM=~/android/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
export ANDROID_NDK_ROOT=~/android/android-ndk-r15c
export ANDROID_NDK_LLVM=~/android/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64
export TOOLCHAIN=~/android/android-ndk-r15c/toolchains
export ANDROID_TOOL_CHAIN=~/android/android-ndk-r1c/toolchains
export PATH=$PATH:/usr/share/ant/bin
export PATH=$PATH:~/android/stdtc-r15c/bin
export PATH=$PATH:~/android/tools_r25.2.5
export PATH=$PATH:~/android/android-ndk-r15c
export PATH=$PATH:~/android/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/
export CC=arm-linux-androideabi-gcc
export CXX=arm-linux-androideabi-g++
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
NOW REBOOOOOOOOOOOTTTTT!!!
If you got this far then well done - you now have a working environment to compile cores so lets do just that
I was only interested in the armeabi-v7a cores so I changed the line in libretro-config.sh (in libretro-super directory) to - export TARGET_ABIS=“armeabi-v7a” - and deleted the other ones - it compiled far quicker for me not compiling unecessary targets. Probably a command line way but this worked.
To compile your first cores…
- For me, I need to change the permissions on the file libretro-buid-android-mk.sh in the “libretro-super” directory to allow execute (Allow executing file as program)
- From terminal, enter the libretro-super directory and run - ./libretro-buid-android-mk.sh
This builds completed cores in the “dist/android/armeabi-v7a” directory. As previously stated some fail but I managed to get 42 cores compiled this way off the bat.
To get cores onto your Retroarch install…
Cores need to be zipped and then moved onto your Retroarch.
Easiest way to do this (and it works on an non-rooted Shield) is to follow Thatman84’s excellent guide for creating an local updater here - http://emulationguide.com/retroarch-local-online-updater.
That should be that for now. Your next steps in exploration should be to look at the recipes and see what cores are compiled using different toolchains.
my .bashrc has multiple sections commented out (use a #) the one below is for the r13b NDK for example, some versions of mame if I recall prefer the older r10 version too. I just comment out all but the version I want to use and reboot.
export ANDROID_HOME=~/android/tools_r25.2.5
export NDK_ROOT=~/android/android-ndk-r13b
export ANDROID_NDK=~/android/android-ndk-r13b
export ANDROID_STANDALONE_TOOLCHAIN=~/android/stdtc-r13b
export ANDROID_NDK_ARM=~/android/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
export ANDROID_NDK_ROOT=~/android/android-ndk-r13b
export ANDROID_NDK_LLVM=~/android/android-ndk-r13b/toolchains/llvm/prebuilt/linux-x86_64
export TOOLCHAIN=~/android/android-ndk-r13b/toolchains
export ANDROID_TOOL_CHAIN=~/android/android-ndk-r13b/toolchains
export PATH=$PATH:/usr/share/ant/bin
export PATH=$PATH:~/android/stdtc-r13b/bin
export PATH=$PATH:~/android/tools_r25.2.5
export PATH=$PATH:~/android/android-ndk-r13b
export PATH=$PATH:~/android/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/
export CC=arm-linux-androideabi-gcc
export CXX=arm-linux-androideabi-g++
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
I do have a google sheet that I have noted what compiled best for me and how I acheived it - I would be willing to share that with anyone interested.
So to sign out - I am not saying this is THE way and no doubt I added unecessary steps but if you followed this guide to the letter you certainly “should” have compiled cores sitting on your pc
If people try this guide sucessfully please let me know and I will offer it to update the docs. Also if anyone has any improvements please share too
Brent