Skip to content

Commit 8e993fb

Browse files
authored
AndroidStudio compatibility (#192)
With these changes we fully support the AndroidStudio IDE, files have proper intellisense, builds work, and debugging is seamless (if you have symbols in your binaries) Features: * Support for AndroidStudio. * Access to all C++ source files from all projects. * Improved 'ICE_ASSERT_CORE' to support constexpr contexts. * Updated NDK to version 28.1, which builds by default with 16KiB page support. * Retargeted Android examples to API Level 35 Fixes: * Fixed threads platform feature was missing AIOPort object. * Fixed aligned allocation crash by using 'posix_memalign' instead of 'aligned_alloc'. * Fixed various missing-symbol errors at runtime. Improvements: * Added linker flag to check for missing symbols during linking. (-Wl,-z,defs) * Added assertion to URI parsing. (including constexpr contexts) * Added assertion to Shard creation. (including constexpr contexts) Other * Tested and executed on Android emulators (x64-16KiB and armv8-4KiB)
1 parent 99dc4e0 commit 8e993fb

File tree

18 files changed

+78
-58
lines changed

18 files changed

+78
-58
lines changed

.github/workflows/build-validate-android.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
matrix:
1919
project: [all]
20-
pipeline: [Android29-ARMv8, Android29-x64]
20+
pipeline: [Android35-ARMv8,Android35-x64]
2121
config: [Debug,Develop,Profile,Release]
2222
with:
2323
host-platform: 'windows-latest'

source/code/core/core/public/ice/assert_core.hxx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,42 @@
88
#include <cassert>
99
#undef assert
1010

11+
namespace ice::detail
12+
{
13+
14+
// The following function will fail to access element at index [2] only in constexpr scenarios and when the expression is false.
15+
// This is good enough for us to create an assertion macro for constexpr and non-constexpr cases.
16+
constexpr char _iceshard_constexpr_assert(bool v) noexcept
17+
{
18+
int cev = std::is_constant_evaluated();
19+
char constexpr_assert_failure[2]{ };
20+
return constexpr_assert_failure[!v + cev];
21+
};
22+
23+
} // namespace ice::detail::assert
24+
1125
#if ISP_WINDOWS
1226

1327
#define ICE_ASSERT_CORE(expression) do { if (std::is_constant_evaluated() == false) { \
1428
(void)( \
1529
(!!(expression)) || \
1630
(_wassert(_CRT_WIDE(#expression), _CRT_WIDE(__FILE__), (unsigned)(__LINE__)), 0) \
17-
); } } while(false)
31+
); } else { ice::detail::_iceshard_constexpr_assert(expression); } } while(false)
1832

1933
#elif ISP_WEBAPP || ISP_LINUX
2034

21-
#define ICE_ASSERT_CORE(expression) ((expression) \
22-
? (void)0 \
23-
: __assert_fail(#expression, __FILE__, __LINE__, __PRETTY_FUNCTION__))
35+
#define ICE_ASSERT_CORE(expression) do { if (std::is_constant_evaluated() == false) { \
36+
((expression) \
37+
? (void)0 \
38+
: __assert_fail(#expression, __FILE__, __LINE__, __PRETTY_FUNCTION__)); \
39+
} else { ice::detail::_iceshard_constexpr_assert(expression); } } while(false)
2440

2541
#else
2642

27-
#define ICE_ASSERT_CORE(expression) ((expression) \
28-
? __assert_no_op \
29-
: __assert2(__FILE__, __LINE__, __PRETTY_FUNCTION__, #expression))
43+
#define ICE_ASSERT_CORE(expression) do { if (std::is_constant_evaluated() == false) { \
44+
((expression) \
45+
? __assert_no_op \
46+
: __assert2(__FILE__, __LINE__, __PRETTY_FUNCTION__, #expression)); \
47+
} else { ice::detail::_iceshard_constexpr_assert(expression); } } while(false)
3048

3149
#endif

source/code/core/core/public/ice/shard.hxx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,7 @@ namespace ice
238238
ice::Shard result{ };
239239
ice::ShardID const id = ice::shardid(definition);
240240

241-
if (std::is_constant_evaluated() == false)
242-
{
243-
ICE_ASSERT_CORE(id.payload == ice::Constant_ShardPayloadID<T> || id.payload == ice::ShardPayloadID_NotSet);
244-
}
245-
241+
ICE_ASSERT_CORE(id.payload == ice::Constant_ShardPayloadID<T> || id.payload == ice::ShardPayloadID_NotSet);
246242
if (id.payload == ice::Constant_ShardPayloadID<T> || id.payload == ice::ShardPayloadID_NotSet)
247243
{
248244
result.id = id;
@@ -257,11 +253,7 @@ namespace ice
257253
{
258254
ice::Shard result{ };
259255

260-
if (std::is_constant_evaluated() == false)
261-
{
262-
ICE_ASSERT_CORE(id.payload == ice::Constant_ShardPayloadID<T> || id.payload == ice::ShardPayloadID_NotSet);
263-
}
264-
256+
ICE_ASSERT_CORE(id.payload == ice::Constant_ShardPayloadID<T> || id.payload == ice::ShardPayloadID_NotSet);
265257
if (id.payload == ice::Constant_ShardPayloadID<T> || id.payload == ice::ShardPayloadID_NotSet)
266258
{
267259
result.id = id;

source/code/core/memsys/private/mem.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace ice
4646
.size = size,
4747
.alignment = alignment,
4848
};
49-
#elif ISP_LINUX || ISP_WEBAPP || (ISP_ANDROID && ISP_ANDROID <= 29)
49+
#elif ISP_LINUX || ISP_WEBAPP || (ISP_ANDROID && ISP_ANDROID <= 35)
5050
void* memory_location;
5151

5252
[[maybe_unused]]

source/code/core/tasks/private/task_thread_utils.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// Copyright 2025 - 2025, Dandielo <dandielo@iceshard.net>
2+
/// SPDX-License-Identifier: MIT
3+
14
#include <ice/task_thread_utils.hxx>
25
#include <ice/os/windows.hxx>
36
#include <ice/os/unix.hxx>

source/code/core/tasks/public/ice/task_thread_utils.hxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// Copyright 2025 - 2025, Dandielo <dandielo@iceshard.net>
2+
/// SPDX-License-Identifier: MIT
3+
14
#pragma once
25
#include <ice/base.hxx>
36
#include <ice/clock_types.hxx>

source/code/core/utils/private/config/config_builder_types.hxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "config_internal.hxx"
66
#include <ice/config/config_builder.hxx>
77
#include <ice/string/heap_var_string.hxx>
8+
#include <ice/string/heap_string.hxx>
89
#include <ice/container/array.hxx>
910

1011
namespace ice::config::detail

source/code/example/android/simple/build.gradle.template.kts

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ plugins {
66
android {
77
// Here we use TargetSDK to have possible access to newer APIs
88
compileSdk = $(TargetSDK)
9-
// buildToolsVersion = "$ (AndroidBuildToolsVersion)"
109

1110
namespace = "$(Namespace)"
1211

12+
// Defines the NDK version to be used for this project
13+
ndkVersion = "$(NDKVersion)"
14+
1315
defaultConfig {
1416

1517
// Uniquely identifies the package for publishing.
@@ -27,6 +29,16 @@ android {
2729

2830
// Defines a user-friendly version name for your app.
2931
versionName = "$(VersionName)"
32+
33+
// By default keep debug symbols, just remove it in release afterwards
34+
packaging.jniLibs.keepDebugSymbols += "**/*.so"
35+
36+
$(IBTBuildSystemIntegration)
37+
}
38+
39+
compileOptions {
40+
targetCompatibility = JavaVersion.VERSION_11
41+
sourceCompatibility = JavaVersion.VERSION_11
3042
}
3143

3244
buildTypes {
@@ -51,39 +63,13 @@ android {
5163

5264
$(ProjectJNISources)
5365
}
54-
}
55-
56-
afterEvaluate {
57-
/**
58-
* IBT Integration for FastBuild build system.
59-
* To properly handle our build system, we create a new additional tasks that mimic the behavior of built-in CMakeBuild / NdkBuild steps.
60-
* Because gradle requires the outputs to be stored in a sub-folder with a specific ABI name, IBT is handling this by default.
61-
*
62-
* NOTE: Currently only ARM64 is supported as a value ABI target using the default IBT Pipeline.
63-
* You can add additional ABI support by calling the proper pipeline for the given ABI.
64-
*/
65-
android.buildTypes.configureEach {
66-
val buildConfig = this.name.replaceFirstChar { it.titlecase() }
67-
val buildPipeline = "Android$(CompileSDK)"
68-
val abiList = listOf("ARMv8", "x64")
69-
70-
var abiTargets = emptyArray<String>()
71-
for (abi in abiList)
72-
{
73-
abiTargets += "-t"
74-
abiTargets += "all-${buildPipeline}-${abi}-${buildConfig}"
75-
}
7666

77-
val fbuildTask = tasks.register<Exec>("compile${buildConfig}UsingFastbuild") {
78-
workingDir("$(WorkspaceDir)")
79-
executable("$(WorkspaceDir)/$(ScriptFile)")
80-
commandLine(listOf("$(WorkspaceDir)/$(ScriptFile)", "build") + abiTargets)
81-
}
82-
tasks["merge${buildConfig}NativeLibs"].dependsOn(fbuildTask)
67+
lint {
68+
baseline = file("lint-baseline.xml")
8369
}
8470
}
8571

8672
dependencies {
87-
implementation("androidx.appcompat:appcompat:1.6.1")
73+
implementation("androidx.appcompat:appcompat:1.7.1")
8874
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
8975
}

source/code/example/android/simple/private/example_android.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct TestTrait : public ice::Trait
4747

4848
TestTrait(ice::TraitContext& context) noexcept
4949
: ice::Trait{ context }
50+
, timer{ }
5051
{
5152
_context.bind<&TestTrait::logic>();
5253
_context.bind<&TestTrait::gfx>(ice::gfx::ShardID_GfxFrameUpdate);

source/code/example/android/simple/simple.bff

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
.Namespace = 'net.example.simple'
2020
.ApplicationID = 'net.example.myapp'
2121

22-
.TargetSDK = '34'
22+
.TargetSDK = '36'
2323
// .MinSDK = '28' This comes from the Pipeline AndroidAPILevel value
2424

2525
.VersionCode = 142
2626
.VersionName = '1.4.2'
2727

2828
.GradlePlugins = {
29-
'id("com.android.application") version "8.2.0"'
29+
'id("com.android.application") version "8.10.1"'
3030
'id("org.jetbrains.kotlin.android") version "1.8.20"'
3131
}
3232
]
@@ -43,6 +43,7 @@
4343
'vulkan_renderer'
4444
'iceshard_pipelines'
4545
'imgui_module'
46+
'shader_tools'
4647
}
4748
]
4849

0 commit comments

Comments
 (0)