23
23
#include " include/zipconf.h"
24
24
#include < sstream>
25
25
#include < dlfcn.h>
26
+ #include " sys/system_properties.h"
26
27
27
28
using namespace v8 ;
28
29
using namespace std ;
@@ -130,18 +131,18 @@ ObjectManager* Runtime::GetObjectManager() const
130
131
return m_objectManager;
131
132
}
132
133
133
- void Runtime::Init (JNIEnv *_env, jobject obj, int runtimeId, jstring filesPath, jboolean verboseLoggingEnabled, jstring packageName, jobjectArray args, jstring callingDir, jobject jsDebugger)
134
+ void Runtime::Init (JNIEnv *_env, jobject obj, int runtimeId, jstring filesPath, jstring nativeLibDir, jboolean verboseLoggingEnabled, jstring packageName, jobjectArray args, jstring callingDir, jobject jsDebugger)
134
135
{
135
136
JEnv env (_env);
136
137
137
138
auto runtime = new Runtime (env, obj, runtimeId);
138
139
139
140
auto enableLog = verboseLoggingEnabled == JNI_TRUE;
140
141
141
- runtime->Init (filesPath, enableLog, packageName, args, callingDir, jsDebugger);
142
+ runtime->Init (filesPath, nativeLibDir, enableLog, packageName, args, callingDir, jsDebugger);
142
143
}
143
144
144
- void Runtime::Init (jstring filesPath, bool verboseLoggingEnabled, jstring packageName, jobjectArray args, jstring callingDir, jobject jsDebugger)
145
+ void Runtime::Init (jstring filesPath, jstring nativeLibDir, bool verboseLoggingEnabled, jstring packageName, jobjectArray args, jstring callingDir, jobject jsDebugger)
145
146
{
146
147
LogEnabled = verboseLoggingEnabled;
147
148
@@ -161,7 +162,7 @@ void Runtime::Init(jstring filesPath, bool verboseLoggingEnabled, jstring packag
161
162
DEBUG_WRITE (" Initializing Telerik NativeScript" );
162
163
163
164
NativeScriptException::Init (m_objectManager);
164
- m_isolate = PrepareV8Runtime (filesRoot, packageName, callingDir, jsDebugger, profilerOutputDir);
165
+ m_isolate = PrepareV8Runtime (filesRoot, nativeLibDir, packageName, callingDir, jsDebugger, profilerOutputDir);
165
166
166
167
s_isolate2RuntimesCache.insert (make_pair (m_isolate, this ));
167
168
}
@@ -420,7 +421,7 @@ static void InitializeV8() {
420
421
421
422
bool x = false ;
422
423
423
- Isolate* Runtime::PrepareV8Runtime (const string& filesPath, jstring packageName, jstring callingDir, jobject jsDebugger, jstring profilerOutputDir)
424
+ Isolate* Runtime::PrepareV8Runtime (const string& filesPath, jstring nativeLibDir, jstring packageName, jstring callingDir, jobject jsDebugger, jstring profilerOutputDir)
424
425
{
425
426
Isolate::CreateParams create_params;
426
427
bool didInitializeV8 = false ;
@@ -429,8 +430,30 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName,
429
430
430
431
m_startupData = new StartupData ();
431
432
432
- void * snapshotPtr = dlopen (" libsnapshot.so" , RTLD_LAZY | RTLD_LOCAL);
433
- if (snapshotPtr)
433
+ // Retrieve the device android Sdk version
434
+ char sdkVersion[PROP_VALUE_MAX];
435
+ __system_property_get (" ro.build.version.sdk" , sdkVersion);
436
+
437
+ auto pckName = ArgConverter::jstringToString (packageName);
438
+
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
+ }
451
+
452
+ if (snapshotPtr == nullptr ) {
453
+ DEBUG_WRITE_FORCE (" Failed to load snapshot: %s" , dlerror ());
454
+ }
455
+
456
+ if (snapshotPtr)
434
457
{
435
458
m_startupData->data = static_cast <const char *>(dlsym (snapshotPtr, " TNSSnapshot_blob" ));
436
459
m_startupData->raw_size = *static_cast <const unsigned int *>(dlsym (snapshotPtr, " TNSSnapshot_blob_len" ));
@@ -530,7 +553,7 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName,
530
553
V8::SetCaptureStackTraceForUncaughtExceptions (true , 100 , StackTrace::kOverview );
531
554
532
555
isolate->AddMessageListener (NativeScriptException::OnUncaughtError);
533
-
556
+
534
557
__android_log_print (ANDROID_LOG_DEBUG, " TNS.Native" , " V8 version %s" , V8::GetVersion ());
535
558
536
559
auto globalTemplate = ObjectTemplate::New ();
@@ -610,7 +633,6 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName,
610
633
611
634
CallbackHandlers::Init (isolate);
612
635
613
- auto pckName = ArgConverter::jstringToString (packageName);
614
636
auto outputDir = ArgConverter::jstringToString (profilerOutputDir);
615
637
m_profiler.Init (isolate, global, pckName, outputDir);
616
638
JsDebugger::Init (isolate, pckName, jsDebugger);
0 commit comments