dotnet / dotnet/android-libraries

MAUI app cannot resolve androidx.compose.ui.platform.ComposeView from Android Binding Library

Open
#1,090 10 comments 0 reactions 1 assignee Claimed by @moljac View on GitHub
binding-issue missing-api
Dominant language
C#
Stars
317
Forks
73
Avg merge
1d 8h
Merged PRs (30d)
17

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
```

```
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;'
```

see also https://stackoverflow.com/questions/79421004/maui-java-class-resolution-fails-even-with-dependencie-added

### Steps to Reproduce

1. create a new android studio project
2. add an android library module
3. create a custom class extending ComponentActivity()
4. in setContentView, add a ComposeView
5. add a composable in the content

```kotlin
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")
}
}
}
)
}
}
```

6. build the library
7. create a new Android Binding Library in VS
8. add the .AAR
9. add all xamarin.androix dependencies

```xml

```

10. build the library
11. create a new MAUI application
12. add a reference to the Binding Library
13. launch the custom activity, with for example a button
```cs
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
```cs
private void OpenCompose_Clicked(object sender, EventArgs e)
{
#if ANDROID
if (Platform.CurrentActivity is MainActivity mainActivity)
{
MainActivity.StartComposeActivity(mainActivity, "test");
}
#endif
}
```

and

```cs

```

14. admire the crash

Image

### Did you find any workaround?

no :(

### Relevant log output

```shell

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.