Skip to content
This repository was archived by the owner on Nov 9, 2026. It is now read-only.

Commit 91cf1ad

Browse files
committed
Port remaining Android XR compatibility fixes
1 parent a128e68 commit 91cf1ad

7 files changed

Lines changed: 61 additions & 28 deletions

File tree

‎.github/workflows/build-android.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Run Connected Android Test
3939
uses: reactivecircus/android-emulator-runner@v2
4040
with:
41-
api-level: 33
41+
api-level: 35
4242
target: google_apis
4343
arch: x86_64
4444
emulator-options: -no-snapshot -no-window -no-boot-anim -no-audio

‎Core/AppRuntime/V8Inspector/Source/V8InspectorAgent.cpp‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
#include <v8-inspector.h>
99
#include <v8-platform.h>
10+
#if __has_include(<v8-version.h>)
11+
#include <v8-version.h>
12+
#endif
1013

1114
#include <string.h>
1215
#include <chrono>
@@ -194,7 +197,14 @@ namespace Babylon
194197

195198
void ConnectFrontend()
196199
{
197-
session_ = inspector_->connect(1, new ChannelImpl(agent_), v8_inspector::StringView(), v8_inspector::V8Inspector::kFullyTrusted);
200+
#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION >= 11)
201+
session_ = inspector_->connect(
202+
1, new ChannelImpl(agent_), v8_inspector::StringView(),
203+
v8_inspector::V8Inspector::kFullyTrusted);
204+
#else
205+
session_ = inspector_->connect(
206+
1, new ChannelImpl(agent_), v8_inspector::StringView());
207+
#endif
198208
}
199209

200210
void DisconnectFrontend()
@@ -419,9 +429,9 @@ namespace Babylon
419429
}
420430
v8::Local<v8::String> string_value = v8::Local<v8::String>::Cast(value);
421431
int len = string_value->Length();
422-
std::basic_string<char16_t> buffer(len, '\0');
423-
string_value->Write(v8::Isolate::GetCurrent(), reinterpret_cast<uint16_t*>(&buffer[0]), 0, len); // Write expects uint16_t* but the template parameter is char16_t
424-
return v8_inspector::StringBuffer::create(v8_inspector::StringView(reinterpret_cast<uint16_t*>(buffer.data()), len));
432+
std::vector<uint16_t> buffer(len);
433+
string_value->Write(v8::Isolate::GetCurrent(), buffer.data(), 0, len);
434+
return v8_inspector::StringBuffer::create(v8_inspector::StringView(buffer.data(), len));
425435
}
426436

427437
bool AgentImpl::AppendMessage(
@@ -661,4 +671,4 @@ namespace Babylon
661671
return "file://" + script_path_;
662672
}
663673

664-
} // namespace inspector
674+
} // namespace inspector

‎Core/Node-API/Include/Shared/napi/napi-inl.h‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
#include <type_traits>
2020
#include <utility>
2121

22+
#if defined(__clang__) || defined(__GNUC__)
23+
#define NAPI_NO_SANITIZE_VPTR __attribute__((no_sanitize("vptr")))
24+
#else
25+
#define NAPI_NO_SANITIZE_VPTR
26+
#endif
27+
2228
namespace Napi {
2329

2430
#ifdef NAPI_CPP_CUSTOM_NAMESPACE
@@ -4495,11 +4501,7 @@ inline napi_value InstanceWrap<T>::WrappedMethod(
44954501
// ObjectWrap<T> class
44964502
////////////////////////////////////////////////////////////////////////////////
44974503
template <typename T>
4498-
// [BABYLON-NATIVE-ADDITION]
4499-
#ifndef _MSC_VER
4500-
__attribute__((no_sanitize("vptr")))
4501-
#endif
4502-
inline ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) {
4504+
inline NAPI_NO_SANITIZE_VPTR ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) {
45034505
napi_env env = callbackInfo.Env();
45044506
napi_value wrapper = callbackInfo.This();
45054507
napi_status status;
@@ -4513,7 +4515,7 @@ inline ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) {
45134515
}
45144516

45154517
template <typename T>
4516-
inline ObjectWrap<T>::~ObjectWrap() {
4518+
inline NAPI_NO_SANITIZE_VPTR ObjectWrap<T>::~ObjectWrap() {
45174519
// If the JS object still exists at this point, remove the finalizer added
45184520
// through `napi_wrap()`.
45194521
if (!IsEmpty() && !_finalized) {
@@ -4527,7 +4529,7 @@ inline ObjectWrap<T>::~ObjectWrap() {
45274529
}
45284530

45294531
template <typename T>
4530-
inline T* ObjectWrap<T>::Unwrap(Object wrapper) {
4532+
inline NAPI_NO_SANITIZE_VPTR T* ObjectWrap<T>::Unwrap(Object wrapper) {
45314533
void* unwrapped;
45324534
napi_status status = napi_unwrap(wrapper.Env(), wrapper, &unwrapped);
45334535
NAPI_THROW_IF_FAILED(wrapper.Env(), status, nullptr);
@@ -6684,4 +6686,6 @@ bool Env::CleanupHook<Hook, Arg>::IsEmpty() const {
66846686

66856687
} // namespace Napi
66866688

6689+
#undef NAPI_NO_SANITIZE_VPTR
6690+
66876691
#endif // SRC_NAPI_INL_H_

‎Core/Node-API/package-jsc.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"dependencies": {
3-
"jsc-android": "250231.0.0"
3+
"jsc-android": "294992.0.0"
44
}
55
}

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ npm install
3232
_Follow the steps from [All Development Platforms](#all-development-platforms) before proceeding._
3333

3434
**Required Tools:**
35-
[Android Studio](https://developer.android.com/studio), [Node.js](https://nodejs.org/en/download/), [Ninja](https://ninja-build.org/)
35+
[Android Studio](https://developer.android.com/studio) with Android NDK 28.2.13676358 and API level 35 SDK platform installed, [Node.js](https://nodejs.org/en/download/), [Ninja](https://ninja-build.org/)
3636

3737
The minimal requirement target is Android 5.0.
3838

@@ -42,7 +42,7 @@ An `.apk` that can be executed on your device or simulator is the output.
4242

4343
First, download the latest release of Ninja, extract the binary, and add it to your system path.
4444

45-
Once you have Android Studio downloaded, you need to set up an Android emulator if you do not have a physical Android device. You can do this by selecting `Tools` -> `Device Manager` and then selecting a device. (We are using Pixel 2 API 27).
45+
Once you have Android Studio downloaded, you need to set up an Android emulator if you do not have a physical Android device. You can do this by selecting `Tools` -> `Device Manager` and then selecting a device. (We are using Pixel 2 API 35).
4646

4747
Open the project located at
4848
`JsRuntimeHost\Tests\UnitTests\Android` with Android Studio. Note that this can take a while to load. (The bottom right corner of the Android Studio window shows you what is currently being loaded.)
@@ -68,4 +68,4 @@ Security Response Center (MSRC) at [secure@microsoft.com](mailto:secure@microsof
6868
You should receive a response within 24 hours. If for some reason you do not, please
6969
follow up via email to ensure we received your original message. Further information,
7070
including the [MSRC PGP](https://technet.microsoft.com/en-us/security/dn606155) key, can
71-
be found in the [Security TechCenter](https://technet.microsoft.com/en-us/security/default).
71+
be found in the [Security TechCenter](https://technet.microsoft.com/en-us/security/default).

‎Tests/UnitTests/Android/app/build.gradle‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,55 @@ if (project.hasProperty("jsEngine")) {
77
jsEngine = project.property("jsEngine")
88
}
99

10+
def targetApiLevel = 35
11+
def requiredNdkVersion = project.findProperty("ndkVersion") ?: "28.2.13676358"
12+
1013
android {
1114
namespace 'com.jsruntimehost.unittests'
12-
compileSdk 33
13-
ndkVersion = "23.1.7779620"
14-
if (project.hasProperty("ndkVersion")) {
15-
ndkVersion = project.property("ndkVersion")
16-
}
15+
compileSdk targetApiLevel
16+
ndkVersion = requiredNdkVersion
1717

1818
defaultConfig {
1919
applicationId "com.jsruntimehost.unittests"
2020
minSdk 21
21-
targetSdk 33
21+
targetSdk targetApiLevel
2222
versionCode 1
2323
versionName "1.0"
2424

2525
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2626

2727
externalNativeBuild {
2828
cmake {
29-
arguments (
29+
arguments(
3030
"-DANDROID_STL=c++_shared",
3131
"-DNAPI_JAVASCRIPT_ENGINE=${jsEngine}",
3232
"-DJSRUNTIMEHOST_CORE_APPRUNTIME_V8_INSPECTOR=ON"
3333
)
3434
}
3535
}
3636

37-
if (project.hasProperty("abiFilters")) {
38-
ndk {
39-
abiFilters project.getProperty("abiFilters")
37+
ndk {
38+
def abiFiltersProp = project.findProperty("abiFilters")?.toString()
39+
if (abiFiltersProp) {
40+
def propFilters = abiFiltersProp.split(',').collect { it.trim() }.findAll { !it.isEmpty() }
41+
if (!propFilters.isEmpty()) {
42+
abiFilters(*propFilters)
43+
}
44+
} else {
45+
def requestedAbi = project.findProperty("android.injected.build.abi") ?: System.getenv("ANDROID_ABI")
46+
def defaultAbis = []
47+
if (requestedAbi) {
48+
defaultAbis = requestedAbi.split(',').collect { it.trim() }.findAll { !it.isEmpty() }
49+
}
50+
if (defaultAbis.isEmpty()) {
51+
def hostArch = (System.getProperty("os.arch") ?: "").toLowerCase()
52+
if (hostArch.contains("aarch64") || hostArch.contains("arm64")) {
53+
defaultAbis = ['arm64-v8a']
54+
} else {
55+
defaultAbis = ['arm64-v8a', 'x86_64']
56+
}
57+
}
58+
abiFilters(*defaultAbis)
4059
}
4160
}
4261
}

‎Tests/UnitTests/Android/app/src/main/cpp/JNI.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Java_com_jsruntimehost_unittests_Native_javaScriptTests(JNIEnv* env, jclass claz
2222
android::global::Initialize(javaVM, context);
2323

2424
Babylon::DebugTrace::EnableDebugTrace(true);
25-
Babylon::DebugTrace::SetTraceOutput([](const char* trace) { printf("%s\n", trace); fflush(stdout); });
25+
Babylon::DebugTrace::SetTraceOutput([](const char* trace) { __android_log_print(ANDROID_LOG_INFO, "JsRuntimeHost", "%s", trace); });
2626

2727
auto testResult = RunTests();
2828

0 commit comments

Comments
 (0)