Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ The repo is structured in the following projects (ordered by dependencies):
* **build/project-template** - this is an empty placeholder Android Application project, used by the [NativeScript CLI](https://github.com/NativeScript/nativescript-cli) when building an Android project.

# Build Prerequisites
The source in this repo is organized in Android Studio projects.
Following are the minimal prerequisites to build the runtime package.

* Install the latest [Android Studio ](https://developer.android.com/studio/index.html).
* Install Android API Level 22 from Android Studio -> Tools -> Android -> SDK Manager
* Install the Android NDK from Android Studio -> Tools -> Android -> SDK Manager
* Install Android API Level 22, 23, 24, 25 from Android Studio -> Tools -> Android -> SDK Manager
* Android NDK 12b - [NDK Archives](https://developer.android.com/ndk/downloads/older_releases.html)
* Download Android Support Repository through the Android SDK Manager
* Download Build Tools 25.0.2 through the Android SDK Manager.

Expand Down
Binary file added docs/test-cli-app-howto/3rd-party-plugins.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/test-cli-app-howto/add-binaries.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/test-cli-app-howto/align-versions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/test-cli-app-howto/config-debugger-tab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/test-cli-app-howto/edit-configurations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/test-cli-app-howto/final-binaries.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/test-cli-app-howto/open-project.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/test-cli-app-howto/open-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/test-cli-app-howto/select-project.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/test-cli-app-howto/set-compile-sdk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/test-cli-app-howto/set-ndk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions test-cli-app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/src
proguard-rules.pro
/captures
app/build
app/src/*
app/.iml
app/proguard-rules.pro
!app/build.gradle
!app/src/.gitkeep
gradle-app.setting
52 changes: 52 additions & 0 deletions test-cli-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Debugging NativeScript CLI app with the Hybrid (Java and CPP) debugger in Android Studio

## Prerequisites:
- [Android Studio](https://developer.android.com/studio/index.html#downloads)
- Android SDK (Can be managed through the SDK Manager in AS)
- Android Platform 23, 24, 25
- Android Support Repository
- Build Tools *25.0.2*
- Android NDK 12b - [NDK Archives](https://developer.android.com/ndk/downloads/older_releases.html)


## First Launch
- Open Android Studio - Click `Open an existing Android Studio project`
- ![Open existing AS project](../docs/test-cli-app-howto/open-project.png)
- Select the `test-cli-app` Gradle project and click `OK`
- ![Select project](../docs/test-cli-app-howto/select-project.png)
- Next configure the path to the Android NDK. This allows compilation and debugging of the native code (the runtime contains predominantly C++ code). `File -> Project Structure...` (`Ctrl+Alt+Shift+S`)
- ![Open settings](../docs/test-cli-app-howto/open-settings.png)
- Set the Android NDK location to point to your `12b` extracted NDK package on a hard drive. If prompted - **Do not** install latest NDK.
- ![Set NDK](../docs/test-cli-app-howto/set-ndk.png)

## Configuring the project
- Build a NativeScript application using the CLI (`tns build android`)
- Navigate to `my-app/platforms/android/`, copy the `src` directory to `test-cli-app/app/`
- Align the `model.android.compileSdkVersion` to match the one used when building your project (default - highest installed, or one passed with the `--compileSdk` flag)
- ![Set compileSdk](../docs/test-cli-app-howto/set-compile-sdk.png)
- Align the support library versions so that the big version (first number) matches that of the compileSdk
- ![Align versions](../docs/test-cli-app-howto/align-versions.png)
- > **IMPORTANT**: If the project refers to any gradle plugins (additional support library plugins, sidedrawers, design library, google play libraries, 3rd party libraries etc.) either in `my-app/app/app.gradle`, or in any of the nativescript plugins installed in the application, those references will need to be included manually in the `test-cli-app/app/build.gradle` file's `dependencies` scope.

- Illustration of the above: using the `nativescript-drawingpad` in a project, it is required to refer the jcenter `"com.github.gcacace:signature-pad"` package:
- ![3rd Party libs](../docs/test-cli-app-howto/3rd-party-plugins.png)
- Build the entire project to ensure everything is setup properly, and the runtime is ready to be debugged - `Build -> Rebuild Project`


## Configuring debug symbols for debugging C++ code
- **Note:** The following needs to be done only once. The paths to the binary directories are stored locally. Add the necessary symbols that will allow your applications to break in native (C++) code
- Click on the `app` project -> `Edit Configurations`...
- ![Edit configurations](../docs/test-cli-app-howto/edit-configurations.png)
- On the settings window that opens up click on the `Debugger` tab
- ![Debugger tab](../docs/test-cli-app-howto/config-debugger-tab.png)
- Click the `+` (plus) button and proceed by adding the directories with the symbol tables for x86 and armeabi-v7a ABIs. This will ensure that whether the application debugged is an x86 emulator, or an armeabi-v7a device, C++ breakpoints will be hit.
- ![Add Binaries](../docs/test-cli-app-howto/add-binaries.png)
- Ultimately the `Debugger/Symbol Directories` tab should end up looking like this:
- ![Final look binaries](../docs/test-cli-app-howto/final-binaries.png)



## Debugging the project
Click the Play/Debug icon beneath the Android Studio Toolbar to run yourNativeScript app using the locally built runtime. Any changes made to the`runtime` subproject will be reflected immediately on following installations(runs) of the app through the AS UI.

In addition to debugging of the runtime bits, AS provides a clean and usefulUI to monitor the device Logcat. (Alt-6) will open the `Android Monitor` tool.
108 changes: 108 additions & 0 deletions test-cli-app/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')

apply plugin: 'com.android.model.application'

def runOnDevice = project.hasProperty("runOnDevice");
def runOnDeviceOrEmulator = runOnDevice ? "-d" : "-e";

model {
android {
compileSdkVersion = 25
buildToolsVersion = "25.0.2"

defaultConfig.with {
applicationId = "com.tns.debugapp"
minSdkVersion.apiLevel = 17
targetSdkVersion.apiLevel = 25
versionCode = 1
versionName = "1.0"
}

lintOptions.with {
abortOnError = false
}
}

// android.ndk {
// moduleName = "test-app-dummy-native-lib"
// }

android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
}
}

dependencies {
def supportVer = "25.3.1"
compile project(':runtime')
compile fileTree(include: ['*.jar'], dir: 'libs')

compile "com.android.support:support-v4:$supportVer"
compile "com.android.support:appcompat-v7:$supportVer"
compile "com.android.support:design:$supportVer"

testCompile 'junit:junit:4.12'
}

repositories {
jcenter()
flatDir {
dirs 'src/F0', 'src/F1',
'src/F2', 'src/F3',
'src/F4', 'src/F5',
'src/F6', 'src/F7',
'src/F8', 'src/F9',
'src/F10', 'src/F11'
}
}

task addAarDependencies {
FileTree tree = fileTree(dir: "$projectDir/src", include: ["**/*.aar"])
tree.each { File file ->
def length = file.name.length() - 4
def fileName = file.name[0..<length]
println "\t+adding dependency: " + file.getAbsolutePath()
project.dependencies.add("compile", [name: fileName, ext: "aar"])
}
}

/////////////////////////////// installing application ////////////////////////////

task installApk(type: Exec) {
doFirst {
println "Attempting to install buit apk"

if (isWinOs) {
commandLine "cmd", "/c", "node", "$rootDir\\tools\\deploy-apk.js", "$rootDir\\runtimedebug\\build\\outputs\\apk\\app-debug.apk"
} else {
commandLine "node", "$rootDir/tools/deploy-apk.js", "$rootDir/runtimedebug/build/outputs/apk/app-debug.apk"
}
}

doLast {
println "Install result:" + execResult
}
}

task startInstalledApk(type: Exec) {
doFirst {
println "Starting test application"

if (isWinOs) {
commandLine "cmd", "/c", "adb", "shell", "am", "start", "-n", "org.nativescript.runtimedebug/com.tns.NativeScriptActivity", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER"
} else {
commandLine "adb", "shell", "am", "start", "-n", "org.nativescript.runtimedebug/com.tns.NativeScriptActivity", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER"
}
}
}

startInstalledApk.dependsOn(installApk)

task deleteDist (type: Delete) {
doFirst {
delete "$rootDir/dist"
}
}
1 change: 1 addition & 0 deletions test-cli-app/app/src/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
102 changes: 16 additions & 86 deletions test-cli-app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,95 +1,25 @@
apply plugin: 'com.android.model.application'
/*
* Usage:
* gradlew assembleDebug - Builds an Android apk in debug
* gradlew assembleRelease - Builds an Android apk in release
* gradlew runtests - Builds and runs the test applciation and pull an test results xml file in /dist/android_unit_test_results.xml
*/

import groovy.json.JsonSlurper //used to parse package.json

model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.3"

defaultConfig.with {
applicationId = "org.nativescript.runtimedebug"
minSdkVersion.apiLevel = 17
targetSdkVersion.apiLevel = 22
versionCode = 1
versionName = "1.0"
}

lintOptions.with {
abortOnError = false
}
}

android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
}
}

dependencies {
compile project(':runtime')
compile project(':binding-generator')
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile "com.android.support:support-v4:23.3.0"
}

repositories {
jcenter()
flatDir {
dirs 'src/F0', 'src/F1',
'src/F2', 'src/F3',
'src/F4', 'src/F5',
'src/F6', 'src/F7',
'src/F8', 'src/F9',
'src/F10', 'src/F11'
}
}

task addAarDependencies {
FileTree tree = fileTree(dir: "$projectDir/src", include: ["**/*.aar"])
tree.each { File file ->
// remove the extension of the file (.aar)
def length = file.name.length() - 4
def fileName = file.name[0..<length]
println "\t+adding dependency: " + file.getAbsolutePath()
project.dependencies.add("compile", [name: fileName, ext: "aar"])
}
}

def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')

/////////////////////////////// installing application ////////////////////////////

task installApk(type: Exec) {
doFirst {
println "Attempting to install buit apk"

if (isWinOs) {
commandLine "cmd", "/c", "node", "$rootDir\\tools\\deploy-apk.js", "$rootDir\\runtimedebug\\build\\outputs\\apk\\app-debug.apk"
} else {
commandLine "node", "$rootDir/tools/deploy-apk.js", "$rootDir/runtimedebug/build/outputs/apk/app-debug.apk"
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}

doLast {
println "Install result:" + execResult
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.8.2'
}
}

task startInstalledApk(type: Exec) {
doFirst {
println "Starting test application"

if (isWinOs) {
commandLine "cmd", "/c", "adb", "shell", "am", "start", "-n", "org.nativescript.runtimedebug/com.tns.NativeScriptActivity", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER"
} else {
commandLine "adb", "shell", "am", "start", "-n", "org.nativescript.runtimedebug/com.tns.NativeScriptActivity", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER"
}
allprojects {
repositories {
jcenter()
}
}

startInstalledApk.dependsOn(installApk)
}
20 changes: 20 additions & 0 deletions test-cli-app/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

#org.gradle.jvmargs=-Xmx2048M
Binary file added test-cli-app/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions test-cli-app/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Thu Aug 18 11:40:33 EEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
Loading