ActionBarSherlock for Mono for Android的jar-Binding

我喜欢在我的Mono For Android项目中绑定ActionBarSherlock的jar库。 我尊重这个文档: http : //docs.xamarin.com/android/tutorials/Binding_a_Java_Library_(.jar)

我已经成功绑定了ActionBarSherlock所需要的android-support-v4.jar。 但是,当我尝试编译actionbarsherlock.jar时,它给我以下错误信息:

Target ResolveLibraryProjects: Skipping target "ResolveLibraryProjects" because it has no inputs. Target _ResolveMonoAndroidSdks: MonoAndroid Tools: C:\Program Files (x86)\MSBuild\Novell\ MonoAndroid Framework: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v2.2\;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\ Android SDK: C:\Program Files (x86)\Android\android-sdk\ Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_31\ Target ExportJarToXml: SourceJars: Jars\actionbarsherlock.jar ReferenceJars: Jars\android-support-v4.jar C:\Program Files (x86)\Java\jdk1.6.0_31\bin\java.exe -jar "C:\Program Files (x86)\MSBuild\Novell\jar2xml.jar" --jar=C:\Users\assrock\Documents\JavaBind\JavaBind\Jars\actionbarsherlock.jar --ref="C:\Program Files (x86)\Android\android-sdk\platforms\android-8\android.jar" --out=C:\Users\assrock\Documents\JavaBind\JavaBind\obj\Release\api.xml --ref=C:\Users\assrock\Documents\JavaBind\JavaBind\Jars\android-support-v4.jar Couldn't load class com/actionbarsherlock/internal/ActionBarSherlockNative$ActionModeCallbackWrapper Couldn't load class com/actionbarsherlock/internal/app/ActionBarWrapper$TabWrapper Couldn't load class com/actionbarsherlock/internal/app/ActionBarWrapper Couldn't load class com/actionbarsherlock/internal/view/ActionProviderWrapper Couldn't load class com/actionbarsherlock/internal/view/menu/MenuItemWrapper$1 Exception in thread "main" java.lang.NoClassDefFoundError: com/actionbarsherlock/R at java.lang.Class.getDeclaringClass(Native Method) at jar2xml.JavaClass.getConstructorParameterOffset(JavaClass.java:149) at jar2xml.JavaClass.appendCtor(JavaClass.java:138) at jar2xml.JavaClass.appendToDocument(JavaClass.java:462) at jar2xml.JavaPackage.appendToDocument(JavaPackage.java:66) at jar2xml.Start.main(Start.java:157) Caused by: java.lang.ClassNotFoundException: com.actionbarsherlock.R at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 6 more C:\Program Files (x86)\MSBuild\Novell\Xamarin.Android.Bindings.targets(170,5): error MSB6006: "java.exe" exited with code 1. Task "JarToXml" execution -- FAILED Done building target "ExportJarToXml" in project "C:\Users\assrock\Documents\JavaBind\JavaBind\JavaBind.csproj".-- FAILED Done building project "C:\Users\assrock\Documents\JavaBind\JavaBind\JavaBind.csproj".-- FAILED Build FAILED. Warnings: C:\Program Files (x86)\MSBuild\Novell\Xamarin.Android.Bindings.targets(40,11): warning MSB4011: There is a circular reference involving the import of file "c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.Targets". This file may have been imported more than once, or you may have attempted to import the main project file. All except the first instance of this file will be ignored. Errors: C:\Users\assrock\Documents\JavaBind\JavaBind\JavaBind.csproj (Build) -> C:\Program Files (x86)\MSBuild\Novell\Xamarin.Android.Bindings.targets (ExportJarToXml target) -> C:\Program Files (x86)\MSBuild\Novell\Xamarin.Android.Bindings.targets(170,5): error MSB6006: "java.exe" exited with code 1. 1 Warning(s) 1 Error(s) Time Elapsed 00:00:00.4730270 --------------------- Fertig --------------------- Build: 1 Fehler, 0 Warnungen 

对于android-support-v4.jar,我find了这些xml文件,并把它们放在Transforms目录下:

EnumFields.xml

 <enum-field-mappings> <mapping jni-class="android/support/v4/app/FragmentActivity$FragmentTag" clr-enum-type="Android.Support.V4.App.FragmentTagType"> <field jni-name="Fragment_id" clr-name="Id" value="1" /> <field jni-name="Fragment_name" clr-name="Name" value="0" /> <field jni-name="Fragment_tag" clr-name="Tag" value="2" /> </mapping> </enum-field-mappings> 

EnumMethods.xml

 <enum-method-mappings> <mapping jni-class="android/support/v4/app/Fragment$SavedState"> <method jni-name="writeToParcel" parameter="p1" clr-enum-type="Android.OS.ParcelableWriteFlags" /> <method jni-name="writeToParcel" parameter="flags" clr-enum-type="Android.OS.ParcelableWriteFlags" /> </mapping> </enum-method-mappings> 

metadata.xml中

 <metadata> <remove-node path="/api/package[@name='android.support.v4.app']/class[@name='BackStackState']" /> <remove-node path="/api/package[@name='android.support.v4.app']/class[@name='FragmentState']" /> <remove-node path="/api/package[@name='android.support.v4.app']/class[@name='FragmentManagerState']" /> <remove-node path="/api/package[@name='android.support.v4.widget']/class[@name='CursorAdapter']/implements[@name='android.support.v4.widget.CursorFilter.CursorFilterClient']" /> <remove-node path="/api/package[@name='android.support.v4.widget']/class[@name='CursorAdapter']/field[@name='mCursorFilter']" /> <remove-node path="/api/package[@name='android.support.v4.content']/class[@name='AsyncTaskLoader.LoadTask']" /> <!-- FIXME: This method is an override of another method in the base types. The base method expects JLO, but this method returns Cursor. So we somehow have to fill the gap between them. --> <remove-node path="/api/package[@name='android.support.v4.content']/class[@name='CursorLoader']/method[@name='loadInBackground']" /> <remove-node path="/api/package[@name='android.support.v4.view.accessibility']/class[@name='AccessibilityNodeInfoCompat.AccessibilityNodeInfoIcsImpl']" /> <remove-node path="/api/package[@name='android.support.v4.widget']/class[@name='CursorAdapter.ChangeObserver']" /> <remove-node path="/api/package[@name='android.support.v4.view.accessibility']/class[@name='AccessibilityNodeInfoCompat.AccessibilityNodeInfoIcsImpl']" /> <remove-node path="/api/package[@name='android.support.v4.view.accessibility']/class[@name='AccessibilityNodeInfoCompat.AccessibilityNodeInfoStubImpl']" /> <remove-node path="/api/package[@name='android.support.v4.view']/interface[@name='ViewPager.OnAdapterChangeListener']" /> <attr path="/api/package[@name='android.support.v4.app']/class[@name='LoaderManager']/method[@name='initLoader']/parameter[@name='p2']" name="type">android.support.v4.app.LoaderManager.LoaderCallbacks</attr> <attr path="/api/package[@name='android.support.v4.app']/class[@name='LoaderManager']/method[@name='initLoader']/parameter[@name='callback']" name="type">android.support.v4.app.LoaderManager.LoaderCallbacks</attr> <attr path="/api/package[@name='android.support.v4.app']/class[@name='LoaderManager']/method[@name='initLoader']" name="return">android.support.v4.content.Loader</attr> <attr path="/api/package[@name='android.support.v4.app']/class[@name='LoaderManager']/method[@name='restartLoader']/parameter[@name='p2']" name="type">android.support.v4.app.LoaderManager.LoaderCallbacks</attr> <attr path="/api/package[@name='android.support.v4.app']/class[@name='LoaderManager']/method[@name='restartLoader']/parameter[@name='callback']" name="type">android.support.v4.app.LoaderManager.LoaderCallbacks</attr> <attr path="/api/package[@name='android.support.v4.app']/class[@name='LoaderManager']/method[@name='restartLoader']" name="return">android.support.v4.content.Loader</attr> </metadata> 

Solutions Collecting From Web of "ActionBarSherlock for Mono for Android的jar-Binding"

ActionBarSherlock包含UI元素,样式和其他不能被编译成JAR文件的东西。 在ActionBarSherlock常见问题解答中有关于此的说明。

问:为什么ActionBarSherlock是一个库项目,而原来的兼容性库只是一个.jar?

答:ActionBarSherlock中的自定义操作栏实现依赖于样式,主题,布局和可绘制以正确显示。 由于Android和.jar文件的限制,目前无法以其他方式完成。

编辑:有一些额外的信息关于尝试共享资源在Android单声道在图书馆项目在这个链接: http : //mono-for-android.1047100.n5.nabble.com/Resources-from-a-Library-Project -td4657828.html 。 简短的回答是目前看起来不可能。

我相信我已经成功绑定在Android单声道的ActionBarSherlock。

您需要将java文件打包为JAR文件,但没有资源,也没有R java类文件。 在打包文件之前,请确保在Android设置中选中了“Is Library”,这样资源ID就不会被创build为常量,并且在已编译的Java类中被内联。

完成此操作后,可以使用最新版本的Mono for Android来绑定JAR文件。

资源需要与JAR文件分开复制,并直接放置在主要的android应用程序项目中。 不幸的是,在使用Mono for Android时,目前没有办法在独立的图书馆项目中分离资源,但我预计这种情况很快就会改变。

最后,您需要编辑C-Sharp项目文件,以便每次重build时自动创build新版本的com.actionbarsherlock.R java类文件。 这是保持所有资源ID同步所必需的。

我可能已经错过了一两步,但这些是最重要的。

请参阅我的博客文章,了解更多信息和下载链接的源代码:

http://www.craigsprogramming.com/2012/07/actionbarsherlock-with-mono-for-android.html

这可能看起来像一个大锤的做法,但可能会解决你的问题…

我会build议使用Maven构build,这更好地处理这些依赖关系。 您将能够在您的POM中引用ActionBarSherlock项目,而MVN将为您pipe理依赖关系。

我可以确认原始答案是否正确 – 包含包含布局资源的JAR文件是有限制的。

看起来像Xamarin解决了ActionBarSherlock绑定的问题

https://bugzilla.xamarin.com/show_bug.cgi?id=6186

此修正已包含在4.2.5中,现在可在alpha通道上使用。