@@ -138,8 +138,6 @@ class AndroidDebugService implements IDebugService {
138
138
this . startAppWithDebugger ( packageFile , packageName ) . wait ( ) ;
139
139
} else {
140
140
this . startAppWithDebugger ( packageFile , packageName ) . wait ( ) ;
141
- //TODO: Find different way to make sure that the app is started.
142
- sleep ( 500 ) ;
143
141
this . attachDebugger ( device . deviceInfo . identifier , packageName ) . wait ( ) ;
144
142
}
145
143
} ) . future < void > ( ) ( ) ;
@@ -202,41 +200,46 @@ class AndroidDebugService implements IDebugService {
202
200
// As we need to redirect output of a command on the device, keep using only one argument.
203
201
// We could rewrite this with two calls - touch and rm -f , but -f flag is not available on old Android, so rm call will fail when file does not exist.
204
202
203
+ this . device . applicationManager . stopApplication ( packageName ) . wait ( ) ;
204
+
205
205
if ( this . $options . debugBrk ) {
206
206
this . device . adb . executeShellCommand ( [ `cat /dev/null > /data/local/tmp/${ packageName } -debugbreak` ] ) . wait ( ) ;
207
207
}
208
+ this . device . adb . executeShellCommand ( [ `cat /dev/null > /data/local/tmp/${ packageName } -debugger-started` ] ) . wait ( ) ;
208
209
209
- this . device . applicationManager . stopApplication ( packageName ) . wait ( ) ;
210
210
this . device . applicationManager . startApplication ( packageName ) . wait ( ) ;
211
211
212
- if ( this . $options . debugBrk ) {
213
- let waitText : string = `0 /data/local/tmp/${ packageName } -debugbreak` ;
214
- let maxWait = 12 ;
215
- let debugerStarted : boolean = false ;
216
- while ( maxWait > 0 && ! debugerStarted ) {
217
- let forwardsResult = this . device . adb . executeShellCommand ( [ "ls" , "-s" , `/data/local/tmp/${ packageName } -debugbreak` ] ) . wait ( ) ;
218
- maxWait -- ;
219
- debugerStarted = forwardsResult . indexOf ( waitText ) === - 1 ;
220
- if ( ! debugerStarted ) {
221
- sleep ( 500 ) ;
222
- }
223
- }
224
-
225
- if ( debugerStarted ) {
226
- this . $logger . info ( "# NativeScript Debugger started #" ) ;
227
- } else {
228
- this . $logger . warn ( "# NativeScript Debugger did not start in time #" ) ;
229
- }
212
+ this . waitForDebugger ( packageName ) ;
230
213
231
- if ( this . $options . client ) {
232
- let localDebugPort = this . getForwardedLocalDebugPortForPackageName ( this . device . deviceInfo . identifier , packageName ) . wait ( ) ;
233
- this . startDebuggerClient ( localDebugPort ) . wait ( ) ;
234
- this . openDebuggerClient ( AndroidDebugService . DEFAULT_NODE_INSPECTOR_URL + "?port=" + localDebugPort ) ;
235
- }
214
+ if ( this . $options . client ) {
215
+ let localDebugPort = this . getForwardedLocalDebugPortForPackageName ( this . device . deviceInfo . identifier , packageName ) . wait ( ) ;
216
+ this . startDebuggerClient ( localDebugPort ) . wait ( ) ;
217
+ this . openDebuggerClient ( AndroidDebugService . DEFAULT_NODE_INSPECTOR_URL + "?port=" + localDebugPort ) ;
236
218
}
219
+
237
220
} ) . future < void > ( ) ( ) ;
238
221
}
239
222
223
+ private waitForDebugger ( packageName : String ) {
224
+ let waitText : string = `0 /data/local/tmp/${ packageName } -debugger-started` ;
225
+ let maxWait = 12 ;
226
+ let debugerStarted : boolean = false ;
227
+ while ( maxWait > 0 && ! debugerStarted ) {
228
+ let forwardsResult = this . device . adb . executeShellCommand ( [ "ls" , "-s" , `/data/local/tmp/${ packageName } -debugger-started` ] ) . wait ( ) ;
229
+ maxWait -- ;
230
+ debugerStarted = forwardsResult . indexOf ( waitText ) === - 1 ;
231
+ if ( ! debugerStarted ) {
232
+ sleep ( 500 ) ;
233
+ }
234
+ }
235
+
236
+ if ( debugerStarted ) {
237
+ this . $logger . info ( "# NativeScript Debugger started #" ) ;
238
+ } else {
239
+ this . $logger . warn ( "# NativeScript Debugger did not start in time #" ) ;
240
+ }
241
+ }
242
+
240
243
private startDebuggerClient ( port : Number ) : IFuture < void > {
241
244
return ( ( ) => {
242
245
let nodeInspectorModuleFilePath = require . resolve ( "node-inspector" ) ;
0 commit comments