Skip to content

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

Open
@TheFoxan12

Description

@TheFoxan12

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

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
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")
                    }
                }
            }
        )
    }
}
  1. build the library
  2. create a new Android Binding Library in VS
  3. add the .AAR
  4. 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" />
  1. build the library
  2. create a new MAUI application
  3. add a reference to the Binding Library
  4. 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"/>
  1. admire the crash
Image

Did you find any workaround?

no :(

Relevant log output

Metadata

Metadata

Assignees

Labels

binding-issueJava error when attempting to use bound type/methodmissing-apiJava types/members not available in binding

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions