In certain scenarios where runtime errors occur, the debug info provided by the NativeScript CLI is not sufficient. This article will guide you through the steps needed to debug the Android Runtime library module as a part of your NativeScript application. It implies you have already cloned and set up the android-runtime repository. For more info on how to setup the android-runtime project on your workstation refer to its README.
- Android Studio >= 2.3.x
- All the tools needed to build the Android Runtime. Read more info here.
- (Debug C++) Once Android Studio Is installed, you need to install the
LLDBtool used for debugging native code. You can do that by: navigating to
Tools -> Android -> SDK Managerthen go to
SDK Toolstab and install
1. Create a new NativeScript application using one of the following commands depending on your language/technology preference:
NativeScript with Angular:
tns create debug-android-runtime --ng
NativeScript with TypeScript:
tns create debug-android-runtime --tsc
tns create debug-android-runtime
tns prepare android
After you have prepared the project, make sure the
tns-androidversion is at least 3.4.0, because that's the version the Android Studio support is introduced. You can check the version by running
tns infoinside the project folder.
- Open Android Studio
File -> Openor
Open an existing Android Studio project
Set path to the project: e.g.
- Open the project
Note: Tested with Android Studio 2.3.3, 3.0.0, 3.0.1 If you don't need to debug the Android runtime, at this point you can already build your app using Android Studio by running the
:appproject play button.
1. Make sure you have NDK and SDK directories set, because it's needed to build the Android runtime.
File -> Project Structure
- Navigate to
- Check if
Android NDK Locationand
Android SDK Locationare set
Following the set up the
Project Structure dialog look like this:
WARNING: Make sure your environment fulfills all the requirements mentioned in android-runtime's README.
settings.gradlefile in the already opened Android Studio project, which should look like this:
- Uncomment the included projects:
- Uncomment and set the
:runtime-binding-generatorproject dirs. These project dirs, can be found in the already cloned android-runtime repository.
After the changes, Android Studio will ask you to sync files and
settings.gradle file should look like:
After the sync has completed, the
:runtime-binding-generator modules should appear in the Project view in Android Studio:
If you only want to debug the Java part of the runtime, you're already all set up. All you need to do is set a break point and run in debug.
Runtime.javaand set a breakpoint at:
private void init ...method.
- Run Debug
When you run the project in debug, you should see the Android Runtime build log in the Gradle Console(bottom right).
- Open the
:appproject debug configurations:
- Add the runtime symbols in the debugger tab.
The symbols can be found in the cloned android runtime repo in:
<android-runtime-repo>/test-app/runtime/build/intermediates/cmake/release/obj. In order for this folder to exist, you must run the android runtime build at least once.
com_tns_Runtime.cppand set a breakpoint at:
extern "C" JNIEXPORT void Java_com_tns_Runtime_initNativeScript ...method.
- Run Debug
If you have NativeScript plugins, containing Java Libraries in your application, you will still be able to build it with Android Studio, but you won't be able to debug it with the Android runtime. We will fix that issue in the upcoming releases.
If you encounter this error:
Error while starting native debug session: com.intellij.execution.ExecutionException: LLDB package hasn’t been found, you're probably trying to debug C++ code and you need to install the
LLDBdebugger. Look at the Requirements for instructions on how to do it.
If you encounter this error:
Error:Unable to find module with Gradle path ':runtime' (needed by module 'app'.)
File -> Invalidate Caches/Restart -> Invalidate and Restart