platform in C# ◦ not for running .NET Fx apps on Android: No WPF, no Metro, no UWP • Reuse existing platform- independent .NET code • Take full advantage of IDE integration (out of scope for today)
apps for releases. ◦ No IDE support (no debugger UI, no UI designer, no profiler UI) • Part of "Open Sourced" Xamarin Platforms Mono Xamarin.Android Components MonoDevelop Xamarin Studio (MD Addins) XamarinVS Visual Studio
◦ no transpiler • provides Android API ◦ not just lang. runtime ◦ even Java.* API => we build and bundle mono (Not going to explain "how" within the session)
(Mono, part of XA) • PCLs (x-plat libs) (we can already build them) • Android API (part of XA) • Java Bindings ◦ build with XA • .NET Libs for XA ◦ build with XA
standard Android application ◦ Has AndroidManifest.xml, classes.dex, packaged resources... ◦ Launches within standard Android application loop (Zygote, ActivityThread, ...) • initializes mono runtime at startup, makes it possible to run MSIL code Everything is packaged within APK in Android manner.
• Android Gradle tasks extends it. • Android Studio integrates Gradle. Xamarin.Android SDK (.NET) • .NET uses MSBuild everywhere. • Xamarin.Android extends it. • Xamarin Studio and Visual Studio integrate MSBuild. ...so, you are supposed to understand How Android App Builds and Works... .., if you are really stuck at what's going on during builds.
Xamarin.Android - Fast Deployment Build (non-OSS) • builds APK, but it does not run by itself • needs separate dex uploads • reuses build cache as much as possible (Not for this session - it is NOT part of Xamarin.Android SDK)
Linux • broadband network for gigabytes of downloads • 13GB~ local storage There is no installable package for Linux yet. (There will be, depending on how Xamarin is serious about Linux...) You are supposed to build it by yourself. And there may be often broken builds yet (still early dev. stage)
• make prepare • make Checks out mono, fsharp, and all submodules Automatically downloads Android SDK & NDK Builds mono runtime * supported ABIs i.e. it takes forever to build(!)
and C includes. Skip them, not very important • lib ◦ mandroid - individual build tools and their deps used by MSBuild extensions. ◦ xbuild/Xamarin/Android - contains MSBuild extensions. ▪ lib/{arch} - contains NDK-built and host(Linux/Mac)-built mono and monodroid native libs. ◦ xbuild-frameworks/MonoAndroid ▪ v1.0 - System.* and co. • Facades, RedistList - PCL facades for XA ▪ v7.0 etc. - Mono.Android.dll etc., per API Level
has no IDE support... create project elsewhere (!) You need xabuild: xbuild (mono MSbuild) with required environment variables. $ xabuild [app.csproj] /t:SignAndroidPackage /p:Configuration=Release $ adb install bin/Release/{yourapp}.apk
API • JNI via P/Invoke Java->Mono • Android Framework only calls Java objects, so we need them • MSBuild tasks generate and package Java stubs in apk ◦ native methods invoke java-interop functions libmonodroid: App Bootstrap • mono <Provider> in AndroidManifest.xml
• also generates Mono.Android.dll • Can bind arbitrary Android libs (jar/aar) ◦ XamarinComponents • generated code makes use of JNIEnv class (Java Interop) generate Java API XML description use jar2xml (old) or class-parse (new) ↓ modify API by metadata fixup ↓ generator: parse API XML and generate C# ↓ compile C# (with jars embedded in DLL)
conform to Android standard ◦ remember original filenames • res/*/* => R.java ◦ using aapt (resource compiler in Android SDK) • R.java => Resource.Designer.cs (or .fs) ◦ Parse Java source with simple regex and get resource IDs ◦ restore original filenames to generate C#(F#) field identifiers • Then your code can use Resource.Id.YourButton
Release build assemblies should be as small as possible. • Remove unused code from DLLs using mark and sweep technique • /p:AndroidLinkMode=[SdkOnly|All] • We support proguard too ◦ xbuild /p:AndroidEnableProguard=True ◦ To shrink jars from binding AND shrink DLLs more. (proguard cfg generator as part of linker feature) Mono.Android.dll original 30MB App.dll uses these Mono.Android.dll shrunk, 3MB