diff --git a/build-artifacts/project-template-gradle/build-tools/android-static-binding-generator/staticbindinggenerator.jar b/build-artifacts/project-template-gradle/build-tools/android-static-binding-generator/staticbindinggenerator.jar index 04d661f3a..2de8d4053 100644 Binary files a/build-artifacts/project-template-gradle/build-tools/android-static-binding-generator/staticbindinggenerator.jar and b/build-artifacts/project-template-gradle/build-tools/android-static-binding-generator/staticbindinggenerator.jar differ diff --git a/build-artifacts/project-template-gradle/src/main/java/com/tns/NativeScriptApplication.java b/build-artifacts/project-template-gradle/src/main/java/com/tns/NativeScriptApplication.java index 36f86afa6..b9e2a72cc 100644 --- a/build-artifacts/project-template-gradle/src/main/java/com/tns/NativeScriptApplication.java +++ b/build-artifacts/project-template-gradle/src/main/java/com/tns/NativeScriptApplication.java @@ -12,7 +12,10 @@ public NativeScriptApplication() { public void onCreate() { super.onCreate(); - new RuntimeHelper(this).initRuntime(); + com.tns.Runtime runtime = RuntimeHelper.initRuntime(this); + if (runtime !=null) { + runtime.run(); + } } public static Application getInstance() { diff --git a/build-artifacts/project-template-gradle/src/main/java/com/tns/RuntimeHelper.java b/build-artifacts/project-template-gradle/src/main/java/com/tns/RuntimeHelper.java index 0180679fd..209e367d4 100644 --- a/build-artifacts/project-template-gradle/src/main/java/com/tns/RuntimeHelper.java +++ b/build-artifacts/project-template-gradle/src/main/java/com/tns/RuntimeHelper.java @@ -10,16 +10,12 @@ import android.util.Log; import java.io.IOException; -public class RuntimeHelper { - private final Application app; - - public RuntimeHelper(Application app) { - this.app = app; - } +public final class RuntimeHelper { + private RuntimeHelper() {} // hasErrorIntent tells you if there was an event (with an uncaught // exception) raised from ErrorReport - public boolean hasErrorIntent() { + public static boolean hasErrorIntent(Application app) { boolean hasErrorIntent = false; try { @@ -38,18 +34,19 @@ public boolean hasErrorIntent() { return hasErrorIntent; } - public void initRuntime() + public static Runtime initRuntime(Application app) { if (Runtime.isInitialized()) { - return; + return Runtime.getCurrentRuntime(); } System.loadLibrary("NativeScript"); + Runtime runtime = null; Logger logger = new LogcatLogger(app); - Debugger debugger = AndroidJsDebugger.isDebuggableApp(this.app) ? new AndroidJsDebugger(app, logger) : null; + Debugger debugger = AndroidJsDebugger.isDebuggableApp(app) ? new AndroidJsDebugger(app, logger) : null; - boolean showErrorIntent = hasErrorIntent(); + boolean showErrorIntent = hasErrorIntent(app); if (!showErrorIntent) { NativeScriptUncaughtExceptionHandler exHandler = new NativeScriptUncaughtExceptionHandler(logger, app); @@ -110,12 +107,12 @@ public void initRuntime() ThreadScheduler workThreadScheduler = new WorkThreadScheduler(new Handler(Looper.getMainLooper())); Configuration config = new Configuration(workThreadScheduler, logger, debugger, appName, null, rootDir, appDir, classLoader, dexDir, dexThumb, v8Config); - Runtime runtime = new Runtime(config); + runtime = new Runtime(config); exHandler.setRuntime(runtime); - if (NativeScriptSyncService.isSyncEnabled(this.app)) { - NativeScriptSyncService syncService = new NativeScriptSyncService(runtime, logger, this.app); + if (NativeScriptSyncService.isSyncEnabled(app)) { + NativeScriptSyncService syncService = new NativeScriptSyncService(runtime, logger, app); syncService.sync(); syncService.startServer(); @@ -141,14 +138,14 @@ public void initRuntime() try { // put this call in a try/catch block because with the latest changes in the modules it is not granted that NativeScriptApplication is extended through JavaScript. - Runtime.initInstance(this.app); + Runtime.initInstance(app); } catch (Exception e) { } - runtime.run(); } + return runtime; } - private final String logTag = "MyApp"; + private static final String logTag = "MyApp"; } diff --git a/runtime/src/main/java/com/tns/Runtime.java b/runtime/src/main/java/com/tns/Runtime.java index abcbbf658..c1a0e679a 100644 --- a/runtime/src/main/java/com/tns/Runtime.java +++ b/runtime/src/main/java/com/tns/Runtime.java @@ -122,7 +122,7 @@ public int getRuntimeId() return this.runtimeId; } - private static Runtime getCurrentRuntime() + public static Runtime getCurrentRuntime() { Runtime runtime = currentRuntime.get(); diff --git a/test-app/app/src/main/java/com/tns/NativeScriptApplication.java b/test-app/app/src/main/java/com/tns/NativeScriptApplication.java index 36f86afa6..b9e2a72cc 100644 --- a/test-app/app/src/main/java/com/tns/NativeScriptApplication.java +++ b/test-app/app/src/main/java/com/tns/NativeScriptApplication.java @@ -12,7 +12,10 @@ public NativeScriptApplication() { public void onCreate() { super.onCreate(); - new RuntimeHelper(this).initRuntime(); + com.tns.Runtime runtime = RuntimeHelper.initRuntime(this); + if (runtime !=null) { + runtime.run(); + } } public static Application getInstance() { diff --git a/test-app/app/src/main/java/com/tns/RuntimeHelper.java b/test-app/app/src/main/java/com/tns/RuntimeHelper.java index 0180679fd..975e39d83 100644 --- a/test-app/app/src/main/java/com/tns/RuntimeHelper.java +++ b/test-app/app/src/main/java/com/tns/RuntimeHelper.java @@ -10,16 +10,13 @@ import android.util.Log; import java.io.IOException; -public class RuntimeHelper { - private final Application app; - - public RuntimeHelper(Application app) { - this.app = app; +public final class RuntimeHelper { + private RuntimeHelper() { } // hasErrorIntent tells you if there was an event (with an uncaught // exception) raised from ErrorReport - public boolean hasErrorIntent() { + private static boolean hasErrorIntent(Application app) { boolean hasErrorIntent = false; try { @@ -38,18 +35,19 @@ public boolean hasErrorIntent() { return hasErrorIntent; } - public void initRuntime() + public static Runtime initRuntime(Application app) { if (Runtime.isInitialized()) { - return; + return Runtime.getCurrentRuntime(); } System.loadLibrary("NativeScript"); Logger logger = new LogcatLogger(app); - Debugger debugger = AndroidJsDebugger.isDebuggableApp(this.app) ? new AndroidJsDebugger(app, logger) : null; + Debugger debugger = AndroidJsDebugger.isDebuggableApp(app) ? new AndroidJsDebugger(app, logger) : null; - boolean showErrorIntent = hasErrorIntent(); + Runtime runtime = null; + boolean showErrorIntent = hasErrorIntent(app); if (!showErrorIntent) { NativeScriptUncaughtExceptionHandler exHandler = new NativeScriptUncaughtExceptionHandler(logger, app); @@ -110,12 +108,12 @@ public void initRuntime() ThreadScheduler workThreadScheduler = new WorkThreadScheduler(new Handler(Looper.getMainLooper())); Configuration config = new Configuration(workThreadScheduler, logger, debugger, appName, null, rootDir, appDir, classLoader, dexDir, dexThumb, v8Config); - Runtime runtime = new Runtime(config); + runtime = new Runtime(config); exHandler.setRuntime(runtime); - if (NativeScriptSyncService.isSyncEnabled(this.app)) { - NativeScriptSyncService syncService = new NativeScriptSyncService(runtime, logger, this.app); + if (NativeScriptSyncService.isSyncEnabled(app)) { + NativeScriptSyncService syncService = new NativeScriptSyncService(runtime, logger, app); syncService.sync(); syncService.startServer(); @@ -141,14 +139,14 @@ public void initRuntime() try { // put this call in a try/catch block because with the latest changes in the modules it is not granted that NativeScriptApplication is extended through JavaScript. - Runtime.initInstance(this.app); + Runtime.initInstance(app); } catch (Exception e) { } - runtime.run(); } + return runtime; } - private final String logTag = "MyApp"; + private static final String logTag = "MyApp"; }