简体   繁体   English

如何降级 kotlin 多平台项目上的 gradle 以使用 Android Studio 稳定版?

[英]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.最近我开始在一个 kotlin 多平台项目上工作,当我开始时我没有任何以前的经验,我得到的项目已经创建了它的基础。 The developer that create the project had the ideia to use the compose library on android development part.创建项目的开发人员有使用 android 开发部分上的 compose 库的想法。 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.但是我选择不使用 compose,因为交付应用程序很匆忙。

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.所以项目 gradle 版本目前在6.8和 android 插件在7.0.0-alpha05但我想降级以停止使用 Android 版本并使用稳定版 Canary 上的 Studio But when i downgrade the gradle i am getting this error:但是当我降级 gradle 时,我收到了这个错误:

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: gradle 属性:

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:共享 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: 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.如果您只想降级 gradle,您可以在您发布的 gradle 属性文件中降级 gradle。

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.您需要将其设置为 Android Studio 4.2.1 支持的最新版本。 There are also compatibility considerations with the Android gradle plugin.还有与 Android gradle 插件的兼容性考虑。 You can see a compatibility matrix for that here:您可以在此处查看兼容性矩阵:

https://developer.android.com/studio/releases/gradle-plugin#4-2-0 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.请注意,如果您的项目使用依赖于特定版本的 AGP/Gradle 的 compose,您可能需要重写这些部分。 It is okay to use the canary versions of android studio or recent versions of intellij - unless you are hitting some issue.可以使用 android studio 的金丝雀版本或最新版本的 intellij - 除非您遇到一些问题。 You can use compose and old view classes together using AndroidView您可以使用AndroidView一起使用撰写和旧视图类

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Studio:如何在 Kotlin 多平台共享模块 build.gradle.kts 中访问项目级 compileSdkVersion 和 targetSdkVersion? - Android Studio: How to access project level compileSdkVersion and targetSdkVersion in Kotlin Multiplatform shared module build.gradle.kts? 如何使 Kotlin Multiplatform 与 Android Studio 的项目视图一起使用? - How to make Kotlin Multiplatform work with Android Studio's project view? 当我无法使用 Gradle 时,如何在我的 Android Studio 项目中设置 Kotlin 编译器选项? - How can I set Kotlin compiler options in my Android Studio project, when I can't use Gradle? 无法降级Android Gradle插件版本 - Can't downgrade Android Gradle plugin version Jar 生产的 Kotlin 多平台库项目在 Android Studio 中不可见 - Jar produced by Kotlin Multiplatform Library project not visible in Android Studio Kotlin版本如何降级 - How to downgrade Kotlin version 我可以在 Gradle 插件中配置 Kotlin 多平台模块吗? - Can I configure a Kotlin Multiplatform module in a Gradle plugin? 我可以从 Android Studio IDE 查看 Kotlin Multiplatform 的 iOS 文档吗? - Can I view iOS documentation from Android Studio IDE for Kotlin Multiplatform? 如何在 Android Studio 中使用最新的 gradle 版本 - How to use the latest gradle version in Android Studio 如何在android studio中使用之前版本的gradle? - how to use the previous version of gradle in android studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM