简体   繁体   中英

How can i downgrade the gradle on project kotlin multiplatform to use a Android Studio Stable version?

Recently i started to work on a kotlin multiplatform project, i did not have any previous experience when i started, and i got the project with its base already created. The developer that create the project had the ideia to use the compose library on android development part. Then he quit the job, and i started in it. But i choose to not use compose because of the rush on deliver the application.

So the project gradle version is currently on 6.8 and android plugin on 7.0.0-alpha05 but i want to downgrade to stop to use the Android Studio on Canary version, and use on a stable version. But when i downgrade the gradle i am getting this error:

A problem occurred configuring project ':shared'.
> Failed to notify project evaluation listener.
   > /Users/jhonata/Documents/Projetos/Aurea/quicktendr-mgmt/shared/src/main/AndroidManifest.xml (No such file or directory)

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':shared'.
    at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:75)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:68)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.access$400(LifecycleProjectEvaluator.java:51)
    at org.gradle.configuration.project.LifecycleProjectEvaluator$NotifyAfterEvaluate.run(LifecycleProjectEvaluator.java:191)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
    at ...

gradle properties:

distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

shared gradle:

import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("kotlin-parcelize")
    id("dev.icerock.mobile.multiplatform-resources")
    kotlin("plugin.serialization")
}
android {
    configurations {
        create("androidTestApi")
        create("androidTestDebugApi")
        create("androidTestReleaseApi")
        create("testApi")
        create("testDebugApi")
        create("testReleaseApi")
    }
}

kotlin {
//    jvm()
    android()
    ios {
        binaries {
            framework {
                baseName = "shared"
                when (val target = this.compilation.target.name) {
                    "iosX64" -> {
                        export(Deps.Decompose.iosX64)
                    }

                    "iosArm64" -> {
                        export(Deps.Decompose.iosArm64)
                    }

                    else -> error("Unsupported target: $target")
                }
            }
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                api(Deps.Decompose.decompose)
                api(Deps.coroutines)
                implementation(Deps.ktxSerializationJson)
                implementation(Deps.ktorCore)
                implementation(Deps.ktorSerialization)
                implementation(Deps.kissMeCommon)
                implementation("ch.qos.logback:logback-classic:1.2.3")
                implementation("dev.icerock.moko:mvvm-core:0.10.1")
                implementation("dev.icerock.moko:mvvm-livedata:0.10.1")
                api("dev.icerock.moko:resources:0.15.1")
                api("dev.icerock.moko:mvvm:0.9.1")
                implementation("io.ktor:ktor-client-logging:1.4.2")
                implementation("io.ktor:ktor-client-auth:1.4.2")
            }
        }

        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }

//        val mobileMain by creating {
//            dependsOn(commonMain)
//            dependencies {
//
//            }
//        }

        val androidMain by getting {
            dependencies {
                implementation(Deps.ktorAndroid)
                implementation(Deps.kissMeAndroid)
            }
        }
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13")
            }
        }
        val iosMain by getting {
            dependencies {
                implementation(Deps.ktorIOS)
                implementation(Deps.kissMeIOS)
            }
        }
        val iosTest by getting
//        val jvmMain by getting {
//            dependencies {
//                implementation("io.ktor:ktor-client-okhttp:1.4.2")
//            }
//        }

        named("iosX64Main") {
            dependencies {
                api(Deps.Decompose.iosX64)
            }
        }

        named("iosArm64Main") {
            dependencies {
                api(Deps.Decompose.iosArm64)
            }
        }
    }
}

multiplatformResources {
    multiplatformResourcesPackage = "com.quicktendr.mgmt" // required
    iosBaseLocalizationRegion = "es" // optional, default "en"
}

android {
    compileSdkVersion(29)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(24)
        targetSdkVersion(29)
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

val packForXcode by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
    val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
    val framework =
        kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val targetDir = File(buildDir, "xcode-frameworks")
    from({ framework.outputDirectory })
    into(targetDir)
}

tasks.getByName("build").dependsOn(packForXcode)

gradle:

buildscript {
    repositories {
        gradlePluginPortal()
        jcenter()
        google()
        mavenCentral()
        maven("https://kotlin.bintray.com/kotlinx")
        maven("https://dl.bintray.com/jetbrains/kotlin-native-dependencies")
        maven("https://dl.bintray.com/kotlin/kotlin-dev")
        maven("https://dl.bintray.com/icerockdev/plugins")
    }
    dependencies {
        val kotlinVersion = "1.4.31"
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
        classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
        classpath("com.android.tools.build:gradle:4.2.1")
        classpath("com.github.jengelman.gradle.plugins:shadow:5.2.0")
        classpath("dev.icerock.moko:resources-generator:0.15.1")
        classpath("com.google.gms:google-services:4.3.5")
        classpath("com.google.firebase:firebase-crashlytics-gradle:2.5.2")
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven("https://dl.bintray.com/arkivanov/maven")
        maven("https://dl.bintray.com/icerockdev/moko")
        maven("https://dl.bintray.com/netguru/maven/")
        maven("https://repo.repsy.io/mvn/chrynan/public")
        maven("https://jitpack.io")
    }
}

If you just want to downgrade gradle, you can downgrade gradle in the gradle properties file which you posted.

distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

You would need to set this to the latest version supported by Android Studio 4.2.1. There are also compatibility considerations with the Android gradle plugin. You can see a compatibility matrix for that here:

https://developer.android.com/studio/releases/gradle-plugin#4-2-0

Please be aware that if your project was using things like compose which relied on particular versions of AGP/Gradle, you might need to rewrite those pieces. It is okay to use the canary versions of android studio or recent versions of intellij - unless you are hitting some issue. You can use compose and old view classes together using AndroidView

https://developer.android.com/jetpack/compose/interop/interop-apis#views-in-compose

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM