Open
Description
Android framework version
net9.0-android
Affected platform version
VS Enterprise 2022 17.12.4, .NET 9.0.102,
Description
I have kotlin code that needs androidx.compose.ui to work.
I build an android library from this kotlin code, then import it in an Android Binding Library in VS, and I add the dependencies in the .csproj,
with notably
<PackageReference Include="Xamarin.AndroidX.Compose.UI.Android" Version="1.7.6.1" />
among a lot of other packages
I then import this library in a MAUI application, and when launching a ComponentActivity, there is a runtime error
Java.Lang.NoClassDefFoundError: 'Failed resolution of: Landroidx/compose/ui/platform/ComposeView;'
Steps to Reproduce
- create a new android studio project
- add an android library module
- create a custom class extending ComponentActivity()
- in setContentView, add a ComposeView
- add a composable in the content
open class ExampleActivity : ComponentActivity() {
@Composable
fun Greeting(name: String) {
Text(text = "Hello $name!")
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(
ComposeView(this).apply {
setContent {
MaterialTheme {
Greeting(name = "compose")
}
}
}
)
}
}
- build the library
- create a new Android Binding Library in VS
- add the .AAR
- add all xamarin.androix dependencies
<PackageReference Include="Xamarin.AndroidX.Activity" Version="1.10.0" />
<PackageReference Include="Xamarin.AndroidX.Activity.Compose" Version="1.10.0" />
<PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.10.0" />
<PackageReference Include="Xamarin.AndroidX.Annotation" Version="1.9.1.2" />
<PackageReference Include="Xamarin.AndroidX.Annotation.Experimental" Version="1.4.1.8" />
<PackageReference Include="Xamarin.AndroidX.Annotation.Jvm" Version="1.9.1.2" />
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.7.0.5" />
<PackageReference Include="Xamarin.AndroidX.Collection.Jvm" Version="1.4.5.2" />
<PackageReference Include="Xamarin.AndroidX.Compose.Foundation" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.Material3" Version="1.3.1.2" />
<PackageReference Include="Xamarin.AndroidX.Compose.Material3Android" Version="1.3.1.2" />
<PackageReference Include="Xamarin.AndroidX.Compose.Runtime" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.Runtime.Android" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.Runtime.LiveData" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.Runtime.RxJava2" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.Runtime.RxJava3" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.Runtime.Saveable" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.Runtime.Saveable.Android" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.UI.Android" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.UI.Geometry" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.UI.Geometry.Android" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.UI.Graphics" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.UI.Graphics.Android" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.UI.Text" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.UI.Text.Android" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.UI.Unit" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.UI.Unit.Android" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.UI.Util" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Compose.UI.Util.Android" Version="1.7.6.1" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Runtime.Compose" Version="2.8.7.2" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Runtime.Compose.Android" Version="2.8.7.2" />
<PackageReference Include="Xamarin.Jetbrains.Annotations" Version="26.0.1.2" />
<PackageReference Include="Xamarin.Kotlin.StdLib" Version="2.0.21.2" />
<PackageReference Include="Xamarin.Kotlin.StdLib.Common" Version="2.0.21.2" />
<PackageReference Include="Xamarin.Kotlin.StdLib.Jdk7" Version="2.0.21.2" />
<PackageReference Include="Xamarin.Kotlin.StdLib.Jdk8" Version="2.0.21.2" />
<PackageReference Include="Xamarin.KotlinX.Coroutines.Android" Version="1.9.0.2" />
<PackageReference Include="Xamarin.KotlinX.Coroutines.Core" Version="1.9.0.2" />
<PackageReference Include="Xamarin.KotlinX.Coroutines.Core.Jvm" Version="1.9.0.2" />
<PackageReference Include="Xamarin.AndroidX.Compose.UI" Version="1.7.6.1" />
- build the library
- create a new MAUI application
- add a reference to the Binding Library
- launch the custom activity, with for example a button
public static void StartComposeActivity(Context context, string param)
{
var intent = new Intent(
context,
typeof(Com.Example.Composebind.ExampleActivity));
//intent.PutExtra("param", param);
context.StartActivity(intent);
}
and
private void OpenCompose_Clicked(object sender, EventArgs e)
{
#if ANDROID
if (Platform.CurrentActivity is MainActivity mainActivity)
{
MainActivity.StartComposeActivity(mainActivity, "test");
}
#endif
}
and
<Button
Text="Open Compose"
Clicked="OpenCompose_Clicked"/>
- admire the crash

Did you find any workaround?
no :(