绑定 Eclipse 库项目Binding an Eclipse Library Project

此演练说明了如何使用 Xamarin.Android 项目模板绑定一个 Eclipse Android 库项目。This walkthrough explains how to use Xamarin.Android project templates to bind an Eclipse Android library project.

概述Overview

尽管。AAR 文件正在逐渐成为 Android 库分发的标准,在某些情况下它为创建的绑定所需Android 库项目Although .AAR files are increasingly becoming the norm for Android library distribution, in some cases it is necessary to create a binding for an Android library project. Android 库项目都包含可共享代码的特殊 Android 项目和 Android 应用程序项目,可以引用的资源。Android library projects are special Android projects that contain shareable code and resources that can be referenced by Android application projects. 通常情况下,您将绑定到一个 Android 库项目时在 Eclipse IDE 中创建库。Typically, you bind to an Android library project when the library is created in the Eclipse IDE. 本演练介绍如何创建一个 Android 库项目的示例。从 Eclipse 项目的目录结构压缩。This walkthrough provides examples of how to create an Android library project .ZIP from the directory structure of an Eclipse project.

Android 库项目的不同于常规的 Android 项目在于这些不编译到一个 APK,不,代表自身,可部署到设备。Android library projects are different from regular Android projects in that they are not compiled into an APK and are not, on their own, deployable to a device. 而是意味着一个 Android 库项目引用的 Android 应用程序项目。Instead, an Android library project is meant to be referenced by an Android application project. 生成 Android 应用程序项目时,会首先编译 Android 库项目。When an Android application project is built, the Android library project is compiled first. Android 应用程序项目将会吸收到已编译的 Android 库项目,然后将代码和资源包含到分发的 APK。The Android application project will then be absorbed into the compiled Android library project and include the code and resources into the APK for distribution. 由于这种差异,创建一个 Android 库项目的绑定是创建 Java 绑定稍有不同。JAR 或。AAR 文件。Because of this difference, creating a binding for an Android library project is slightly different than creating a binding for a Java .JAR or .AAR file.

演练Walkthrough

在 Xamarin.Android Java 绑定项目中使用的 Android 库项目它时,第一个构建在 Eclipse 中的 Android 库项目。To use an Android library project in a Xamarin.Android Java Binding project it is first necessary to build the Android library project in Eclipse. 编译完成后,下面的屏幕截图显示一个 Android 库项目的示例:The following screenshot shows an example of one Android library project after compilation:

在 Eclipse 中的示例库项目Example library project in Eclipse

请注意,已从 Android 库项目的源代码编译到一个临时。名为 JAR 文件android mapviewballoons.jar,和资源复制到bin/res/危机文件夹。Notice that the source code from the Android library project has been compiled to a temporary .JAR file named android-mapviewballoons.jar, and that the resources have been copied to the bin/res/crunch folder.

在 Eclipse 中编译之后的 Android 库项目,它然后可将绑定使用 Xamarin.Android Java 绑定项目。Once the Android library project has been compiled in Eclipse, it can then be bound using a Xamarin.Android Java Binding project. 第一个。必须创建 ZIP 文件,其中包含binres Android 库项目的文件夹。First a .ZIP file must be created which contains the bin and res folders of the Android library project. 务必删除中间危机子目录,以便资源位于bin/res。下面的屏幕截图显示了内容的其中一个此类。ZIP 文件:It is important that you remove the intervening crunch subdirectory so that the resources reside in bin/res. The following screenshot shows the contents of one such .ZIP file:

Android 库项目.zip 的内容Contents of Android library project .zip

这。ZIP 文件然后添加到 Xamarin.Android Java 绑定项目中,如以下屏幕截图中所示:This .ZIP file is then added to Xamarin.Android Java Binding project, as shown in the following screenshot:

Zip 添加到 Java 绑定项目Zip added to Java Binding project

请注意,生成操作的。ZIP 文件已自动设置为LibraryProjectZipNotice that the Build Action of the .ZIP file has been automatically set to LibraryProjectZip.

如果有的话。所需的 Android 库项目的 JAR 文件,应将它们添加到Jar Java 绑定库项目的文件夹和生成操作设置为ReferenceJar.If there are any .JAR files that are required by the Android library project, they should be added to the Jars folder of the Java Binding Library project and the Build Action set to ReferenceJar. 此示例所示的屏幕截图:An example of this can be seen in the screenshot below:

生成操作设置为 ReferenceJarBuild action set to ReferenceJar

完成这些步骤后,如前面在本文档中所述,可以使用 Xamarin.Android Java 绑定项目。Once these steps are complete, the Xamarin.Android Java Binding project can be used as described earlier on in this document.

备注

目前不支持在其他 Ide 中编译的 Android 库项目。Compiling the Android library projects in other IDEs is not supported at this time. 相同的目录结构或中的文件不能创建其他 Ide bin Eclipse 的文件夹。Other IDEs may not create the same directory structure or files in the bin folder as Eclipse.

总结Summary

在本文中,我们介绍了通过绑定一个 Android 库项目的过程。In this article, we walked through the process of binding an Android library project. 我们构建 Android 库项目在 Eclipse 中,然后我们创建了从一个 zip 文件binres Android 库项目的文件夹。We built the Android library project in Eclipse, then we created a zip file from the bin and res folders of the Android library project. 接下来,我们使用此 zip 创建 Xamarin.Android Java 绑定项目。Next, we used this zip to create a Xamarin.Android Java Binding project.