1. Download and unzip the SDL source code
Download Link: https://libsdl.org/download-2.0.php
2. Import the Project
2-1. Import the project,
2-2. Locate the downloaded SDL source code, select Android-project, click OK,
2-3. Select an empty directory, as an imported Android catalog, then click Next,
2-4. If the directory does not exist, then pop up the following box, click OK, create a new directory
2-5. Click Finish to start building the project, and so it is built
3. Modify configuration information and fix various errors
3-1. Because I am using Android Studio 3.0, it prompts me that the minimum gradle must be more than 4.1
Workaround: It is obvious that the gradle-wrapper.properties file under the wrapper directory under the project is modified. I changed directly to 4.2 because I have downloaded 4.2 gradle, such as:
3-2. Modify the Build.gralde file under the app, modify the Compilesdkversion, add abifilters only need arm architecture, add ndkbuild to use NDK to compile, as follows:
3-3. Create a folder named SDL under the JNI directory and copy the include, SRC, and android.mk files from the SDL source code, as shown in:
3-4. Create a source code named YOURSOURCEHERE.C in the SRC directory under the JNI directory, which is the entry for the main function, nothing to do, just to keep the error, as shown below:
The location of the yoursourcehere.c source file is as shown in the figure, and you can see why the Created folder name is SDL, why the. C source file is named yoursourcehere.c, and if you want to create another name, you just need to modify the right name accordingly.
3-5. Modify the Application.mk file, open the App_stl annotation to indicate the use of the standard library, modify the App_platform, and so on, as shown:
4. Build the project to generate the so dynamic library
4-1. Build the step, first click on the button of Figure 1 to build the project, after the successful build, then click on the button of Figure 2 to build the so dynamic library, as shown in:
4-2. Final build results, such as:
Libsdl2.so is what we expect dynamic library, is the JNI/SDL directory source files generated by the dynamic library, and Libmain.so Library is jni/src under the yoursourcehere.c source file generated so dynamic library. All the compilation work is completed.
Steps to compile the SDL library under Android Studio