Skip to content

Commit c16a1d6

Browse files
committed
fix build
1 parent 844d68c commit c16a1d6

2 files changed

Lines changed: 49 additions & 50 deletions

File tree

runtime/src/main/java/com/tns/Runtime.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public void init()
498498
init(config.logger, config.debugger, config.appName, config.nativeLibDir, config.rootDir, config.appDir, config.classLoader, config.dexDir, config.dexThumb, config.appConfig, dynamicConfig.callingJsDir);
499499
}
500500

501-
private void init(Logger logger, Debugger debugger, String appName, String nativeLibDir, File rootDir, File appDir, ClassLoader classLoader, File dexDir, String dexThumb, AppConfig appConfig, String callingJsDir) throws RuntimeException {
501+
private void init(Logger logger, Debugger debugger, String appName, String nativeLibDir, File rootDir, File appDir, ClassLoader classLoader, File dexDir, String dexThumb, AppConfig appConfig, String callingJsDir) throws RuntimeException
502502
{
503503
if (initialized)
504504
{
@@ -554,12 +554,13 @@ private void init(Logger logger, Debugger debugger, String appName, String nativ
554554
}
555555

556556
@RuntimeCallable
557-
public void enableVerboseLogging()
558-
{
557+
public void enableVerboseLogging() {
558+
559559
logger.setEnabled(true);
560560
ProxyGenerator.IsLogEnabled = true;
561561
}
562562

563+
563564
@RuntimeCallable
564565
public void disableVerboseLogging()
565566
{
@@ -651,7 +652,7 @@ private Class<?> resolveClass(String fullClassName, String[] methodOverrides, St
651652
}
652653

653654
@RuntimeCallable
654-
private long getUsedMemory() {
655+
private long getUsedMemory()
655656
{
656657
long usedMemory = dalvikRuntime.totalMemory() - dalvikRuntime.freeMemory();
657658
return usedMemory;
@@ -1459,7 +1460,7 @@ public static void workerScopeClose()
14591460
}
14601461

14611462
@RuntimeCallable
1462-
public static void passUncaughtExceptionFromWorkerToMain(String message, String filename, String stackTrace, int lineno) {
1463+
public static void passUncaughtExceptionFromWorkerToMain(String message, String filename, String stackTrace, int lineno)
14631464
{
14641465
// Thread should always be a worker
14651466
Runtime currentRuntime = Runtime.getCurrentRuntime();

runtime/src/main/jni/Runtime.cpp

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -426,39 +426,34 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring nativeLibDir
426426
Isolate::CreateParams create_params;
427427
bool didInitializeV8 = false;
428428

429-
auto pckName = ArgConverter::jstringToString(packageName);
430-
__android_log_print(ANDROID_LOG_INFO, pckName.c_str(), "NativeScript Runtime Version %s, commit %s", NATIVE_SCRIPT_RUNTIME_VERSION, NATIVE_SCRIPT_RUNTIME_COMMIT_SHA);
431-
__android_log_print(ANDROID_LOG_DEBUG, pckName.c_str(), "V8 version %s", V8::GetVersion());
432-
433-
434429
create_params.array_buffer_allocator = &g_allocator;
435430

436431
m_startupData = new StartupData();
437432

438-
// Retrieve the device android Sdk version
439-
char sdkVersion[PROP_VALUE_MAX];
440-
__system_property_get("ro.build.version.sdk", sdkVersion);
433+
// Retrieve the device android Sdk version
434+
char sdkVersion[PROP_VALUE_MAX];
435+
__system_property_get("ro.build.version.sdk", sdkVersion);
441436

442-
auto pckName = ArgConverter::jstringToString(packageName);
443-
444-
void* snapshotPtr;
437+
auto pckName = ArgConverter::jstringToString(packageName);
445438

446-
// If device isn't running on Sdk 17
447-
if (strcmp(sdkVersion, string("17").c_str()) != 0) {
448-
snapshotPtr = dlopen("libsnapshot.so", RTLD_LAZY | RTLD_LOCAL);
449-
} else {
450-
// If device is running on android Sdk 17
451-
// dlopen reads relative path to dynamic libraries or reads from folder different than the nativeLibsDirs on the android device
452-
string libDir = ArgConverter::jstringToString(nativeLibDir);
453-
string snapshotPath = libDir + "/libsnapshot.so";
454-
snapshotPtr = dlopen(snapshotPath.c_str(), RTLD_LAZY | RTLD_LOCAL);
455-
}
439+
void* snapshotPtr;
440+
441+
// If device isn't running on Sdk 17
442+
if (strcmp(sdkVersion, string("17").c_str()) != 0) {
443+
snapshotPtr = dlopen("libsnapshot.so", RTLD_LAZY | RTLD_LOCAL);
444+
} else {
445+
// If device is running on android Sdk 17
446+
// dlopen reads relative path to dynamic libraries or reads from folder different than the nativeLibsDirs on the android device
447+
string libDir = ArgConverter::jstringToString(nativeLibDir);
448+
string snapshotPath = libDir + "/libsnapshot.so";
449+
snapshotPtr = dlopen(snapshotPath.c_str(), RTLD_LAZY | RTLD_LOCAL);
450+
}
456451

457-
if(snapshotPtr == nullptr) {
458-
DEBUG_WRITE_FORCE("Failed to load snapshot: %s", dlerror());
459-
}
452+
if(snapshotPtr == nullptr) {
453+
DEBUG_WRITE_FORCE("Failed to load snapshot: %s", dlerror());
454+
}
460455

461-
if (snapshotPtr)
456+
if (snapshotPtr)
462457
{
463458
m_startupData->data = static_cast<const char *>(dlsym(snapshotPtr, "TNSSnapshot_blob"));
464459
m_startupData->raw_size = *static_cast<const unsigned int *>(dlsym(snapshotPtr, "TNSSnapshot_blob_len"));
@@ -487,11 +482,11 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring nativeLibDir
487482
m_startupData->data = static_cast<const char*>(m_heapSnapshotBlob->memory);
488483
m_startupData->raw_size = m_heapSnapshotBlob->size;
489484

490-
DEBUG_WRITE("Snapshot read %s (%dB).", snapshotPath.c_str(), m_heapSnapshotBlob->size);
485+
DEBUG_WRITE_FORCE("Snapshot read %s (%dB).", snapshotPath.c_str(), m_heapSnapshotBlob->size);
491486
}
492487
else if (!saveSnapshot)
493488
{
494-
DEBUG_WRITE("No snapshot file found at %s", snapshotPath.c_str());
489+
DEBUG_WRITE_FORCE("No snapshot file found at %s", snapshotPath.c_str());
495490

496491
}
497492
else
@@ -509,26 +504,26 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring nativeLibDir
509504
customScript = File::ReadText(Constants::V8_HEAP_SNAPSHOT_SCRIPT);
510505
}
511506

512-
DEBUG_WRITE("Creating heap snapshot");
507+
DEBUG_WRITE_FORCE("Creating heap snapshot");
513508
*m_startupData = V8::CreateSnapshotDataBlob(customScript.c_str());
514509

515510
if (m_startupData->raw_size == 0)
516511
{
517-
DEBUG_WRITE("Failed to create heap snapshot.");
512+
DEBUG_WRITE_FORCE("Failed to create heap snapshot.");
518513
}
519514
else
520515
{
521516
bool writeSuccess = File::WriteBinary(snapshotPath, m_startupData->data, m_startupData->raw_size);
522517

523518
if (!writeSuccess)
524519
{
525-
__android_log_print(ANDROID_LOG_ERROR, pckName.c_str(), "Failed to save created snapshot.");
520+
DEBUG_WRITE_FORCE("Failed to save created snapshot.");
526521
}
527522
else
528523
{
529-
DEBUG_WRITE("Saved snapshot of %s (%dB) in %s (%dB)",
530-
Constants::V8_HEAP_SNAPSHOT_SCRIPT.c_str(), customScript.size(),
531-
snapshotPath.c_str(), m_startupData->raw_size);
524+
DEBUG_WRITE_FORCE("Saved snapshot of %s (%dB) in %s (%dB)",
525+
Constants::V8_HEAP_SNAPSHOT_SCRIPT.c_str(), customScript.size(),
526+
snapshotPath.c_str(), m_startupData->raw_size);
532527
}
533528
}
534529
}
@@ -559,6 +554,8 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring nativeLibDir
559554

560555
isolate->AddMessageListener(NativeScriptException::OnUncaughtError);
561556

557+
__android_log_print(ANDROID_LOG_DEBUG, "TNS.Native", "V8 version %s", V8::GetVersion());
558+
562559
auto globalTemplate = ObjectTemplate::New();
563560

564561
const auto readOnlyFlags = static_cast<PropertyAttribute>(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
@@ -591,10 +588,10 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring nativeLibDir
591588

592589
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "Worker"), workerFuncTemplate);
593590
}
594-
/*
595-
* Emulate a `WorkerGlobalScope`
596-
* Attach postMessage, close to the global object
597-
*/
591+
/*
592+
* Emulate a `WorkerGlobalScope`
593+
* Attach postMessage, close to the global object
594+
*/
598595
else {
599596
auto postMessageFuncTemplate = FunctionTemplate::New(isolate, CallbackHandlers::WorkerGlobalPostMessageCallback);
600597
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "postMessage"), postMessageFuncTemplate);
@@ -661,17 +658,18 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring nativeLibDir
661658

662659
jobject Runtime::ConvertJsValueToJavaObject(JEnv& env, const Local<Value>& value, int classReturnType)
663660
{
664-
JsArgToArrayConverter argConverter(m_isolate, value, false/*is implementation object*/, classReturnType);
665-
jobject jr = argConverter.GetConvertedArg();
666-
jobject javaResult = nullptr;
667-
if (jr != nullptr)
668-
{
669-
javaResult = env.NewLocalRef(jr);
670-
}
661+
JsArgToArrayConverter argConverter(m_isolate, value, false/*is implementation object*/, classReturnType);
662+
jobject jr = argConverter.GetConvertedArg();
663+
jobject javaResult = nullptr;
664+
if (jr != nullptr)
665+
{
666+
javaResult = env.NewLocalRef(jr);
667+
}
671668

672-
return javaResult;
669+
return javaResult;
673670
}
674671

672+
675673
void Runtime::DestroyRuntime() {
676674
s_id2RuntimeCache.erase(m_id);
677675
s_isolate2RuntimesCache.erase(m_isolate);

0 commit comments

Comments
 (0)