Android: Difference between revisions

From MAMEDEV Wiki
(Created page with " == Android build == First, download and install Android NDK r25c or later by unpacking release taken from the Android developer site [https://developer.android.com/ndk/down...")
 
No edit summary
 
Line 15: Line 15:
In time of writing version was SDL2-2.26.3, but later version should work fine as well.
In time of writing version was SDL2-2.26.3, but later version should work fine as well.


Next step is to build SDL2 with Android NDK and prepare include files in required form.
Next step is to build SDL2 with Android NDK:


   tar xvfz SDL2-2.26.3.tar.gz
   tar xvfz SDL2-2.26.3.tar.gz

Latest revision as of 19:05, 26 February 2023

Android build

First, download and install Android NDK r25c or later by unpacking release taken from the Android developer site [1].

To be used, only enviroment variables need to be properly set, as in example:

 export PATH="$PATH:/opt/android-ndk"
 export ANDROID_NDK=/opt/android-ndk
 export ANDROID_NDK_HOME=/opt/android-ndk

Since there is no precompiled SDL2 for Android we need to prepare that as well. First is to download latest from SDL github [2]. In time of writing version was SDL2-2.26.3, but later version should work fine as well.

Next step is to build SDL2 with Android NDK:

 tar xvfz SDL2-2.26.3.tar.gz
 cd SDL2-2.26.3


To compile for ARM64 (arm64-v8a):

 cmake -S . -B build_arm64 \
     -DANDROID_PLATFORM=android-24 \
     -DANDROID_ABI=arm64-v8a \
     -DCMAKE_INSTALL_PREFIX=~/SDL_Android_arm64 \
     -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \
     -DSDL_SHARED=ON -DSDL_STATIC=ON -DSDL_STATIC_PIC=ON -DSDL_TEST=ON \
     -DSDL2_DISABLE_SDL2MAIN=OFF -DSDL2_DISABLE_INSTALL=OFF \
     -DCMAKE_INSTALL_INCLUDEDIR=include -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_BUILD_TYPE=Release
 make -C build_arm64 install

To compile for Intel x86:

 cmake -S . -B build_x86 \
     -DANDROID_PLATFORM=android-24 \
     -DANDROID_ABI=x86 \
     -DCMAKE_INSTALL_PREFIX=~/SDL_Android_x86 \
     -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \
     -DSDL_SHARED=ON -DSDL_STATIC=ON -DSDL_STATIC_PIC=ON -DSDL_TEST=ON \
     -DSDL2_DISABLE_SDL2MAIN=OFF -DSDL2_DISABLE_INSTALL=OFF \
     -DCMAKE_INSTALL_INCLUDEDIR=include -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_BUILD_TYPE=Release
 make -C build_x86 install

To compile for Intel x86_64:

 cmake -S . -B build_x86_64 \
     -DANDROID_PLATFORM=android-24 \
     -DANDROID_ABI=armeabi-v7a \
     -DCMAKE_INSTALL_PREFIX=~/SDL_Android_x86_64 \
     -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \
     -DSDL_SHARED=ON -DSDL_STATIC=ON -DSDL_STATIC_PIC=ON -DSDL_TEST=ON \
     -DSDL2_DISABLE_SDL2MAIN=OFF -DSDL2_DISABLE_INSTALL=OFF \
     -DCMAKE_INSTALL_INCLUDEDIR=include -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_BUILD_TYPE=Release
 make -C build_x86_64 install

To compile for ARM (armeabi-v7a):

 cmake -S . -B build_arm \
     -DANDROID_PLATFORM=android-24 \
     -DANDROID_ABI=armeabi-v7a \
     -DCMAKE_INSTALL_PREFIX=~/SDL_Android_arm \
     -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \
     -DSDL_SHARED=ON -DSDL_STATIC=ON -DSDL_STATIC_PIC=ON -DSDL_TEST=ON \
     -DSDL2_DISABLE_SDL2MAIN=OFF -DSDL2_DISABLE_INSTALL=OFF \
     -DCMAKE_INSTALL_INCLUDEDIR=include -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_BUILD_TYPE=Release
 make -C build_arm install


After this all is ready for MAME to be built. Note that it can be built for android-arm, android-arm64, android-x86 and android-x64. If you are testing with emulator you only need android-x86 build, but for real device nowdays android-arm64 will only be needed, and there are less and less android-arm.

 make SUBTARGET=tiny SDL_INSTALL_ROOT=~/SDL_Android_x86 android-x86 -j9

This prepared binaries, but still we need to deploy application to device. Easiest way is to use Android Studio [3].

All build features are also available using gradle, next set of commands will create debug build and deploy it on connected Android device.

 gradlew assembleDebug
 gradlew installDebug