Skip to content

Commit

Permalink
Android build fixes (#1156)
Browse files Browse the repository at this point in the history
* Add gradle build scripts to more examples

* Fix building graphicspipelinelibrary example on android

* Fix tinygltf dependencies

hostimagecopy uses tinygltf but didn't depend on it, while meshshader doesn't use it.

* Load more Vulkan functions on Android

The sparse functions are used by texturesparseresidency, while the begin/end rendering functions are used by trianglevulkan13.
  • Loading branch information
w-pearson authored Oct 8, 2024
1 parent a2d5a1f commit 358babf
Show file tree
Hide file tree
Showing 65 changed files with 2,734 additions and 16 deletions.
35 changes: 35 additions & 0 deletions android/examples/conditionalrender/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.4.1 FATAL_ERROR)

set(NAME conditionalrender)

set(SRC_DIR ../../../examples/${NAME})
set(BASE_DIR ../../../base)
set(EXTERNAL_DIR ../../../external)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -DVK_USE_PLATFORM_ANDROID_KHR -DVK_NO_PROTOTYPES")

file(GLOB EXAMPLE_SRC "${SRC_DIR}/*.cpp")

add_library(native-lib SHARED ${EXAMPLE_SRC})

add_library(native-app-glue STATIC ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

add_subdirectory(../base ${CMAKE_SOURCE_DIR}/../base)

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")

include_directories(${BASE_DIR})
include_directories(${EXTERNAL_DIR})
include_directories(${EXTERNAL_DIR}/glm)
include_directories(${EXTERNAL_DIR}/imgui)
include_directories(${EXTERNAL_DIR}/tinygltf)
include_directories(${ANDROID_NDK}/sources/android/native_app_glue)

target_link_libraries(
native-lib
native-app-glue
libbase
android
log
z
)
64 changes: 64 additions & 0 deletions android/examples/conditionalrender/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apply plugin: 'com.android.application'
apply from: '../gradle/outputfilename.gradle'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "de.saschawillems.vulkanConditionalrender"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
ndk {
abiFilters rootProject.ext.abiFilters
}
externalNativeBuild {
cmake {
cppFlags "-std=c++14"
arguments "-DANDROID_STL=c++_shared", '-DANDROID_TOOLCHAIN=clang'
}
}
}
sourceSets {
main.assets.srcDirs = ['assets']
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}

task copyTask {
copy {
from '../../common/res/drawable'
into "src/main/res/drawable"
include 'icon.png'
}

copy {
from rootProject.ext.shaderPath + 'glsl/base'
into 'assets/shaders/glsl/base'
include '*.spv'
}

copy {
from rootProject.ext.shaderPath + 'glsl/conditionalrender'
into 'assets/shaders/glsl/conditionalrender'
include '*.*'
}

copy {
from rootProject.ext.assetPath + 'models/gltf/glTF-Embedded'
into 'assets/models/gltf/glTF-Embedded'
include 'Buggy.gltf'
}
}

preBuild.dependsOn copyTask
24 changes: 24 additions & 0 deletions android/examples/conditionalrender/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.saschawillems.vulkanConditionalrender">

<application
android:label="Vulkan conditional render"
android:icon="@drawable/icon"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<activity android:name="de.saschawillems.vulkanSample.VulkanActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.lib_name"
android:value="native-lib" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.gamepad" android:required="false" />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2018 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
package de.saschawillems.vulkanSample;

import android.app.AlertDialog;
import android.app.NativeActivity;
import android.content.DialogInterface;
import android.content.pm.ApplicationInfo;
import android.os.Bundle;

import java.util.concurrent.Semaphore;

public class VulkanActivity extends NativeActivity {

static {
// Load native library
System.loadLibrary("native-lib");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

// Use a semaphore to create a modal dialog

private final Semaphore semaphore = new Semaphore(0, true);

public void showAlert(final String message)
{
final VulkanActivity activity = this;

ApplicationInfo applicationInfo = activity.getApplicationInfo();
final String applicationName = applicationInfo.nonLocalizedLabel.toString();

this.runOnUiThread(new Runnable() {
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(activity, android.R.style.Theme_Material_Dialog_Alert);
builder.setTitle(applicationName);
builder.setMessage(message);
builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
semaphore.release();
}
});
builder.setCancelable(false);
AlertDialog dialog = builder.create();
dialog.show();
}
});
try {
semaphore.acquire();
}
catch (InterruptedException e) { }
}
}
35 changes: 35 additions & 0 deletions android/examples/debugprintf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.4.1 FATAL_ERROR)

set(NAME debugprintf)

set(SRC_DIR ../../../examples/${NAME})
set(BASE_DIR ../../../base)
set(EXTERNAL_DIR ../../../external)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -DVK_USE_PLATFORM_ANDROID_KHR -DVK_NO_PROTOTYPES")

file(GLOB EXAMPLE_SRC "${SRC_DIR}/*.cpp")

add_library(native-lib SHARED ${EXAMPLE_SRC})

add_library(native-app-glue STATIC ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

add_subdirectory(../base ${CMAKE_SOURCE_DIR}/../base)

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")

include_directories(${BASE_DIR})
include_directories(${EXTERNAL_DIR})
include_directories(${EXTERNAL_DIR}/glm)
include_directories(${EXTERNAL_DIR}/imgui)
include_directories(${EXTERNAL_DIR}/tinygltf)
include_directories(${ANDROID_NDK}/sources/android/native_app_glue)

target_link_libraries(
native-lib
native-app-glue
libbase
android
log
z
)
65 changes: 65 additions & 0 deletions android/examples/debugprintf/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apply plugin: 'com.android.application'
apply from: '../gradle/outputfilename.gradle'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "de.saschawillems.vulkanDebugprintf"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
ndk {
abiFilters rootProject.ext.abiFilters
}
externalNativeBuild {
cmake {
cppFlags "-std=c++14"
arguments "-DANDROID_STL=c++_shared", '-DANDROID_TOOLCHAIN=clang'
}
}
}
sourceSets {
main.assets.srcDirs = ['assets']
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}

task copyTask {
copy {
from '../../common/res/drawable'
into "src/main/res/drawable"
include 'icon.png'
}

copy {
from rootProject.ext.shaderPath + 'glsl/base'
into 'assets/shaders/glsl/base'
include '*.spv'
}

copy {
from rootProject.ext.shaderPath + 'glsl/debugprintf'
into 'assets/shaders/glsl/debugprintf'
include '*.*'
}

copy {
from rootProject.ext.assetPath + 'models'
into 'assets/models'
include 'treasure_smooth.gltf'
}

}

preBuild.dependsOn copyTask
24 changes: 24 additions & 0 deletions android/examples/debugprintf/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.saschawillems.vulkanDebugprintf">

<application
android:label="Vulkan debug printf"
android:icon="@drawable/icon"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<activity android:name="de.saschawillems.vulkanSample.VulkanActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.lib_name"
android:value="native-lib" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.gamepad" android:required="false" />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2018 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
package de.saschawillems.vulkanSample;

import android.app.AlertDialog;
import android.app.NativeActivity;
import android.content.DialogInterface;
import android.content.pm.ApplicationInfo;
import android.os.Bundle;

import java.util.concurrent.Semaphore;

public class VulkanActivity extends NativeActivity {

static {
// Load native library
System.loadLibrary("native-lib");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

// Use a semaphore to create a modal dialog

private final Semaphore semaphore = new Semaphore(0, true);

public void showAlert(final String message)
{
final VulkanActivity activity = this;

ApplicationInfo applicationInfo = activity.getApplicationInfo();
final String applicationName = applicationInfo.nonLocalizedLabel.toString();

this.runOnUiThread(new Runnable() {
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(activity, android.R.style.Theme_Material_Dialog_Alert);
builder.setTitle(applicationName);
builder.setMessage(message);
builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
semaphore.release();
}
});
builder.setCancelable(false);
AlertDialog dialog = builder.create();
dialog.show();
}
});
try {
semaphore.acquire();
}
catch (InterruptedException e) { }
}
}
Loading

0 comments on commit 358babf

Please sign in to comment.