Exemplo n.º 1
0
        private static string GetSdkApiLevel()
        {
            if (CachedSDKLevel == null)
            {
                // default to looking on disk for latest API level
                string Target = AndroidPlatform.AndroidSdkApiTarget;

                // if we want to use whatever version the ndk uses, then use that
                if (Target == "matchndk")
                {
                    Target = AndroidToolChain.GetNdkApiLevel();
                }

                // run a command and capture output
                if (Target == "latest")
                {
                    // we expect there to be one, so use the first one
                    string AndroidCommandPath = Environment.ExpandEnvironmentVariables("%ANDROID_HOME%/tools/android.bat");

                    var ExeInfo = new ProcessStartInfo(AndroidCommandPath, "list targets");
                    ExeInfo.UseShellExecute        = false;
                    ExeInfo.RedirectStandardOutput = true;
                    using (var GameProcess = Process.Start(ExeInfo))
                    {
                        PossibleApiLevels = new List <string>();
                        GameProcess.BeginOutputReadLine();
                        GameProcess.OutputDataReceived += ParseApiLevel;
                        GameProcess.WaitForExit();
                    }

                    if (PossibleApiLevels != null && PossibleApiLevels.Count > 0)
                    {
                        Target = AndroidToolChain.GetLargestApiLevel(PossibleApiLevels.ToArray());
                    }
                    else
                    {
                        throw new BuildException("Can't make an APK an API installed (see \"android.bat list targets\")");
                    }
                }

                Console.WriteLine("Building Java with SDK API '{0}'", Target);
                CachedSDKLevel = Target;
            }

            return(CachedSDKLevel);
        }