Skip to content

Instantly share code, notes, and snippets.

@OrangeTide
Last active September 8, 2024 21:46
Show Gist options
  • Save OrangeTide/5eb368db8b5aa3a69eec188ea9b3d839 to your computer and use it in GitHub Desktop.
Save OrangeTide/5eb368db8b5aa3a69eec188ea9b3d839 to your computer and use it in GitHub Desktop.
To set up a new SDL Android project

How To Set Up a New SDL Android project

  1. Install Android Studio
  1. Get SDL sources SDL2-2.0.12.tar.gz and extract to a location of your choice

    cd /tmp
    curl -O https://www.libsdl.org/release/SDL2-2.0.12.tar.gz
    tar zxvf SDL2-2.0.12.tar.gz
    
  2. Set ANDROID_HOME and ANDROID_NDK_HOME. NDK must have a platform/ directory underneath it to be compatible with SDL's androidbuild.sh

    export ANDROID_HOME=$HOME/Android/Sdk
    export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/21.1.6352462/
    
  3. Run androidbuild.sh script (with COPYSOURCE=1):

    COPYSOURCE=1 /tmp/SDL2-2.0.12/build-scripts/androidbuild.sh \
      com.orangetide.hellodungeon \
      $HOME/my-prototype/src/hellodungeon.c
    
  4. Move project to somewhere suitable:

    mv /tmp/SDL2-2.0.12/build/com.orangetide.hellodungeon ~/DEVEL/hellodungeon
    
  5. Move headers so that #include <SDL/SDL.h> works

  • move include/ to include/SDL2 by shuffling it around

    cd ~/DEVEL/hellodungeon
    mv app/jni/SDL/include app/jni/SDL/SDL2
    mkdir app/jni/SDL/include
    mv app/jni/SDL/SDL2 app/jni/SDL/include/
    
  • Change to LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/SDL2

    vim app/jni/SDL/Android.mk
    
  • Touch up some of the header files for the new include path

    cd ~/DEVEL/hellodungeon
    sed -i -e 's,../../include,&/SDL2,' $(grep -rl ../include app/jni/SDL/src/events/)
    
  1. Move native source to a convenient place
  • Move your source

    cd ~/DEVEL/hellodungeon
    mkdir src
    mv app/jni/src/*.c src/
    
  • Edit LOCAL_SRC_FILES := ../../../src/hellodungeon.c

    vim app/jni/src/Android.mk
    
  • Edit target_sources(main PRIVATE ../../../src/hellodungeon.c)

    vim app/jni/src/CMakeLists.txt
    
  1. Upgrade gradle / Edit to version 7.0.3 or 7.0.2:

    cd ~/DEVEL/hellodungeon
    vim gradle.properties
    vim gradle/wrapper/gradle-wrapper.properties
    
  2. Fix deprecated gradle features Replace jcenter() with mavenCentral() in both places

    vim build.gradle
    
  3. Build from command-line

    cd ~/DEVEL/hellodungeon
    ./gradlew assembleDebug
    
  4. Build from Android studio

  • TODO: provide screen shots

TODO: Describe how to import SDL_image, SDL_mixer, SDL_ttf, SDL_gfx, SDL_net

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment