Unable to import Content Negotiation and Serializable imports in kotlin Android Studio

32 Views Asked by At

I am creating an app on andoird studio and I need to be able to do JSON serialization.However , I am not able to use imports such as

import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.serialization.kotlinx.json.*

etc even though I have added the required dependencies.

This is my project level gradle

import com.android.build.gradle.AppExtension
import com.android.build.gradle.internal.crash.afterEvaluate

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:8.1.4")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22")
        classpath("com.google.gms:google-services:4.4.1")
        val kotlinVersion = "1.9.22"
        classpath(kotlin("serialization", version = kotlinVersion))
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
    // Add the following code to ensure namespace is set for all Android modules
    subprojects {
        afterEvaluate { project ->
            if (project.hasProperty("android")) {
                (project.extensions.getByType(AppExtension::class.java) as AppExtension).run {
                    if (namespace == null) {
                        namespace = project.group as String
                    }
                }
            }
        }
    }
}

rootProject.buildDir = file("../build")
subprojects {
    project.buildDir = file("${rootProject.buildDir}/${project.name}")
}
tasks.register("clean") {
    doLast {
        delete(rootProject.buildDir)
    }
}

and this is my module level gradle

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("com.google.gms.google-services")
    id("kotlinx-serialization")
}

android {
    namespace = "com.example.prosubscriberapp"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.example.prosubscriberapp"
        minSdk = 26
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary = true
        }
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.5.1"
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}

val exposedLibraryVersion: String by project
val h2LibraryVersion: String by project

dependencies {

    implementation("androidx.core:core-ktx:1.12.0")
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
    implementation("androidx.activity:activity-compose:1.8.2")
    implementation(platform("androidx.compose:compose-bom:2023.08.00"))
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-graphics")
    implementation("androidx.compose.ui:ui-tooling-preview")
    implementation("androidx.compose.material3:material3")
    implementation ("io.ktor:ktor-server-netty:2.3.7")
    implementation ("io.ktor:ktor-serialization:2.3.7")
    implementation ("mysql:mysql-connector-java:8.0.23")
    implementation("io.ktor:ktor-jackson:1.6.5")
    implementation ("io.ktor:ktor-server-core:2.3.7")
    implementation ("io.ktor:ktor-server-netty:2.3.7")
    implementation ("io.ktor:ktor-gson:2.3.7")
    implementation ("io.ktor:ktor-server-core:2.3.7")
    implementation ("io.ktor:ktor-server-netty:2.3.7")
    implementation ("io.ktor:ktor-locations:2.3.7")
    implementation ("io.ktor:ktor-features:2.3.7")
    implementation("com.google.apis:google-api-services-gmail:v1-rev110-1.31.0")
    implementation("com.google.api-client:google-api-client:1.31.0")
    implementation("com.google.oauth-client:google-oauth-client-jetty:1.31.0")
    implementation("com.google.apis:google-api-services-gmail:v1-rev110-1.31.0")
    implementation ("io.ktor:ktor-gson:1.7.4")
    implementation ("javax.sql:javax.sql-api:2.0.1")
    implementation ("org.jetbrains.exposed:exposed:0.33.2")
    implementation ("org.jetbrains.exposed:exposed-java-time:0.36.2")
    implementation("org.jetbrains.exposed:exposed-java-time:0.36.2")
    implementation("com.google.firebase:proto-lite-well-known-types:18.0.0")
    implementation ("mysql:mysql-connector-java:8.0.23")
    implementation ("org.jetbrains.exposed:exposed-core:0.41.1")
    implementation ("org.jetbrains.exposed:exposed-dao:0.41.1")
    implementation ("org.jetbrains.exposed:exposed-jdbc:0.41.1")
    implementation ("org.jetbrains.exposed:exposed:0.33.2")
    implementation ("org.jetbrains.exposed:exposed-java-time:0.36.2")
    implementation("org.jetbrains.exposed:exposed-java-time:0.36.2")
    implementation ("org.jetbrains.exposed:exposed-java-time:0.36.2")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.22")
    implementation("org.jetbrains.exposed:exposed-core:0.41.1")
    implementation("org.jetbrains.exposed:exposed-dao:0.41.1")
    implementation("org.jetbrains.exposed:exposed-jdbc:0.41.1")
    implementation("org.jetbrains.exposed:exposed-java-time:0.36.2")
    implementation("org.jetbrains.exposed:exposed-core:0.41.1")
    implementation("org.jetbrains.exposed:exposed-dao:0.41.1")
    implementation("org.jetbrains.exposed:exposed-jdbc:0.41.1")
    implementation("mysql:mysql-connector-java:8.0.23")
    implementation("com.h2database:h2:2.1.214")
    implementation("com.jakewharton.threetenabp:threetenabp:1.3.7")
    implementation ("org.jetbrains.kotlinx:kotlinx-serialization-core:1.6.3")
    implementation("org.apache.mahout:mahout-math:0.13.0")
    implementation("org.apache.mahout:mahout-cf:0.14.0")
    implementation ("org.apache.commons:commons-lang3:3.12.0")
    implementation("org.apache.mahout:mahout-cf:0.14.0") // Adjust the version according to your Mahout version
    implementation ("org.apache.commons:commons-lang3:3.12.0")
    implementation ("org.apache.commons:commons-text:1.9")
    implementation ("io.github.pickle4j:pickle4j:1.3.0")
    implementation ("org.apache.mahout:mahout-cf:0.14.0")
    implementation ("org.apache.commons:commons-csv:1.8")
    implementation ("io.reactivex.rxjava3:rxjava:3.0.0")
    implementation ("io.reactivex.rxjava3:rxandroid:3.0.0")
    implementation ("commons-io:commons-io:2.11.0")
    implementation("io.ktor:ktor-client-core:1.7.4")
    implementation("io.ktor:ktor-client-json-jvm:1.7.4")
    implementation("io.ktor:ktor-client-serialization-jvm:1.9.22")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
    implementation("io.ktor:ktor-client-content-negotiation:1.9.22")
    implementation("io.ktor:ktor-serialization-kotlinx-json:1.9.22")
    implementation(platform("com.google.firebase:firebase-bom:32.7.2"))
    implementation("com.google.firebase:firebase-analytics")
    implementation("com.google.firebase:firebase-messaging:23.4.1")
    implementation("io.ktor:ktor-server-core-jvm:2.3.7")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
    androidTestImplementation("androidx.compose.ui:ui-test-junit4")
    debugImplementation("androidx.compose.ui:ui-tooling")
    debugImplementation("androidx.compose.ui:ui-test-manifest")

}

I am basically unable to install the kotlinx-serialization-json library and I dont know why.Please Help

0

There are 0 best solutions below