Gradle plugins for embedding C# in an Android app.
- Android Studio
- Visual Studio for Mac
Currently working for:
=== Visual Studio Community 2019 for Mac ===
Version 8.10.6 (build 10)
=== Mono Framework MDK ===
Runtime:
Mono 6.12.0.140 (2020-02/51d876a041e) (64-bit)
Package version: 612000140
=== Xamarin.Android ===
Version: 11.3.0.4
Commit: xamarin-android/d16-10/ae14caf
Android SDK:
Supported Android versions:
4.4 (API level 19)
5.0 (API level 21)
5.1 (API level 22)
6.0 (API level 23)
8.0 (API level 26)
8.1 (API level 27)
SDK Tools Version: 26.1.1
SDK Platform Tools Version: 31.0.3
SDK Build Tools Version: 31.0.0
Build Information:
Mono: b4a3858
Java.Interop: xamarin/java.interop/d16-10@f39db25
ProGuard: Guardsquare/proguard/v7.0.1@912d149
SQLite: xamarin/sqlite/3.35.4@85460d3
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-10@c5732a0
=== Operating System ===
Mac OS X 10.16.0
Darwin 20.6.0 Darwin Kernel Version 20.6.0
Mon Aug 30 06:12:21 PDT 2021
root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64
- Clone this repo.
- Open the test Android project in Android Studio.
- Run the app.
- Clone this repo.
- Create an Android app in a sibling directory.
- Create a Visual Studio Android library project in a sibling directory.
- Configure the Visual Studio project. See test library settings.
- Include the plugins project in the Android project
settings.gradle
. See test app settings.
includeBuild '../../'
- Apply the app plugin in the app
build.gradle
and the library plugin in thebuild.gradle
of the module that will use C# (perhaps the appbuild.gradle
in a small app). See test app configuration.
apply plugin: 'com.roy.dot-net-embed-app'
apply plugin: 'com.roy.dot-net-embed-library'
- Configure the
dotNet
extension in thebuild.gradle
where the library plugin is applied. See test app configuration.
dotNet {
pluginLogLevel LogLevel.LIFECYCLE
projectFile "../../dot-net/DotNetLibrary/DotNetLibrary.csproj"
solutionFile "../../dot-net/DotNet.sln"
buildTypes {
debug {
msBuildConfig "Debug"
}
release {
msBuildConfig "Release"
}
}
}
- Add the Mono Runtime content provider to
AndroidManifest.xml
in the Android projectapplication
element to initialize Mono on startup. Get this fromobj/debug/android/AndroidManifest.xml
after building the C# project.
<provider
android:name="mono.MonoRuntimeProvider"
android:authorities="com.roy.dotnetlibrary.mono.MonoRuntimeProvider.__mono_init__"
android:exported="false"
android:initOrder="1999999999" />
- Create C# classes extending
Java.Lang.Object
, applying theExport
andRegister
attributes. See an example. - Run Gradle task
:app:compileDebugDotNet
to create the Android Callable Wrappers that will be visible in Android Studio. - Utilize the Android Callable Wrappers in Java or Kotlin.
- Run the app!