Skip to content

Commit f3943b1

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] Read NDK version from source.properties (#138)
Google has removed the RELEASE.txt from the latest ndk version in favour of a source.properties file. This commit adds support for reading the version from this new file.
1 parent 158a0f1 commit f3943b1

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,23 @@ static bool GetNdkToolchainRelease (string androidNdkPath, out string version)
175175
return true;
176176
}
177177

178+
static bool GetNdkToolchainSourceProperties (string androidNdkPath, out NdkVersion version)
179+
{
180+
version = new NdkVersion ();
181+
var sourcePropertiesPath = Path.Combine (androidNdkPath, "source.properties");
182+
if (!File.Exists (sourcePropertiesPath)) {
183+
return false;
184+
}
185+
var match = Regex.Match (File.ReadAllText (sourcePropertiesPath).Trim (), "^Pkg.Revision\\s*=\\s*([.0-9]+)$", RegexOptions.Multiline);
186+
if (!match.Success) {
187+
return false;
188+
}
189+
var numbers = match.Groups[1].Value.Trim().Split ('.');
190+
version.Version = int.Parse (numbers [0]);
191+
version.Revision = Convert.ToChar (int.Parse (numbers [1]) + (int)'a').ToString ();
192+
return true;
193+
}
194+
178195
public struct NdkVersion
179196
{
180197
public int Version;
@@ -186,8 +203,11 @@ public static bool GetNdkToolchainRelease (string androidNdkPath, out NdkVersion
186203
ndkVersion = new NdkVersion ();
187204

188205
string version;
189-
if (!GetNdkToolchainRelease(androidNdkPath, out version))
206+
if (!GetNdkToolchainRelease (androidNdkPath, out version)) {
207+
if (GetNdkToolchainSourceProperties (androidNdkPath, out ndkVersion))
208+
return true;
190209
return false;
210+
}
191211

192212
var match = Regex.Match(version, @"r(\d+)\s*(.*)\s+.*");
193213
if( !match.Success)

0 commit comments

Comments
 (0)