# How to build a SDL2 application for Android using command line

**URL:** <https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021>\
**Category:** SDL Development\
**Created:** [December 27, 2023, 1:00am UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021 "2023-12-27T01:00:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![8Observer8](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://discourse.libsdl.org/u/8Observer8)\
**Post date:** [December 27, 2023, 1:00am UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/1 "2023-12-27T01:00:17Z")

</div>

Hi,

My steps:

- I installed Android SDK, NDK, JDK, and Gradle
- I installed these packages using `SDK Manager`:  
 ![image](https://discourse.libsdl.org/uploads/default/original/2X/d/d15cd4d30fdbbac7d479ec419fc2d6d790e15480.png)  
 ![image](https://discourse.libsdl.org/uploads/default/original/2X/a/a6b9ffe9796f9b825a91c67164d18adbbb7310d0.png)
- I created ANDROID\_HOME, ANDROID\_NDK, and JAVA\_HOME variables:  
 ![image](https://discourse.libsdl.org/uploads/default/original/2X/8/8d967830023d56aa3dd7c5c2ac748d4965672c2a.png)
- I added the Gradle path to the Path variable
- I downloaded this folder (from release 2.28.5): [https://github.com/libsdl-org/SDL/tree/main/android-project](https://github.com/libsdl-org/SDL/tree/main/android-project)
- I opened the project folder in CMD and typed this command: `"./gradlew" build`

But I have these errors. Please wrote what I can try. I don’t want to use Android Studio. It is too slow on my laptop. I want to use CMD and Sublime Text 4.

```auto
E:\_Projects\SDL\android\android-project>"./gradlew" build
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :app:configureNdkBuildDebug[arm64-v8a] FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:configureNdkBuildDebug[arm64-v8a]'.
> [CXX1429] error when building with ndkBuild using E:\_Projects\SDL\android\android-project\app\jni\Android.mk: C++ build system [configure] failed while executing:
      @echo off
      "E:\\AppData\\Android\\SDK\\ndk\\25.1.8937393\\ndk-build.cmd" ^
        "NDK_PROJECT_PATH=null" ^
        "APP_BUILD_SCRIPT=E:\\_Projects\\SDL\\android\\android-project\\app\\jni\\Android.mk" ^
        "NDK_APPLICATION_MK=E:\\_Projects\\SDL\\android\\android-project\\app\\jni\\Application.mk" ^
        "APP_ABI=arm64-v8a" ^
        "NDK_ALL_ABIS=arm64-v8a" ^
        "NDK_DEBUG=1" ^
        "NDK_OUT=E:\\_Projects\\SDL\\android\\android-project\\app\\build\\intermediates\\cxx\\Debug\\29445a3u/obj" ^
        "NDK_LIBS_OUT=E:\\_Projects\\SDL\\android\\android-project\\app\\build\\intermediates\\cxx\\Debug\\29445a3u/lib" ^
        "APP_PLATFORM=android-19" ^
        "APP_SHORT_COMMANDS=false" ^
        "LOCAL_SHORT_COMMANDS=false" ^
        -B ^
        -n
    from E:\_Projects\SDL\android\android-project\app
  E:/AppData/Android/SDK/ndk/25.1.8937393/build/../build/core/build-binary.mk:586: Android NDK: Module main depends on undefined modules: SDL2
  E:/AppData/Android/SDK/ndk/25.1.8937393/build/../build/core/build-binary.mk:599: *** Android NDK: Note that old versions of ndk-build silently ignored this error case. If your project worked on those versions, the missing libraries were not needed and you can remove those dependencies from the module to fix your build. Alternatively, set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies. . Stop.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 12s
15 actionable tasks: 2 executed, 13 up-to-date

```

---

<div class="post-metadata">

**Author:** ![yataro](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/y/6de8d8/32.png) [@yataro](https://discourse.libsdl.org/u/yataro)\
**Post date:** [December 27, 2023, 5:49am UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/2 "2023-12-27T05:49:50Z")

</div>

`android-project` is a project template. To create a buildable project you should use `androidbuild.sh` (you have to use bash or port it to batch file) script or perform the same actions manually. See [SDL2/Android - SDL Wiki](https://wiki.libsdl.org/SDL2/Android)  
You can also prebuild SDL as a library to skip source-copy-build step for future projects.

---

<div class="post-metadata">

**Author:** ![8Observer8](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://discourse.libsdl.org/u/8Observer8)\
**Post date:** [December 27, 2023, 2:12pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/3 "2023-12-27T14:12:00Z")

</div>

Thank! I see that the manual has a link to this step-by-step manual: [SDL/docs/README-android.md at main · libsdl-org/SDL · GitHub](https://github.com/libsdl-org/SDL/blob/main/docs/README-android.md) I opened the SDL2 source code folder and I found the `androidbuild.sh` inside the `build-scripts` folder. I think I should to go to the the `build-scripts` folder and run the `androidbuild.sh` script from it. The manual says:

> for example if you are in the build-scripts directory and want to create the testgles.c test, you’ll run:
> 
> ```auto
> ./androidbuild.sh org.libsdl.testgles ../test/testgles.c
> 
> ```

- I am inside of the the `build-scripts` folder:  
 ![image](https://discourse.libsdl.org/uploads/default/original/2X/0/0ee2892c4d5c092f5bd63545f2a6844bf999ab2a.png)
- I executed this command: `"./androidbuild.sh" org.libsdl.testgles ../test/testgles.c`
- I don’t see any output messages
- I go to the `test` folder and I see a lot of files there:  
 ![image](https://discourse.libsdl.org/uploads/default/original/2X/e/e69d936d67517fa76bf6197869d11fe43943bd93.png)
- I opened the `testgles.c` file and I see a code from OpenGL 1.1. It is a desktop version of OpenGL that will not work on Android:

```c++
        glViewport(0, 0, state->window_w, state->window_h);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrthof(-2.0, 2.0, -2.0 * aspectAdjust, 2.0 * aspectAdjust, -20.0, 20.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LESS);
        glShadeModel(GL_SMOOTH);

```

It is strange for me. Or does OpenGL 1.1 work on Android?

---

<div class="post-metadata">

**Author:** ![8Observer8](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://discourse.libsdl.org/u/8Observer8)\
**Post date:** [December 27, 2023, 2:23pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/4 "2023-12-27T14:23:45Z")

</div>

I don’t understand what is the next step in this manual: [SDL/docs/README-android.md at main · libsdl-org/SDL · GitHub](https://github.com/libsdl-org/SDL/blob/main/docs/README-android.md) But I see the next step in this one: [SDL2/Android - SDL Wiki](https://wiki.libsdl.org/SDL2/Android)

> - Follow the instructions to install on your device:

```auto
cd /usr/src/SDL2/build/org.libsdl.testgles/
ant debug install # SDL <= 2.0.7
./gradlew installDebug # SDL >= 2.0.8

```

But there is not such folder `SDL2/build/org.libsdl.testgles`:  
 ![image](https://discourse.libsdl.org/uploads/default/original/2X/7/74c9e5d238c45ec60d42d5ca1ad92ad47fd1ffaf.png)

![image](https://discourse.libsdl.org/uploads/default/original/2X/9/95ac5d01c7a793a937e53c5695e1bd0d8eb6910d.png)

![image](https://discourse.libsdl.org/uploads/default/original/2X/a/a323fb87bd5147ee0ec0c8e74097d6c91be6e835.png)

![image](https://discourse.libsdl.org/uploads/default/original/2X/8/8ee98c37d275e0ade879b09bc653cf4ea2e326aa.png)

---

<div class="post-metadata">

**Author:** ![8Observer8](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://discourse.libsdl.org/u/8Observer8)\
**Post date:** [December 27, 2023, 2:32pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/5 "2023-12-27T14:32:13Z")

</div>

```auto
cd /usr/src/SDL2/build/org.libsdl.testgles/
ant debug install # SDL <= 2.0.7
./gradlew installDebug # SDL >= 2.0.8

```

In my case I use SDL \>= 2.0.8. So I should use `./gradlew installDebug`. I see that the `SDL-release-2.28.5` has only one `gradlew` file inside of `SDL-release-2.28.5\android-project`:  
 ![image](https://discourse.libsdl.org/uploads/default/original/2X/f/fb8ac2e7d76aaa97b2639c8cfd105be08dc30dd5.png)

- I try to go to the `SDL-release-2.28.5\android-project` folder and execute of this command `"./gradlew" installDebug` But I again get the same error as in the first message:

```auto
E:\_Projects\SDL\android\SDL-release-2.28.5\android-project>"./gradlew" installDebug
> Task :app:configureNdkBuildDebug[arm64-v8a] FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:configureNdkBuildDebug[arm64-v8a]'.
> [CXX1429] error when building with ndkBuild using E:\_Projects\SDL\android\SDL-release-2.28.5\android-project\app\jni\Android.mk: C++ build system [configure] failed while executing:
      @echo off
      "E:\\AppData\\Android\\SDK\\ndk\\25.1.8937393\\ndk-build.cmd" ^
        "NDK_PROJECT_PATH=null" ^
        "APP_BUILD_SCRIPT=E:\\_Projects\\SDL\\android\\SDL-release-2.28.5\\android-project\\app\\jni\\Android.mk" ^
        "NDK_APPLICATION_MK=E:\\_Projects\\SDL\\android\\SDL-release-2.28.5\\android-project\\app\\jni\\Application.mk" ^
        "APP_ABI=arm64-v8a" ^
        "NDK_ALL_ABIS=arm64-v8a" ^
        "NDK_DEBUG=1" ^
        "NDK_OUT=E:\\_Projects\\SDL\\android\\SDL-release-2.28.5\\android-project\\app\\build\\intermediates\\cxx\\Debug\\29445a3u/obj" ^
        "NDK_LIBS_OUT=E:\\_Projects\\SDL\\android\\SDL-release-2.28.5\\android-project\\app\\build\\intermediates\\cxx\\Debug\\29445a3u/lib" ^
        "APP_PLATFORM=android-19" ^
        "APP_SHORT_COMMANDS=false" ^
        "LOCAL_SHORT_COMMANDS=false" ^
        -B ^
        -n
    from E:\_Projects\SDL\android\SDL-release-2.28.5\android-project\app
  E:/AppData/Android/SDK/ndk/25.1.8937393/build/../build/core/build-binary.mk:586: Android NDK: Module main depends on undefined modules: SDL2
  E:/AppData/Android/SDK/ndk/25.1.8937393/build/../build/core/build-binary.mk:599: *** Android NDK: Note that old versions of ndk-build silently ignored this error case. If your project worked on those versions, the missing libraries were not needed and you can remove those dependencies from the module to fix your build. Alternatively, set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies. . Stop.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 11s
14 actionable tasks: 14 executed

```

---

<div class="post-metadata">

**Author:** ![yataro](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/y/6de8d8/32.png) [@yataro](https://discourse.libsdl.org/u/yataro)\
**Post date:** [December 27, 2023, 3:19pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/6 "2023-12-27T15:19:53Z")

</div>

> [@8Observer8](#):
>
> I executed this command: `"./androidbuild.sh" org.libsdl.testgles ../test/testgles.c`

Are you sure that scripts runs at all?

> [@8Observer8](#):
>
> I don’t understand what is the next step in this manual: [SDL/docs/README-android.md at main · libsdl-org/SDL · GitHub](https://github.com/libsdl-org/SDL/blob/main/docs/README-android.md) But I see the next step in this one: [SDL2/Android - SDL Wiki](https://wiki.libsdl.org/SDL2/Android)
> 
> > - Follow the instructions to install on your device:

These are commands to install the application on the device/emulator.

> [@8Observer8](#):
>
> I try to go to the `SDL-release-2.28.5\android-project` folder and execute of this command `"./gradlew" installDebug` But I again get the same error as in the first message:

You should execute the script to create a project or do it manually by copying SDL sources to the `jni` folder.

---

<div class="post-metadata">

**Author:** ![8Observer8](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://discourse.libsdl.org/u/8Observer8)\
**Post date:** [December 27, 2023, 5:33pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/7 "2023-12-27T17:33:00Z")

</div>

> [@yataro](#):
>
> Are you sure that scripts runs at all?

Yes, because the `test` directory was generated. And I did not see any error messages.

![image](https://discourse.libsdl.org/uploads/default/original/2X/d/d4a6b4d3f5cb2f3840930660ab56fb1846a90e83.png)

> [@yataro](#):
>
> These are commands to install the application on the device/emulator.

I just follow the manual. It says:

1. Go to the `build-scripts` director. I did it.
2. Compile a sample app (calls ndk-build) with the command: `./androidbuild.sh org.libsdl.testgles ../test/testgles.c`. I did it. The `test` directory was generated.
3. Go to the `SDL2/build/org.libsdl.testgles` and execute `./gradlew installDebug`. But I didn’t find this directory. There is no the `build` directory in the root of the SDL folder.

> [@yataro](#):
>
> You should execute the script to create a project

What script?

---

<div class="post-metadata">

**Author:** ![8Observer8](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://discourse.libsdl.org/u/8Observer8)\
**Post date:** [December 27, 2023, 5:36pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/8 "2023-12-27T17:36:37Z")

</div>

The `test` directory was generated here:

![image](https://discourse.libsdl.org/uploads/default/original/2X/c/cd7a07c98f3ff55f4b37b48806cbf4e3241b316e.png)

---

<div class="post-metadata">

**Author:** ![8Observer8](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://discourse.libsdl.org/u/8Observer8)\
**Post date:** [December 27, 2023, 5:44pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/9 "2023-12-27T17:44:43Z")

</div>

> [@yataro](#):
>
> or do it manually by copying SDL sources to the `jni` folder.

Where to create the `jni` folder? Inside the `SDL-release-2.28.5\android-project`?

- I created the empty `jni` folder inside `SDL-release-2.28.5\android-project`:

![image](https://discourse.libsdl.org/uploads/default/original/2X/4/4d6481021ae46d887319e2bf22c55d994244700a.png)

- I copied the content of the `SDL-release-2.28.5\src` folder to the `SDL-release-2.28.5\android-project\jni`:

![image](https://discourse.libsdl.org/uploads/default/original/2X/6/62cab756ff7a64d7b7eb70b69f76344c716aca27.png)

- I go to the `SDL-release-2.28.5\android-project` folder and execute the `"./gradlew" build ` command:

```auto
E:\_Projects\SDL\android\SDL-release-2.28.5\android-project>"./gradlew" build
> Task :app:configureNdkBuildDebug[arm64-v8a] FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:configureNdkBuildDebug[arm64-v8a]'.
> [CXX1429] error when building with ndkBuild using E:\_Projects\SDL\android\SDL-release-2.28.5\android-project\app\jni\Android.mk: C++ build system [configure] failed while executing:
      @echo off
      "E:\\AppData\\Android\\SDK\\ndk\\25.1.8937393\\ndk-build.cmd" ^
        "NDK_PROJECT_PATH=null" ^
        "APP_BUILD_SCRIPT=E:\\_Projects\\SDL\\android\\SDL-release-2.28.5\\android-project\\app\\jni\\Android.mk" ^
        "NDK_APPLICATION_MK=E:\\_Projects\\SDL\\android\\SDL-release-2.28.5\\android-project\\app\\jni\\Application.mk" ^
        "APP_ABI=arm64-v8a" ^
        "NDK_ALL_ABIS=arm64-v8a" ^
        "NDK_DEBUG=1" ^
        "NDK_OUT=E:\\_Projects\\SDL\\android\\SDL-release-2.28.5\\android-project\\app\\build\\intermediates\\cxx\\Debug\\29445a3u/obj" ^
        "NDK_LIBS_OUT=E:\\_Projects\\SDL\\android\\SDL-release-2.28.5\\android-project\\app\\build\\intermediates\\cxx\\Debug\\29445a3u/lib" ^
        "APP_PLATFORM=android-19" ^
        "APP_SHORT_COMMANDS=false" ^
        "LOCAL_SHORT_COMMANDS=false" ^
        -B ^
        -n
    from E:\_Projects\SDL\android\SDL-release-2.28.5\android-project\app
  E:/AppData/Android/SDK/ndk/25.1.8937393/build/../build/core/build-binary.mk:586: Android NDK: Module main depends on undefined modules: SDL2
  E:/AppData/Android/SDK/ndk/25.1.8937393/build/../build/core/build-binary.mk:599: *** Android NDK: Note that old versions of ndk-build silently ignored this error case. If your project worked on those versions, the missing libraries were not needed and you can remove those dependencies from the module to fix your build. Alternatively, set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies. . Stop.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 46s
15 actionable tasks: 2 executed, 13 up-to-date

```

---

<div class="post-metadata">

**Author:** ![8Observer8](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://discourse.libsdl.org/u/8Observer8)\
**Post date:** [December 27, 2023, 6:04pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/10 "2023-12-27T18:04:14Z")

</div>

I tried to execute this script again after coping source files to `jni`: `"./androidbuild.sh" org.libsdl.testgles ../test/testgles.c`

I ran this script in the `android-project` folder: `"./gradlew" build`. I have the same errors:

```auto
E:\_Projects\SDL\android\SDL-release-2.28.5\android-project>"./gradlew" build

> Task :app:compileDebugJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

> Task :app:configureNdkBuildDebug[arm64-v8a] FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:configureNdkBuildDebug[arm64-v8a]'.
> [CXX1429] error when building with ndkBuild using E:\_Projects\SDL\android\SDL-release-2.28.5\android-project\app\jni\Android.mk: C++ build system [configure] failed while executing:
      @echo off
      "E:\\AppData\\Android\\SDK\\ndk\\25.1.8937393\\ndk-build.cmd" ^
        "NDK_PROJECT_PATH=null" ^
        "APP_BUILD_SCRIPT=E:\\_Projects\\SDL\\android\\SDL-release-2.28.5\\android-project\\app\\jni\\Android.mk" ^
        "NDK_APPLICATION_MK=E:\\_Projects\\SDL\\android\\SDL-release-2.28.5\\android-project\\app\\jni\\Application.mk" ^
        "APP_ABI=arm64-v8a" ^
        "NDK_ALL_ABIS=arm64-v8a" ^
        "NDK_DEBUG=1" ^
        "NDK_OUT=E:\\_Projects\\SDL\\android\\SDL-release-2.28.5\\android-project\\app\\build\\intermediates\\cxx\\Debug\\29445a3u/obj" ^
        "NDK_LIBS_OUT=E:\\_Projects\\SDL\\android\\SDL-release-2.28.5\\android-project\\app\\build\\intermediates\\cxx\\Debug\\29445a3u/lib" ^
        "APP_PLATFORM=android-19" ^
        "APP_SHORT_COMMANDS=false" ^
        "LOCAL_SHORT_COMMANDS=false" ^
        -B ^
        -n
    from E:\_Projects\SDL\android\SDL-release-2.28.5\android-project\app
  E:/AppData/Android/SDK/ndk/25.1.8937393/build/../build/core/build-binary.mk:586: Android NDK: Module main depends on undefined modules: SDL2
  E:/AppData/Android/SDK/ndk/25.1.8937393/build/../build/core/build-binary.mk:599: *** Android NDK: Note that old versions of ndk-build silently ignored this error case. If your project worked on those versions, the missing libraries were not needed and you can remove those dependencies from the module to fix your build. Alternatively, set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies. . Stop.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 14s
16 actionable tasks: 2 executed, 14 up-to-date

```

---

<div class="post-metadata">

**Author:** ![rtrussell](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/rtrussell/32/4768_2.png) [@rtrussell](https://discourse.libsdl.org/u/rtrussell)\
**Post date:** [December 28, 2023, 7:32pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/11 "2023-12-28T19:32:52Z")

</div>

> [@8Observer8](#):
>
> Or does OpenGL 1.1 work on Android?

Yes, OpenGL 1.1 works on Android. I rely on it in my app.

---

<div class="post-metadata">

**Author:** ![8Observer8](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://discourse.libsdl.org/u/8Observer8)\
**Post date:** [December 28, 2023, 8:48pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/12 "2023-12-28T20:48:05Z")

</div>

I solved the problem. @Captain helped me on SDL-discord server. He recommended this manual and helped when I had problems:

- Part 1: [GitHub - Ravbug/sdl3-sample: Minimal HowTo for building and using SDL3 on a variety of platforms, including mobile](https://github.com/Ravbug/sdl3-sample/tree/main)
- Part 2: [https://github.com/Ravbug/sdl3-sample/blob/main/config/README.md](https://github.com/Ravbug/sdl3-sample/blob/main/config/README.md)

Note. This manual works for Android. Except “Ninja” app that must be installed (and added to Path, I used one from Qt: `C:\Qt\Tools\Ninja` ) and manually changing of CMake version in the `build.gradle` script.

I use [scrcpy](https://github.com/Genymobile/scrcpy) to show an Android screen on Laptop to make screenshots. I connected a phone using USB.

![image](https://discourse.libsdl.org/uploads/default/original/2X/e/eb4e3d0445f1d89c450b53dffd7eb7621b35d8ba.png)

 ![image](https://discourse.libsdl.org/uploads/default/original/2X/c/c8b9befd6e0ac2b7ddefff6e20477d6f6dd6e072.png)

---

<div class="post-metadata">

**Author:** ![alisanDogn](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/dfb087/32.png) [@alisanDogn](https://discourse.libsdl.org/u/alisanDogn)\
**Post date:** [April 29, 2024, 6:22pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/13 "2024-04-29T18:22:51Z")

</div>

Can you help me?  
I’m currently experiencing the same problems

---

<div class="post-metadata">

**Author:** ![8Observer8](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://discourse.libsdl.org/u/8Observer8)\
**Post date:** [April 29, 2024, 7:39pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/14 "2024-04-29T19:39:30Z")

</div>

@alisanDogn let’s try to build [the SDL3 example](https://github.com/Ravbug/sdl3-sample/tree/main) and run it on Android. Let’s make the following steps to understand what step stops you:

- Open CMD and execute this command: `git clone https://github.com/Ravbug/sdl3-sample --depth=1 --recurse-submodules`

That command will download the example and SDL3 source code. All requires 155 MB.

You will see the `build.gradle` file here:

![image](https://discourse.libsdl.org/uploads/default/original/2X/6/602e6e09e46f3abeabd2242d7fe2268c1fb526a5.png)

- You should copy it to this folder: `sdl3-sample\SDL\android-project\app`

- Go to the `sdl3-sample\SDL\android-project` folder in CMD and execute this command: `gradlew assembleDebug`

Wait a few minutes for building. At first time it is very long - 13 minutes on my laptop. But next builds will be much faster. `sdl3-sample` requires 327 MB after building for Android.

- APK-file will be created here: `sdl3-sample\SDL\android-project\app\build\outputs\apk\debug`

![image](https://discourse.libsdl.org/uploads/default/original/2X/3/358ec3b3f172ed6a78f0e7e0a9bb58a03054a43e.png)

---

<div class="post-metadata">

**Author:** ![alisanDogn](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/dfb087/32.png) [@alisanDogn](https://discourse.libsdl.org/u/alisanDogn)\
**Post date:** [April 29, 2024, 7:45pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/15 "2024-04-29T19:45:52Z")

</div>

Thank you very much for your reply. I will try this right away.

---

<div class="post-metadata">

**Author:** ![8Observer8](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://discourse.libsdl.org/u/8Observer8)\
**Post date:** [April 29, 2024, 7:56pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/16 "2024-04-29T19:56:40Z")

</div>

Yes, it must work. I have tried it right now. I recommend you to connect your phone with USB-cable. Execute this command: `gradlew installDebug`. The application will be installed on your device. It requires 38 seconds on my laptop. A source code of the example is here: `sdl3-sample\src` in the main.cpp file. I tried to change the background color to this color:

```cpp
    auto red = 255;
    auto green = 50;
    auto blue = 100;
    
    SDL_SetRenderDrawColor(app->renderer, red, green, blue, SDL_ALPHA_OPAQUE);

```

It works:

![image](https://discourse.libsdl.org/uploads/default/original/2X/e/e652c9f2b5018df7395dc0279357a3d34c92f50c.png)

---

<div class="post-metadata">

**Author:** ![alisanDogn](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/dfb087/32.png) [@alisanDogn](https://discourse.libsdl.org/u/alisanDogn)\
**Post date:** [April 29, 2024, 8:01pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/17 "2024-04-29T20:01:39Z")

</div>

I got an error like this: C:\Users\alisa\OneDrive\lasttest\sdl3-sample\SDL\android-project\> ./gradlew assembleDebug

> >

Starting a Gradle Daemon, 3 incompatible and 1 stopped Daemons could not be reused, use --status for details  
\<—\<—\<—\<—\<—\<—\<—\<—\<—\<—\<—\<—\<—\<—\<-\<-\<-\<-\<-\<-  
FAILURE: Build failed with an exception. \> Evaluating\> \> \> root\> \> root project

- Where:  
Build file ‘C:\Users\alisa\OneDrive\lasttest\sdl3-sample\SDL\android-project\build.gradle’ line: 4

- What went wrong:  
A problem occurred evaluating root project ‘android-project’.

> Plugin with id ‘com.android.application’ not found.

---

<div class="post-metadata">

**Author:** ![8Observer8](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://discourse.libsdl.org/u/8Observer8)\
**Post date:** [April 29, 2024, 8:14pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/18 "2024-04-29T20:14:14Z")

</div>

What Gradle version do you have? Please, execute this: `gradle -v`

---

<div class="post-metadata">

**Author:** ![alisanDogn](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/dfb087/32.png) [@alisanDogn](https://discourse.libsdl.org/u/alisanDogn)\
**Post date:** [April 29, 2024, 8:14pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/19 "2024-04-29T20:14:55Z")

</div>

my gradle version:8.1.1

---

<div class="post-metadata">

**Author:** ![8Observer8](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://discourse.libsdl.org/u/8Observer8)\
**Post date:** [April 29, 2024, 8:15pm UTC](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021/20 "2024-04-29T20:15:59Z")

</div>

Sorry, no ideas. Try to ask on discord. Please, write here when you solve the problem.

[Next page](https://discourse.libsdl.org/t/how-to-build-a-sdl2-application-for-android-using-command-line/48021.md?page=2)
