-
Notifications
You must be signed in to change notification settings - Fork 52
Add android support for the game engine. #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| = Android Project for Vulkan Tutorial | ||
|
|
||
| This Android project allows you to run different chapters of the Vulkan Tutorial on Android devices. | ||
|
|
||
| == Selecting a Chapter | ||
|
|
||
| By default, the project builds and runs the `34_android` chapter. You can select a different chapter by setting the `chapter` property in your Gradle build. | ||
|
|
||
| === Available Chapters | ||
|
|
||
| * `34_android`: The Android chapter that uses tinyobjloader to load OBJ models | ||
| * `35_gltf_ktx`: The glTF and KTX chapter that uses tinygltf to load glTF models and KTX to load KTX2 textures | ||
|
|
||
| === How to Select a Chapter | ||
|
|
||
| ==== From the Command Line | ||
|
|
||
| [source,bash] | ||
| ---- | ||
| ./gradlew assembleDebug -Pchapter=35_gltf_ktx | ||
| ---- | ||
|
|
||
| ==== From Android Studio | ||
|
|
||
| 1. Edit the `gradle.properties` file in the project root directory | ||
| 2. Add the following line: | ||
| + | ||
| [source] | ||
| ---- | ||
| chapter=35_gltf_ktx | ||
| ---- | ||
| 3. Sync the project and build | ||
|
|
||
| == Adding New Chapters | ||
|
|
||
| To add support for a new chapter: | ||
|
|
||
| 1. Add the chapter name to the `SUPPORTED_CHAPTERS` list in `app/src/main/cpp/CMakeLists.txt` | ||
| 2. Add any chapter-specific libraries and compile definitions in the same file | ||
| 3. Make sure the chapter's source file exists in the `attachments` directory | ||
|
|
||
| For example, to add support for a hypothetical `36_new_feature` chapter: | ||
|
|
||
| [source,cmake] | ||
| ---- | ||
| # Define the list of supported chapters | ||
| set(SUPPORTED_CHAPTERS | ||
| "34_android" | ||
| "35_gltf_ktx" | ||
| "36_new_feature" | ||
| ) | ||
|
|
||
| # Add chapter-specific libraries and definitions | ||
| if(CHAPTER STREQUAL "34_android") | ||
| # ... | ||
| elseif(CHAPTER STREQUAL "35_gltf_ktx") | ||
| # ... | ||
| elseif(CHAPTER STREQUAL "36_new_feature") | ||
| target_link_libraries(vulkan_tutorial_android | ||
| # Add any required libraries here | ||
| ) | ||
|
|
||
| target_compile_definitions(vulkan_tutorial_android PRIVATE | ||
| # Add any required compile definitions here | ||
| ) | ||
| endif() | ||
| ---- | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| plugins { | ||
| id 'com.android.application' | ||
| } | ||
|
|
||
| android { | ||
| namespace "com.simple_engine" | ||
| compileSdk 36 | ||
| defaultConfig { | ||
| applicationId "com.simple_engine" | ||
| minSdk 24 | ||
| targetSdk 36 | ||
| versionCode 1 | ||
| versionName "1.0" | ||
|
|
||
| externalNativeBuild { | ||
| cmake { | ||
| abiFilters 'arm64-v8a', 'x86_64' | ||
| } | ||
| } | ||
| } | ||
|
|
||
| buildTypes { | ||
| release { | ||
| minifyEnabled false | ||
| proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
| } | ||
| } | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility JavaVersion.VERSION_11 | ||
| targetCompatibility JavaVersion.VERSION_11 | ||
| } | ||
|
|
||
| externalNativeBuild { | ||
| cmake { | ||
| path "src/main/cpp/CMakeLists.txt" | ||
| version "4.0.2+" | ||
| } | ||
| } | ||
|
|
||
| ndkVersion "28.1.13356709" | ||
|
|
||
| // Use assets from the dedicated assets directory and locally compiled shaders | ||
| sourceSets { | ||
| main { | ||
| assets { | ||
| srcDirs = [ | ||
| // Point to the dedicated assets directory | ||
| '../../Assets/' | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| buildFeatures { | ||
| prefab true | ||
| buildConfig true | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation 'androidx.appcompat:appcompat:1.7.1' | ||
| implementation 'com.google.android.material:material:1.12.0' | ||
| implementation 'androidx.games:games-activity:4.0.0' | ||
| } |
29 changes: 29 additions & 0 deletions
29
attachments/simple_engine/android/app/src/main/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <!-- Declare that this app uses Vulkan --> | ||
| <uses-feature android:name="android.hardware.vulkan.version" android:version="0x400003" android:required="true" /> | ||
| <uses-feature android:name="android.hardware.vulkan.level" android:version="0" android:required="true" /> | ||
|
|
||
| <application | ||
| android:allowBackup="true" | ||
| android:fullBackupContent="@xml/backup_rules" | ||
| android:dataExtractionRules="@xml/data_extraction_rules" | ||
| android:label="@string/app_name" | ||
| android:supportsRtl="true" | ||
| android:theme="@style/AppTheme"> | ||
| <activity | ||
| android:name=".VulkanActivity" | ||
| android:configChanges="orientation|keyboardHidden|screenSize" | ||
| android:theme="@android:style/Theme.NoTitleBar.Fullscreen" | ||
| android:exported="true"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| <meta-data | ||
| android:name="android.app.lib_name" | ||
| android:value="simple_engine_android" /> | ||
| </activity> | ||
| </application> | ||
|
|
||
| </manifest> |
29 changes: 29 additions & 0 deletions
29
attachments/simple_engine/android/app/src/main/cpp/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| cmake_minimum_required(VERSION 3.22.1) | ||
|
|
||
| project(simple_engine_android) | ||
|
|
||
| # Add the parent project's cmake folder to the module path | ||
| list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/CMake") | ||
|
|
||
| # Include the game-activity library | ||
| find_package(game-activity REQUIRED CONFIG) | ||
|
|
||
| # Set C++ standard to match the main project | ||
| set(CMAKE_CXX_STANDARD 20) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
|
||
| # Add the simple_engine project as a subdirectory | ||
| add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../../../.." simple_engine_build) | ||
|
|
||
| # Add the main native library | ||
| add_library(simple_engine_android SHARED | ||
| game_activity_bridge.cpp | ||
| ) | ||
|
|
||
| # Link against libraries | ||
| target_link_libraries(simple_engine_android | ||
| SimpleEngine | ||
| game-activity::game-activity | ||
| android | ||
| log | ||
| ) |
13 changes: 13 additions & 0 deletions
13
attachments/simple_engine/android/app/src/main/cpp/game_activity_bridge.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Intentionally empty bridge: rely entirely on GameActivity's native_app_glue | ||
| // provided by the prefab (libgame-activity). That glue will invoke our | ||
| // android_main(android_app*) defined in main.cpp. Defining another | ||
| // GameActivity_onCreate here causes duplicate symbol linker errors. | ||
| // Keeping a translation unit avoids removing the target from CMake. | ||
|
|
||
| #include <android/log.h> | ||
|
|
||
| #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "SimpleEngine", __VA_ARGS__)) | ||
| #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "SimpleEngine", __VA_ARGS__)) | ||
| #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "SimpleEngine", __VA_ARGS__)) | ||
|
|
||
| // Nothing to do here. |
20 changes: 20 additions & 0 deletions
20
attachments/simple_engine/android/app/src/main/java/com/simple_engine/VulkanActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.simple_engine; | ||
|
|
||
| import android.os.Bundle; | ||
| import android.view.WindowManager; | ||
| import com.google.androidgamesdk.GameActivity; | ||
|
|
||
| public class VulkanActivity extends GameActivity { | ||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
|
|
||
| // Keep the screen on while the app is running | ||
| getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); | ||
| } | ||
|
|
||
| // Load the native library | ||
| static { | ||
| System.loadLibrary("simple_engine_android"); | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
attachments/simple_engine/android/app/src/main/res/values/strings.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <resources> | ||
| <string name="app_name">Simple Engine</string> | ||
| </resources> |
6 changes: 6 additions & 0 deletions
6
attachments/simple_engine/android/app/src/main/res/values/styles.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <resources> | ||
| <!-- Base application theme --> | ||
| <style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar"> | ||
| <!-- Customize your theme here --> | ||
| </style> | ||
| </resources> |
9 changes: 9 additions & 0 deletions
9
attachments/simple_engine/android/app/src/main/res/xml/backup_rules.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <full-backup-content> | ||
| <!-- Backup everything by default --> | ||
| <include domain="root" path="."/> | ||
| <include domain="file" path="."/> | ||
| <include domain="database" path="."/> | ||
| <include domain="sharedpref" path="."/> | ||
| <include domain="external" path="."/> | ||
| </full-backup-content> |
19 changes: 19 additions & 0 deletions
19
attachments/simple_engine/android/app/src/main/res/xml/data_extraction_rules.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <data-extraction-rules> | ||
| <cloud-backup> | ||
| <!-- Include all data by default --> | ||
| <include domain="root" path="."/> | ||
| <include domain="file" path="."/> | ||
| <include domain="database" path="."/> | ||
| <include domain="sharedpref" path="."/> | ||
| <include domain="external" path="."/> | ||
| </cloud-backup> | ||
| <device-transfer> | ||
| <!-- Include all data by default --> | ||
| <include domain="root" path="."/> | ||
| <include domain="file" path="."/> | ||
| <include domain="database" path="."/> | ||
| <include domain="sharedpref" path="."/> | ||
| <include domain="external" path="."/> | ||
| </device-transfer> | ||
| </data-extraction-rules> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.