@@ -50,6 +50,34 @@ export class ShiftA implements IKeyCommand {
50
50
private $projectData : IProjectData
51
51
) { }
52
52
53
+ getAndroidStudioPath ( ) : string | null {
54
+ const os = currentPlatform ( ) ;
55
+
56
+ if ( os === "darwin" ) {
57
+ const possibleStudioPaths = [
58
+ "/Applications/Android Studio.app" ,
59
+ `${ process . env . HOME } /Applications/Android Studio.app` ,
60
+ ] ;
61
+
62
+ return possibleStudioPaths . find ( ( p ) => fs . existsSync ( p ) ) || null ;
63
+ } else if ( os === "win32" ) {
64
+ const studioPath = path . join (
65
+ "C:" ,
66
+ "Program Files" ,
67
+ "Android" ,
68
+ "Android Studio" ,
69
+ "bin" ,
70
+ "studio64.exe"
71
+ ) ;
72
+ return fs . existsSync ( studioPath ) ? studioPath : null ;
73
+ } else if ( os === "linux" ) {
74
+ const studioPath = "/usr/local/android-studio/bin/studio.sh" ;
75
+ return fs . existsSync ( studioPath ) ? studioPath : null ;
76
+ }
77
+
78
+ return null ;
79
+ }
80
+
53
81
async execute ( ) : Promise < void > {
54
82
this . $liveSyncCommandHelper . validatePlatform ( this . platform ) ;
55
83
this . $projectData . initializeProjectData ( ) ;
@@ -65,53 +93,32 @@ export class ShiftA implements IKeyCommand {
65
93
}
66
94
}
67
95
68
- const os = currentPlatform ( ) ;
96
+ let studioPath = null ;
69
97
70
- if ( os === "darwin" ) {
71
- const possibleStudioPaths = [
72
- "/Applications/Android Studio.app" ,
73
- `${ process . env . HOME } /Applications/Android Studio.app` ,
74
- ] ;
98
+ studioPath = process . env . NATIVESCRIPT_ANDROID_STUDIO_PATH ;
75
99
76
- const studioPath = possibleStudioPaths . find ( ( p ) => {
77
- this . $logger . trace ( `Checking for Android Studio at ${ p } ` ) ;
78
- return fs . existsSync ( p ) ;
79
- } ) ;
100
+ if ( ! studioPath ) {
101
+ studioPath = this . getAndroidStudioPath ( ) ;
80
102
81
103
if ( ! studioPath ) {
82
104
this . $logger . error (
83
- "Android Studio is not installed, or not in a standard location."
105
+ "Android Studio is not installed, or is not in a standard location. Use NATIVESCRIPT_ANDROID_STUDIO_PATH ."
84
106
) ;
85
107
return ;
86
108
}
109
+ }
110
+
111
+ const os = currentPlatform ( ) ;
112
+ if ( os === "darwin" ) {
87
113
this . $childProcess . exec ( `open -a "${ studioPath } " ${ androidDir } ` ) ;
88
114
} else if ( os === "win32" ) {
89
- const studioPath = path . join (
90
- "C:" ,
91
- "Program Files" ,
92
- "Android" ,
93
- "Android Studio" ,
94
- "bin" ,
95
- "studio64.exe"
96
- ) ;
97
- if ( ! fs . existsSync ( studioPath ) ) {
98
- this . $logger . error ( "Android Studio is not installed" ) ;
99
- return ;
100
- }
101
-
102
115
const child = this . $childProcess . spawn ( studioPath , [ androidDir ] , {
103
116
detached : true ,
104
117
stdio : "ignore" ,
105
118
} ) ;
106
119
child . unref ( ) ;
107
120
} else if ( os === "linux" ) {
108
- if ( ! fs . existsSync ( `/usr/local/android-studio/bin/studio.sh` ) ) {
109
- this . $logger . error ( "Android Studio is not installed" ) ;
110
- return ;
111
- }
112
- this . $childProcess . exec (
113
- `/usr/local/android-studio/bin/studio.sh ${ androidDir } `
114
- ) ;
121
+ this . $childProcess . exec ( `${ studioPath } ${ androidDir } ` ) ;
115
122
}
116
123
}
117
124
}
0 commit comments