Libraries in Xamarin.Android land Android Native Stack (kernel, libc, opengl, android fx etc.) Android Fx Java API Dalvik/ART VM libmonodroid Mono.Android API Other Java Libs System* OpenTK Other .NET Libs Java Bindings
[補] *.jar + res/* Doable only for Java libraries that don't have res/* .jar doesn't contain res/* ! ResourceNotFoundException if you do this regardless. Build Item Type: mostly EmbeddedJar
[補] Android Library Project Outcome Android Library Project... built with ant or Eclipse ADT (!) Add its build results as the target (bound) Java library. Two approaches to achieve that: 1) project.properties : LibraryProjectProperties build item created by "android update project -p ." add it ONLY AFTER you built it (ant debug)
[補] Android Library Project Outcome 2) *.zip: LibraryProjectZip build item Archive the OUTCOME of the build. a bit messier to build compared to C1), but you can distribute it in your project. (i.e. your library users don't have to build it.) (Gradle? ... expect those libs to create .aar)
[補] Build Item Type Details EmbeddedJar You'd mostly like to use it. C# API is generated for this, and the jar is embedded in the dll. EmbeddedReferenceJar NO C# API is generated, but it is embedded in the dll. Useful for jar dependencies.
[補] Build Item Type Details InputJar C# API is generated for this, but the .jar is NOT embedded in the dll. Useful for Manifest element based Java libs, or libraries that you cannot freely distribute by embedding to the .dll. Old Google Maps used it. Kindle libraries can be this too. ReferenceJar neither (useful under very limited situation e.g. java dependencies when generating "ACW")
[補] Library Reference via Web [assembly:Java.Interop.JavaLibraryReference] [assembly:Android.IncludeAndroidResourcesFrom] [assembly:Android.NativeLibraryReference] They are used to download dependencies when resolving Java libraries from . dll. Not (well) documented yet. Xamarin uses it for GooglePlayServices binding.
[補] XA Android Library (which is very different from Binding Library...) You can also embed .jars and res/* in XA (non-binding) Library project. ● AndroidJavaLibrary ● AndroidExternalJavaLibrary (referenced when compiling sources, but NOT embedded in the final .apk) ● AndroidResource, AndroidAsset
Fix Inconsistent Type Access 対策1: public 余計なメンバーが別のビルドエラーを誘発する可能性はある 対策2: PublicAncestor (members in nonpublic class) これは祖先でも可。大概めんどくさい。 package android.app.backup; class FileBackupHelperBase { ... } public class FileBackupHelper extends FileBackupHelperBase
Fix Inconsistent Member Access 対策: protected C#でpublicにアクセスできなくなるが、.NETでは無理。Additionsで対応できる。 class Foo { protected void x () { ... } } class Foo { protected virtual void X () { ... } class Bar extends Foo { public void x () { ... } } class Bar : Foo { public override void X () { ... }
Dealing with Variants and Generics class Foo { public Object x () { ... } } class Foo { public virtual Object X () { ... } class Bar extends Foo { public Integer x () { ... } } class Bar : Foo { public override Integer X () { ... }
Dealing with Variants and Generics android.content.pm.ApplicationInfo.DisplayNameComparator implements java.util.Comparator class Comparator { abstract int compare (T t1, T t2); } class Comparator { int Compare (Object o1,Object o2); } class DisplayNameComparator { int compare (ApplicationInfo a1, ApplicationInfo a2) { ... } } class DisplayNameComparator { int compare (ApplicationInfo a1, ApplicationInfo a2) { ... } }
Property get/set Inconsistency set-only Base, get/set Derived ... 対策: name="generateDispatchingSetter">true public class Base { public void setXxx(int x) { ... } } public class Base { void SetXxx (int x) { ... } } public class Derived { public int getXxx() { ... } public void setXxx(int x) { ... } } public class Derived { public int Xxx { get { ... } set { ... } } }
Enums and Color Xamarin API: int → enum, int → Android.Graphics.Color 基本的にオーバーライドは検出できることになっている が、たまに検出しない場合がある (インターフェース メンバーがenum/Colorを使っている etc.) 対策: use managedType / managedReturn
Name Conflict by PascalCasing 対策: いずれかに "managedName" を適用 public class Foo { public final int FOO_BAR; public int getFooBar(); } public class Foo { public const int FooBar; public int FooBar { get; } }
[補] Packaging binding libraries NuGet common to other .NET profiles. you can publish as you'd like. Component Store needs to come up with docs and samples. needs approval by Xamarin.
[補] Binding feature history Mono.Android.dll etc. were from api.xml (using generator). api.xml was part of AOSP (Android Open Source Project). But it WASN'T at some stage - Honeycomb. So, we ended up to create jar2xml. We enhanced these tools to support any Java libraries.
[補] How it affected the product XA used to be like "For whatever .NET has better API, we offer them rather than binding Java API" ● e.g. no Java collections, no XML API, no apache http API etc. ● But w/o those we could not bind arbitrary API. ● So, ended up to bring (almost) everything. ● At the same time the API "got frozen" to be "stable". ● that causes several ugliness... (failed product strategy)