Thank you, thank you, thank you for sharing your Nativescript expertise. I'm pretty stuck
I'm really trying. I'm searching and trying for last couple days to get a simple Nativescript demo app to run in VS Code debugger and break.
I have my dev environment fully setup. I can build and run Nativescript demo apps in VS Code as long as I don't try to use the debugger.
Here is my tns doctor output. You can see I have it all setup correctly.
I'm only doing Android for now. Ignore the tns-ios update.
I have my launch.json setup like this...
{
"name": "Launch on Android",
"type": "nativescript",
"request": "launch",
"platform": "android",
"appRoot": "${workspaceRoot}",
"sourceMaps": true,
"watch": true,
"tnsArgs": [
"--debug",
"--bundle"
]
},
I've added this line to my webpack.config.js...
devtool: "eval-source-map",
And so far, above is all I can find on how to get Nativescript app debugging working in VS Code. What am I missing? Here is what I get in VS Code debug output when I try to do Launch on Android. Link is to Pastebin...
Nativescript VSCode 'Launch on Android' debug output
EDIT 2/3 console output after running commands in first comment...
[NativeScriptCli] execute: tns --analyticsClient VSCode --version
[NativeScriptCli] execute: tns --analyticsClient VSCode --version
[NSDebugAdapter] Using tns CLI v5.1.1 on path 'tns'
[NSDebugAdapter] Running tns command...
[NativeScriptCli] execute: tns --analyticsClient VSCode debug android --watch --bundle
[NSDebugAdapter] Watching the tns CLI output to receive a connection token
Searching for devices...
Executing before-watchPatterns hook from C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\hooks\before-watchPatterns\nativescript-dev-webpack.js
Executing before-watch hook from C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\hooks\before-watch\nativescript-dev-webpack.js
Running webpack for Android...
Bundling application for entryPath .\app...
C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\webpack-cli\bin\cli.js:453
throw err;
^
Error: EPERM: operation not permitted, scandir 'C:/Users/markd/Documents/code-projects/nativescript/blank-vue-app/platforms/android/app/src/main/assets/app/App_Resources/Android/drawable-mdpi/background.png'
at Object.readdirSync (fs.js:786:3)
at GlobSync._readdir (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:288:41)
at GlobSync._readdirInGlobStar (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:267:20)
at GlobSync._readdir (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:276:17)
at GlobSync._processReaddir (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:137:22)
at GlobSync._process (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:132:10)
at GlobSync._processGlobStar (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:380:10)
at GlobSync._process (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:130:10)
at GlobSync._processGlobStar (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:383:10)
at GlobSync._process (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:130:10)
at GlobSync._processGlobStar (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:383:10)
at GlobSync._process (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:130:10)
at GlobSync._processGlobStar (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:383:10)
at GlobSync._process (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:130:10)
at new GlobSync (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:48:10)
at Function.globSync [as sync] (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\glob\sync.js:26:10)
at Function.rimrafSync [as sync] (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\rimraf\rimraf.js:280:22)
at C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\clean-webpack-plugin\index.js:166:16
at Array.forEach ()
at CleanWebpackPlugin.clean (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\clean-webpack-plugin\index.js:92:15)
at CleanWebpackPlugin.apply (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\clean-webpack-plugin\index.js:212:20)
at webpack (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\webpack\lib\webpack.js:47:13)
at processOptions (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\webpack-cli\bin\cli.js:441:16)
at yargs.parse (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\webpack-cli\bin\cli.js:536:3)
at Object.parse (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\yargs\yargs.js:567:18)
at C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\webpack-cli\bin\cli.js:219:8
at Object. (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\webpack-cli\bin\cli.js:538:3)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object. (C:\Users\markd\Documents\code-projects\nativescript\blank-vue-app\node_modules\webpack\bin\webpack.js:155:2)
at Module._compile (internal/modules/cjs/loader.js:689:30)
[31;1mExecuting webpack failed with exit code 1.[0m
[31;1mCannot read property 'kill' of undefined[0m
tns debug
Description
Initiates a debugging session for your project on a connected device or native emulator. When necessary, the command will prepare, build, deploy and launch the app before starting the debug session. While debugging, the output from the application is printed in the console and any changes made to your code are synchronized on all connected devices or running emulators.
Commands
┌─────────┬─────────────────────┐
│ Usage │ Synopsis │
│ General │ $ tns debug android │
└─────────┴─────────────────────┘
If you aren't getting Chrome debugger to work, you won't get any better results with VS Code, since it uses the same protocol.
I assume you have nativescript-dev-webpack included in your 'devDependencies' block of your package.json?
If not, npm install --save-dev nativescript-dev-webpack
then, tns debug android should prompt you with the URL for the chrome debugger connection, and from there you should be able to set a breakpoint somewhere in your code that your application can hit after a button click or some similar direct user event. If you try to set a breakpoint early in the startup of the app, it may not hit it unless you use the --debug-brk flag (see https://docs.nativescript.org/tooling/debugging/debugging#debugger-options). Best to start with something you can trigger after the app if fully up and running. this will be especially true when using VS Code.
Once you get this level of success with Chrome, install the Nativescript extensions for VS Code (https://docs.nativescript.org/tooling/visual-studio-code-extension).
Note that, when in VS Code, clicking the 'settings gear' icon allows you to edit launch.json which controls the target configuration for the debug options. If you have a root other than ${workspaceRoot}, for example, you may need to edit it here so that finds your project in the right place.
When I use this, I use the 'attach android' option, rather than the launch, but that's mostly just my preference. I believe it works either way. I launch from the command line with tns debug android and then in VS Code select 'attach android' and then wait (a short but seemingly long time) for the 'back and forth' progress indicator at the top to stop and the console output to say 'ready to attach debugger' Then I can select a breakpoint and trigger the app, and it will catch it. It can be frustrating to insure the debugger attachment is in place, especially after an edit that triggers a restart, because of the delay. But I use it for my android debugging quite a bit. For whatever reason, it disconnects repeatedly for me when I try to do the same for iOS, but for that, Chrome works nicely.
What I'd really like is a tight and clean debugger solution for WebStorm, which is my IDE of choice, and there used to be one (that no longer works). Such is life.
You need nativescript-dev-webpack#0.19.1 and need to update your webpack.config file
npm i nativescript-dev-webpack#latest --save-dev
./node_modules/.bin/update-ns-webpack --configs
Related
I have setup a Cordova app with react following this tutorial.
When I try to run it on a physical android device using cordova run android -- --livereload The app is not compiled and not sent to the device, the only output I get is:
cordova run android -- --livereload
Successfully built!
GLOBAL is not defined
This is the verbose output of the command:
GLOBAL is not defined
ReferenceError: GLOBAL is not defined
at Object.isLiveReloadActivated (/Users/ivan/Desktop/MasterThesis/Test2/cordovaReact/plugins/cordova-plugin-livereload/lib/utils/helpers.js:94:5)
at Object.module.exports.isLiveReloadActive (/Users/ivan/Desktop/MasterThesis/Test2/cordovaReact/plugins/cordova-plugin-livereload/lib/index.js:21:17)
at module.exports (/Users/ivan/Desktop/MasterThesis/Test2/cordovaReact/plugins/cordova-plugin-livereload/lib/postEmulateRunHook.js:19:13)
at runScriptViaModuleLoader (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:157:32)
at runScript (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:136:12)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:108:40
at processTicksAndRejections (internal/process/task_queues.js:95:5)
What is GLOBAL and how can I fix this error in order to get my app to compile and live reload?
Add this to your index.html file
<script>const global = globalThis;</script>
When using the NFC library the Ionic docs recommend
(https://github.com/chariotsolutions/phonegap-nfc)
(https://ionicframework.com/docs/native/nfc) I get a ''plugin not installed'' error when trying to reach the code in my component calling the ndef or nfc providers on my Android One Plus through the 'ionic serve --devapp' CLI command. It also says the devapp does not support this plugin, but I am unclear about how I am supposed to go about using this package testing wise in that case.
After specifying version 4 as per suggestion of this post for Ionic 3 I got a different error. This is with rxjs-compat installed and none of the nfc/ndef code actually used aside the imports in the module and component, and the injection into the constructor.
This is using "import {Ndef, NFC} from '#ionic-native/nfc';" instead of /nfc/ngx like above.
Uncaught TypeError: Object(...) is not a function
at index.js:405
at Module../node_modules/#ionic-native/nfc/index.js (index.js:599)
at __webpack_require__ (bootstrap:84)
at Module../src/app/app.module.ts (app.component.ts:12)
at __webpack_require__ (bootstrap:84)
at Module../src/main.ts (main.ts:1)
at __webpack_require__ (bootstrap:84)
at Object.0 (main.ts:12)
at __webpack_require__ (bootstrap:84)
at checkDeferredModules (bootstrap:45)
When I try to build the app instead of serving it with the devapp I come across this (perhaps unrelated) error, even though I am running the app in Android Studio on Windows 10 and have both my Java, Android and Gradle paths defined in my environment variables.
ANDROID_HOME=C:\Users\Sam\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181
Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
I have added the imports and the provider in the app module.
import {Ndef, NFC} from '#ionic-native/nfc';
#NgModule({
...
providers: [
NFC,
Ndef,
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
This is how I inject the providers into my class.
import { Component } from '#angular/core';
import {ToastController} from '#ionic/angular';
import {Ndef, NFC} from '#ionic-native/nfc';
#Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(private nfc: NFC, private ndef: Ndef, private toast: ToastController) {
}
Maybe I am completely on the wrong path about this, but following the documentation or any of the suggestion threads available on similar topics have not lead anywhere. Am I approaching this wrong?
EDIT: After running everything in a new project and making sure I go through each and every step without making any errors, I again end up with the INSTALL PLUGIN ERROR, like such.
[ng] [console.warn]: "Install the NFC plugin: 'ionic cordova plugin add phonegap-nfc'"
[ng] [console.warn]: "Native: tried calling NFC.removeNdefListener, but the NFC plugin is not installed."
[ng] [console.warn]: "Install the NFC plugin: 'ionic cordova plugin add phonegap-nfc'"
[ng] [console.log]: "Angular is running in the development mode. Call enableProdMode() to enable the production mode."
[ng] [console.log]: "calling _sync"
[ng] [console.error]: "ERROR" "plugin_not_installed"
[ng] [console.info]: "[WDS] Live Reloading enabled."
[ng] [console.log]: "calling _reload"
[ng] [console.log]: "done _reloading"
[ng] [console.log]: "Ionic Native: deviceready event fired after 836 ms"
This error appears in my console only when I open up the Android version of the app in DevApp after serving it with serve --devapp. It does not appear when I run it in the browser, it then just gives me the ''Cordova'' not available error, which I imagine is standard for plugins that don't work on certain devices. This is done following the exact step by step process, including the code in the ionic docs. https://ionicframework.com/docs/native/nfc
EDIT2: It might have to do with an XML processing error. When running through the same steps as before I came across an error I dismissed earlier when installing the plugin due to it resolving itself after installing both the iOS and Android platforms on Cordova. The error below happens after running the 'ionic cordova plugin add phonegap-nfc' command. The plugin however DOES install, and is listed under 'cordova plugin list' afterwards, but the installation might not be done completely correctly. The plug-in is not listed under the plugins in config.xml for example.
Failed to install 'phonegap-nfc': Error: Unable to graft xml at selector "/manifest/uses-sdk" from "C:\Users\cliem\Desktop\dev\nfctest\nfctest2\platforms\android\app\src\main\AndroidManifest.xml" during config install
at ConfigFile_graft_child [as graft_child] (C:\Users\cliem\Desktop\dev\nfctest\nfctest2\node_modules\cordova-common\src\ConfigChanges\ConfigFile.js:122:19)
Long story short, don't use a Java version over 8. Nfc plugin does not work with ionic serve --devapp and needs to be tested with ionic cordova run android instead. Console needs to be read out from chrome://inspect.
If you have the latest version of cordova which is 9.0.0, try
$ sudo npm uninstall -g cordova to uninstall it and install in back again with a previous version
$ sudo npm uninstall -g cordova#8.x
This worked for me
Using Android Studio 3.1.4 on Windows 64 Pro.
When running any app, including a sample project, Android Studio gets stuck the second time around on build/run cycle.
In Windows task manager I see java.exe suspended where one of the process threads it says is waiting on network i/o.
I have to kill java.exe from the Windows task manager every time I build/run an app.
I tried all of the following with no help:
deleted .gradle in my user folder
deleted .AndroidStudio3.1 folder in my user folder
invalidate caches/restart
use offline gradle option
disable instant run
Any ideas why this is happening? Seems that the build process is deadlocking on itself. This only happens on the second build/run.
I am encountering the same issue and have tried re-installs, differing JVMs, and countless other tactics. As a temporary workaround I have modified the Gradle build to create a flag file which a separate Powershell script then polls for and if found kills any running Open JDK process. This is a kludge without doubt but helps keep me sane.
Update build.gradle(Module:app) to include the following:
android {
compileSdkVersion 28
...
}
android.applicationVariants.all {
ant.touch(file:"D:/Build.flg")
}
}
Then run the following Powershell script
do {
Write-Host "Checking for D:\Build.flg"
if (Test-Path "D:\Build.flg") {
Remove-Item "D:\Build.flg"
Write-Host "Locating Java processes"
$JavaProcessos = Get-Process java | select Id, processname, Description
Foreach($Process in $JavaProcessos)
{
if($Process.Description -eq "OpenJDK Platform binary") {
Write-Host "Stopping process " $Process.Id $Process.Description
Start-Sleep -s 30
Stop-Process $Process.Id
}
}
}
Start-Sleep -s 10
}
While ($true)
Not pretty but functional.
I could not call the script directly from the build as it kills the JVM that Gradle itself is using at the time - thus the delay and flag approach.
I welcome suggestions to improve, until the root cause is addressed.
In the process of trying to fix the Android Studio alternate build hang, I damaged my Eclipse / Python install. Surprisingly, fixing Eclipse also seems to have eliminated the Android build problem. Came down to setting the right Java environment variables.
Press the ⊞ Win key and search for [Edit the system environment variables].
Then add / update the following based on the location of your JDK installation.
CLASSPATH=.;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_191
JDK_HOME=%JAVA_HOME%
JRE_HOME=%JAVA_HOME%\jre
Finally, add the Java bin to the start of your path
Path=%JAVA_HOME%\bin;...
After this my Android Studio builds no longer hang and Eclipse is fully functional.
I've used Sysinternals ProcessExplorer. In the context menu you can just RESUME the java process and the build will work
I'm trying to set up a local test rig for Appium before trying some cloud services. I've got the Appium.app running locally and have put together a very small test script in Ruby (using xpath). I'm trying to utilize arc (the Appium Ruby Console) to do some further scripting but am having trouble getting it launched. I've got everything installed (appium_lib, appium_console) and best I can tell it should be working. However, when I run the arc command at the terminal, I get the following error:
Failed to match sequence (ALL_SPACE (TABLE / TABLE_ARRAY / KEY_VALUE / COMMENT_LINE){0, } ALL_SPACE) at line 1 char 1.
`- Don't know what to do with "[caps]\n " at line 1 char 1.
Here are the contents of my appium.txt as of now.
[caps]
appium-version: '1.0',
platformName: 'Android',
platformVersion: '4.4',
deviceName: 'Nexus_5_API_22_Lollipop',
app: '/Users/justinr/Desktop/Development/TMSampleAndroid-master/app-debug.apk',
appPackage => 'com.marketlytics.calabashtest',
appActivity => 'com.marketlytics.calabashtest.MainActivity'
Thanks a ton in advance for any insight - please let me know if there are other useful files to see.
Running the arc setup android got this working for me (it stumps an appium.txt in the current directory). Still not sure what the problem with my original file was, though - I can't see any key differences.
I'm developing simple project using Chromium for android is there some way to debug Chromium C++ code through eclipse debugger?
Right now i have possibility to debug C++ through Terminal using GDB or DDD.
In case how to use DDD here is short instruction:
1.Install ddd application
sudo apt-get install ddd
2.Change adb_gdb file in directory chromium/src/build/android
change the line $GDB $GDBARGS -x $COMMANDS && to
ddd --debugger $GDB $GDBARGS -x $COMMANDS &&
cd /chromium/src
. build/android/envsetup.sh
build/android/adb_install_apk.py --apk ContentShell.apk
build/android/adb_run_content_shell
build/android/adb_gdb_content_shell
DDD application (example, how to use)
a. File->Open Source -> Filter -> set filename "ipc_chnnel_proxy.cc" -> Open
b. set breakpoints in the function ChannelProxy::Context::OnMessageReceived
c. run the command Cont
d. DDD will break on this breakpoint
See https://code.google.com/p/chromium/wiki/LinuxEclipseDev in particular the "Optional: Building inside Eclipse" section. It's still a bit flaky but works most of the time.
I got a working solution to debug Chromium for Android from Eclipse. It involves the creation of some wrappers following the idea you propose in your step 2. Your proposal lacks a way of telling Eclipse to use that debugging scripts, but it can be done by properly tweaking the debug configuration in Eclipse to use the gdb/mi debugger and open the proper wrappers.
All the steps are explained in this post: http://blogs.igalia.com/eocanha/2014/10/14/hacking-on-chromium-for-android-from-eclipse-part-2