Integrating compiled libSDL3_image.so on Android Интеграция собранной библиотеки libSDL3_image.so на Android
A step-by-step guide to adding SDL3_image support to your Android project, handling asset copying via CMake, and rendering textures on mobile devices. Пошаговое руководство по добавлению поддержки SDL3_image в ваш Android-проект, автоматической копировании ассетов через CMake и отрисовке текстур на мобильных устройствах.
Step 1: Download Base Template and Rename Project Шаг 1: Скачивание базового шаблона и переименование проекта
First, download the base starter project template depending on your language preference: Сначала скачайте базовый шаблон проекта в зависимости от используемого языка:
Rename your project folder to integrate-sdl3-image-android-c (or integrate-sdl3-image-android-cpp).
Переименуйте папку проекта в integrate-sdl3-image-android-c (или integrate-sdl3-image-android-cpp).
Step 2: Update CMakeLists.txt Шаг 2: Обновление CMakeLists.txt
Open CMakeLists.txt in the root directory and update it to link both SDL3 and SDL3_image libraries:
Откройте CMakeLists.txt в корне проекта и обновите его для связывания обоих библиотек (SDL3 и SDL3_image):
Step 3: Configure Gradle Source Sets Шаг 3: Настройка Source Sets в Gradle
Open android-project/app/build.gradle and set the sourceSets block inside android { ... }. This instructs Gradle to bundle assets directly from the project's root assets folder:
Откройте android-project/app/build.gradle и настройте блок sourceSets внутри android { ... }. Это укажет Gradle упаковывать ассеты напрямую из корневой папки assets:
android {
namespace "com.example.myapp"
compileSdkVersion 35
defaultConfig {
// ...
}
// Direct Gradle to fetch assets straight from the root project folder
sourceSets {
main {
assets.srcDirs = ['../../assets']
}
}
externalNativeBuild {
cmake {
path '../../CMakeLists.txt'
}
}
}
Step 4: Setup Project Assets Шаг 4: Настройка ресурсов (Assets)
1. Download a free texture, such as a crate texture from OpenGameArt Crate 5. 1. Скачайте бесплатную текстуру, например, ящик с сайта OpenGameArt Crate 5.
2. Create a new directory path in the root folder: assets/images.
2. Создайте новую папку в корне вашего проекта: assets/images.
3. Place the downloaded image into assets/images and rename it to crate.png.
3. Поместите скачанное изображение в assets/images и переименуйте его в crate.png.
Step 5: Write the C Source Code Шаг 5: Написание исходного кода на C
Replace the contents of src/main.c with the following code to load and display textures using SDL3_image:
Замените содержимое файла src/main.c следующим кодом для загрузки и отображения текстур с помощью SDL3_image:
Step 6: Build and Run on Android Шаг 6: Сборка и запуск на Android
Run the provided helper scripts in your command prompt to compile the app and push it directly to your connected device: Запустите готовые батч-скрипты в командной строке для сборки и автоматической установки на подключенное устройство:
build-apk
install-apk
Once installed, tap the application icon on your smartphone to launch it and view the rendered crate textures. После завершения установки нажмите на иконку приложения на смартфоне, чтобы запустить его и увидеть отрисованные текстуры ящика.
Source Code Исходный код
You can explore the source code and download the complete project directly from the GitHub repositories: Вы можете изучить исходный код и скачать готовый проект напрямую из репозиториев на GitHub:
Support My Work Поддержать проект
If these tutorials helped you, consider buying me a coffee! Если эти туториалы вам помогли, вы можете поддержать автора.
Sberbank (Russia only) Сбербанк (только для РФ)
Direct transfer via phone number (Russia only) Перевод по номеру телефона (только для РФ)
USDT TRC20
Support via Cryptocurrency Поддержка криптовалютой