Ejemplo n.º 1
0
        public override bool Execute()
        {
            Log.LogDebugMessage("JarToXml Task");
            Log.LogDebugMessage("  JavaOptions: {0}", JavaOptions);
            Log.LogDebugMessage("  JavaMaximumHeapSize: {0}", JavaMaximumHeapSize);
            Log.LogDebugMessage("  AndroidSdkDirectory: {0}", AndroidSdkDirectory);
            Log.LogDebugMessage("  AndroidApiLevel: {0}", AndroidApiLevel);
            Log.LogDebugMessage("  MonoAndroidToolsDirectory: {0}", MonoAndroidToolsDirectory);
            Log.LogDebugMessage("  JavaSdkDirectory: {0}", JavaSdkDirectory);
            Log.LogDebugMessage("  OutputFile: {0}", OutputFile);
            Log.LogDebugMessage("  DroidDocPaths: {0}", DroidDocPaths);
            Log.LogDebugMessage("  JavaDocPaths: {0}", JavaDocPaths);
            Log.LogDebugMessage("  Java7DocPaths: {0}", Java7DocPaths);
            Log.LogDebugMessage("  Java8DocPaths: {0}", Java8DocPaths);
            Log.LogDebugTaskItems("  JavaDocs: {0}", JavaDocs);
            Log.LogDebugTaskItems("  LibraryProjectJars:", LibraryProjectJars);
            Log.LogDebugTaskItems("  SourceJars:", SourceJars);
            Log.LogDebugTaskItems("  ReferenceJars:", ReferenceJars);

            if (SourceJars == null || SourceJars.Count() == 0)
            {
                Log.LogError("At least one Java library is required for binding, this must be either 'EmbeddedJar', 'InputJar' (for jar), 'LibraryProjectZip' (for aar or zip) or 'LibraryProjectProperties' (project.properties) build action.");
                return(false);
            }

            // Ensure that the user has the platform they are targeting installed
            var jarpath = Path.Combine(AndroidSdk.GetPlatformDirectoryFromApiLevel(AndroidApiLevel, MonoAndroidHelper.SupportedVersions), "android.jar");

            if (!File.Exists(jarpath))
            {
                Log.LogError("Could not find android.jar for API Level {0}.  This means the Android SDK platform for API Level {0} is not installed.  Either install it in the Android SDK Manager, or change your Android Bindings project to target an API version that is installed. ({1} missing.)", AndroidApiLevel, jarpath);
                return(false);
            }

            // Ensure that all requested jars exist
            foreach (var jar in SourceJars)
            {
                if (!File.Exists(jar.ItemSpec))
                {
                    Log.LogError("Specified source jar not found: {0}", jar.ItemSpec);
                }
            }

            if (ReferenceJars != null)
            {
                foreach (var jar in ReferenceJars)
                {
                    if (!File.Exists(jar.ItemSpec))
                    {
                        Log.LogError("Specified reference jar not found: {0}", jar.ItemSpec);
                    }
                }
            }

            if (Log.HasLoggedErrors)
            {
                return(false);
            }

            // Ensure our output directory exists
            Directory.CreateDirectory(Path.GetDirectoryName(OutputFile));

            return(base.Execute());
        }
        public override bool Execute()
        {
            Log.LogDebugMessage("GetJavaPlatformJar Task");
            Log.LogDebugMessage("  AndroidSdkDirectory: {0}", AndroidSdkDirectory);
            Log.LogDebugMessage("  AndroidSdkPlatform: {0}", AndroidSdkPlatform);
            Log.LogDebugMessage("  AndroidManifest: {0}", AndroidManifest);

            var platform = AndroidSdkPlatform;

            XAttribute target_sdk = null;

            // Look for targetSdkVersion in the user's AndroidManifest.xml
            if (!string.IsNullOrWhiteSpace(AndroidManifest))
            {
                if (!File.Exists(AndroidManifest))
                {
                    Log.LogError("Specified AndroidManifest.xml file does not exist: {0}.", AndroidManifest);
                    return(false);
                }

                try {
                    var doc      = XDocument.Load(AndroidManifest);
                    var manifest = doc.Root;

                    if (manifest != null)
                    {
                        var uses_sdk = manifest.Element("uses-sdk");

                        if (uses_sdk != null)
                        {
                            target_sdk = uses_sdk.Attribute(androidNs + "targetSdkVersion");

                            if (target_sdk != null && !string.IsNullOrWhiteSpace(target_sdk.Value))
                            {
                                platform = target_sdk.Value;
                            }
                        }
                    }
                } catch (Exception ex) {
                    // If they're manifest is bad, let's error them out
                    Log.LogErrorFromException(ex, true);
                    return(false);
                }
            }

            platform            = GetTargetSdkVersion(platform, target_sdk);
            JavaPlatformJarPath = Path.Combine(AndroidSdk.GetPlatformDirectoryFromApiLevel(platform, MonoAndroidHelper.SupportedVersions), "android.jar");

            if (!File.Exists(JavaPlatformJarPath))
            {
                Log.LogError("Could not find android.jar for API Level {0}. " +
                             "This means the Android SDK platform for API Level {0} is not installed. " +
                             "Either install it in the Android SDK Manager (Tools > Open Android SDK Manager...), " +
                             "or change your Xamarin.Android project to target an API version that is installed. " +
                             "({1} missing.)",
                             platform, JavaPlatformJarPath);
                return(false);
            }

            TargetSdkVersion = platform;

            Log.LogDebugMessage("  [Output] JavaPlatformJarPath: {0}", JavaPlatformJarPath);
            Log.LogDebugMessage("  [Output] TargetSdkVersion: {0}", TargetSdkVersion);

            return(true);
        }
Ejemplo n.º 3
0
        protected override string GenerateCommandLineCommands()
        {
            var cmd = new CommandLineBuilder();

            // Add the JavaOptions if they are not null
            // These could be any of the additional options
            if (!string.IsNullOrEmpty(JavaOptions))
            {
                cmd.AppendSwitch(JavaOptions);
            }

            // Add the specific -XmxN to override the default heap size for the JVM
            // N can be in the form of Nm or NGB (e.g 100m or 1GB )
            cmd.AppendSwitchIfNotNull("-Xmx", JavaMaximumHeapSize);

            // See https://bugzilla.xamarin.com/show_bug.cgi?id=21096
            cmd.AppendSwitch("-XX:-UseSplitVerifier");

            // Arguments sent to java.exe
            cmd.AppendSwitchIfNotNull("-jar ", Path.Combine(MonoAndroidToolsDirectory, "jar2xml.jar"));

            foreach (var jar in SourceJars)
            {
                cmd.AppendSwitchIfNotNull("--jar=", Path.GetFullPath(jar.ItemSpec));
            }

            var libraryProjectJars = MonoAndroidHelper.ExpandFiles(LibraryProjectJars);

            foreach (var jar in libraryProjectJars)
            {
                if (MonoAndroidHelper.IsEmbeddedReferenceJar(jar))
                {
                    cmd.AppendSwitchIfNotNull("--ref=", Path.GetFullPath(jar));
                }
                else
                {
                    cmd.AppendSwitchIfNotNull("--jar=", Path.GetFullPath(jar));
                }
            }

            // Arguments sent to jar2xml
            var jarpath = Path.Combine(AndroidSdk.GetPlatformDirectoryFromApiLevel(AndroidApiLevel, MonoAndroidHelper.SupportedVersions), "android.jar");

            cmd.AppendSwitchIfNotNull("--ref=", Path.GetFullPath(jarpath));

            cmd.AppendSwitchIfNotNull("--out=", Path.GetFullPath(OutputFile));

            if (ReferenceJars != null)
            {
                foreach (var jar in ReferenceJars)
                {
                    cmd.AppendSwitchIfNotNull("--ref=", Path.GetFullPath(jar.ItemSpec));
                }
            }

            if (DroidDocPaths != null)
            {
                foreach (var path in DroidDocPaths.Split(';'))
                {
                    cmd.AppendSwitchIfNotNull("--droiddocpath=", Path.GetFullPath(path));
                }
            }

            if (JavaDocPaths != null)
            {
                foreach (var path in JavaDocPaths.Split(';'))
                {
                    cmd.AppendSwitchIfNotNull("--javadocpath=", Path.GetFullPath(path));
                }
            }

            if (Java7DocPaths != null)
            {
                foreach (var path in Java7DocPaths.Split(';'))
                {
                    cmd.AppendSwitchIfNotNull("--java7docpath=", Path.GetFullPath(path));
                }
            }

            if (Java8DocPaths != null)
            {
                foreach (var path in Java8DocPaths.Split(';'))
                {
                    cmd.AppendSwitchIfNotNull("--java8docpath=", Path.GetFullPath(path));
                }
            }

            if (JavaDocs != null)
            {
                foreach (var doc in JavaDocs)
                {
                    var opt = GetJavadocOption(doc.ItemSpec);
                    if (opt != null)
                    {
                        cmd.AppendSwitchIfNotNull(opt, Path.GetFullPath(Path.GetDirectoryName(doc.ItemSpec)));
                    }
                }
            }
            return(cmd.ToString());
        }