@@ -34,18 +34,18 @@ public string[] AllAndroidNdks {
3434 public string AndroidToolsPathShort { get ; private set ; }
3535 public string AndroidPlatformToolsPathShort { get ; private set ; }
3636
37- public abstract string Adb { get ; }
38- public abstract string Android { get ; }
39- public abstract string Emulator { get ; }
40- public abstract string Monitor { get ; }
41- public abstract string ZipAlign { get ; }
42- public abstract string JarSigner { get ; }
43- public abstract string KeyTool { get ; }
44-
45- public abstract string NdkStack { get ; }
37+ public virtual string Adb { get ; protected set ; } = "adb" ;
38+ public virtual string Android { get ; protected set ; } = "android" ;
39+ public virtual string Emulator { get ; protected set ; } = "emulator" ;
40+ public virtual string Monitor { get ; protected set ; } = "monitor" ;
41+ public virtual string ZipAlign { get ; protected set ; } = "zipalign" ;
42+ public virtual string JarSigner { get ; protected set ; } = "jarsigner" ;
43+ public virtual string KeyTool { get ; protected set ; } = "keytool" ;
44+
45+ public virtual string NdkStack { get ; protected set ; } = "ndk-stack" ;
4646 public abstract string NdkHostPlatform32Bit { get ; }
4747 public abstract string NdkHostPlatform64Bit { get ; }
48- public abstract string Javac { get ; }
48+ public virtual string Javac { get ; protected set ; } = "javac" ;
4949
5050 public abstract string PreferedAndroidSdkPath { get ; }
5151 public abstract string PreferedAndroidNdkPath { get ; }
@@ -81,6 +81,13 @@ public virtual void Initialize (string androidSdkPath = null, string androidNdkP
8181 IsNdk64Bit = Directory . EnumerateDirectories ( toolchainsDir , "arm-linux-androideabi-*" )
8282 . Any ( dir => Directory . Exists ( Path . Combine ( dir , "prebuilt" , NdkHostPlatform64Bit ) ) ) ;
8383 }
84+ // we need to look for extensions other than the default .exe|.bat
85+ // google have a habbit of changing them.
86+ Adb = GetExecutablePath ( AndroidPlatformToolsPath , Adb ) ;
87+ Android = GetExecutablePath ( AndroidToolsPath , Android ) ;
88+ Emulator = GetExecutablePath ( AndroidToolsPath , Emulator ) ;
89+ Monitor = GetExecutablePath ( AndroidToolsPath , Monitor ) ;
90+ NdkStack = GetExecutablePath ( AndroidNdkPath , NdkStack ) ;
8491 }
8592
8693 protected abstract IEnumerable < string > GetAllAvailableAndroidSdks ( ) ;
@@ -119,26 +126,40 @@ public virtual bool ValidateJavaSdkLocation (string loc)
119126 /// </summary>
120127 public bool ValidateAndroidNdkLocation ( string loc )
121128 {
122- return ! string . IsNullOrEmpty ( loc ) && File . Exists ( Path . Combine ( loc , NdkStack ) ) ;
129+ return ! string . IsNullOrEmpty ( loc ) && FindExecutableInDirectory ( NdkStack , loc ) . Any ( ) ;
123130 }
124131
125132 protected IEnumerable < string > FindExecutableInPath ( string executable )
126133 {
127134 var path = Environment . GetEnvironmentVariable ( "PATH" ) ;
128135 var pathDirs = path . Split ( new char [ ] { Path . PathSeparator } , StringSplitOptions . RemoveEmptyEntries ) ;
129- var pathExt = Environment . GetEnvironmentVariable ( "PATHEXT" ) ;
130- var pathExts = pathExt ? . Split ( new char [ ] { Path . PathSeparator } , StringSplitOptions . RemoveEmptyEntries ) ;
131136
132137 foreach ( var dir in pathDirs ) {
133- if ( File . Exists ( Path . Combine ( dir , ( executable ) ) ) )
134- yield return dir ;
135- if ( pathExts == null )
136- continue ;
137- foreach ( var ext in pathExts )
138- if ( File . Exists ( Path . Combine ( dir , Path . ChangeExtension ( executable , ext ) ) ) )
139- yield return dir ;
138+ foreach ( var directory in FindExecutableInDirectory ( executable , dir ) ) {
139+ yield return directory ;
140+ }
140141 }
141142 }
143+
144+ protected IEnumerable < string > FindExecutableInDirectory ( string executable , string dir )
145+ {
146+ foreach ( var exe in Executables ( executable ) )
147+ if ( File . Exists ( Path . Combine ( dir , exe ) ) )
148+ yield return dir ;
149+ }
150+
151+ IEnumerable < string > Executables ( string executable )
152+ {
153+ yield return executable ;
154+ var pathExt = Environment . GetEnvironmentVariable ( "PATHEXT" ) ;
155+ var pathExts = pathExt ? . Split ( new char [ ] { Path . PathSeparator } , StringSplitOptions . RemoveEmptyEntries ) ;
156+
157+ if ( pathExts == null )
158+ yield break ;
159+
160+ foreach ( var ext in pathExts )
161+ yield return Path . ChangeExtension ( executable , ext ) ;
162+ }
142163
143164 protected string NullIfEmpty ( string s )
144165 {
@@ -147,6 +168,14 @@ protected string NullIfEmpty (string s)
147168
148169 return null ;
149170 }
171+
172+ string GetExecutablePath ( string dir , string exe )
173+ {
174+ foreach ( var e in Executables ( exe ) )
175+ if ( File . Exists ( Path . Combine ( dir , e ) ) )
176+ return e ;
177+ return exe ;
178+ }
150179 }
151180}
152181
0 commit comments