androidandroid-jetpack-composeandroid-jetpack-compose-material3

Duplicate Classes Error when running application in android jetpack compose


My build always succeeds (The one needed for the preview) but when I run the emulator it gives me a duplicate class error in the first 300 ms. This is my first app which I am making by following a tutorial, so naturally I have basically no idea about dependencies.

The actual error information is like 100 lines long so here is a line:

Duplicate class com.google.android.engage.video.datamodel.RecommendationReasonWatchAgain found in modules engage-core-1.5.8.aar -> engage-core-1.5.8-runtime (com.google.android.engage:engage-core:1.5.8) and engage-tv-1.0.3.aar -> engage-tv-1.0.3-runtime (com.google.android.engage:engage-tv:1.0.3)

In all the lines, the only thing different is the class name (com.google.android.engage.video.datamodel.RecommendationReasonWatchAgain) in this case.

Also, here is another part of the error:

Task :app:checkDebugDuplicateClasses FAILED

And here is my code: package com.example.jetbizcard

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.jetbizcard.ui.theme.JetBizCardTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            JetBizCardTheme {
                Surface(color= MaterialTheme.colorScheme.background) {
                    CreateBizCard()
                }
            }
        }
    }
}


@Composable
fun CreateBizCard() {
    Surface(modifier = Modifier.fillMaxSize().fillMaxHeight()) {
        Card(modifier = Modifier.width(200.dp)
            .height(390.dp)
            .padding(12.dp),
            elevation=CardDefaults.cardElevation(defaultElevation = 5.dp),
            shape=RoundedCornerShape(corner = CornerSize(15.dp)),
            colors=CardDefaults.cardColors(
                containerColor = Color.White
            )
        ) {
            Column(modifier=Modifier
                .height(300.dp)
                .width(390.dp)
                .padding(top=10.dp),
                verticalArrangement = Arrangement.Top,
                horizontalAlignment = Alignment.CenterHorizontally) {
                CreateProfileImage()

                HorizontalDivider(Modifier
                    .alpha(0.4f)
                    .padding(top=10.dp),
                    color=Color.LightGray,
                    thickness = 2.dp)

                Column(modifier= Modifier.padding(10.dp)) {
                    Text(
                        text = "Miles P.",
                        modifier = Modifier
                            .padding(3.dp),
                        color = MaterialTheme.colorScheme.primary,
                        fontSize = 40.sp,
                    )

                    Text(
                        text = "Android Compose Programmer",
                        modifier = Modifier
                            .padding(3.dp)
                    )

                    Text(
                        text = "@theMilesCompose",
                        modifier = Modifier
                            .padding(3.dp),
                        style = MaterialTheme.typography.titleSmall
                    )
                }
            }


        }
    }

}

@Composable
fun CreateProfileImage(modifier: Modifier = Modifier) {
    Surface(
        modifier = Modifier
            .size(150.dp)
            .padding(5.dp),
        shape = CircleShape,
        border = BorderStroke(1.dp, Color.LightGray),
        shadowElevation = 4.dp,
        color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.5f)
    ) {
        Image(
            painter = painterResource(R.drawable.profile_image),
            contentDescription = "profile image",
            modifier = Modifier.size(135.dp),
            contentScale = ContentScale.Crop
        )
    }
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    JetBizCardTheme {
        CreateBizCard()
    }
}

I tried removing a few things to create something like an MRE. If any other information is needed I can give it to you.

And also, just in case this is a screenshot of the preview of the app: enter image description here


Solution

  • I found the problem, the problem was in my build.gradle.kts where both libs.engage.tv and libs.engage.core where in the dependancy block, I then just commented out the

    implementation(libs.engage.tv)
    

    which worked!