I recently started working on MAUI Android binding library. I have created an aar file which has a simple Kotlin class and an Interface. This interface is implemented by the Kotlin class.
The simple Kotlin class
package
package com.app.mauitestlib
import android.util.Log
class MauiLibTest: MauiTestListener {
fun start(initKey: String) {
Log.d("MauiTest", "start called: ")
}
override fun onInit() {
Log.d("MauiTest", "onInit")
}
}
package
The simple Kotlin Interface
package com.app.mauitestlib
interface MauiTestListener {
fun onInit()
}
Using Android Studio, I have generated mauitestlib-release.aar file. My requirement is to bind the aar file generated to MAUI library using net8.0-android
target framework. I have the following setup for MAUI library
The wfx-maui-test.csproj looks like this.
<Project Sdk="Microsoft.NET.Sdk">
To build this library, I run the following commands,
dotnet clean wfx-maui-test.csproj
dotnet restore wfx-maui-test.csproj
dotnet build -c Release
This generates dll files without any error, but when i publish the library to nuget as library and use it in a MAUI Android project. It fails the following error.
obj/Debug/net8.0-android/android/src/mono/com/app/mauitestlib/MauiTestListenerImplementor.java(8,22): javac error JAVAC0000: error: package com.app.mauitestlib does not exist
Upon debugging, I found that a cs file name Com.App.Mauitestlib.IMauiTestListener.cs
is generated which has the below code.
[global::Android.Runtime.Register ("mono/com/app/mauitestlib/MauiTestListenerImplementor")]
internal sealed partial class IMauiTestListenerImplementor : global::Java.Lang.Object, IMauiTestListener {
}
This is internally registering java file name MauiTestListenerImplementor.java under the package mono/com/app/mauitestlib
which is causing the issue.
How i make sure that the file is not registered under mono/com/app/mauitestlib
package?
How can i make my maui library work with aar file that has Kotlin/Java interface?