0

最近我开始在一个 kotlin 多平台项目上工作,当我开始时我没有任何以前的经验,我得到的项目已经创建了它的基础。创建项目的开发人员有在 android 开发部分使用 compose 库的想法。然后他辞掉了工作,我开始了。但是我选择不使用 compose,因为交付应用程序很匆忙。

因此,项目 gradle 版本当前已启用6.8且 android 插件已启用,7.0.0-alpha05 但我想降级以停止在 Canary 版本上使用 Android Studio,并在稳定版本上使用。但是当我降级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 ...

梯度属性:

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

共享梯度:

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)

毕业典礼:

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")
    }
}
4

1 回答 1

0

如果您只想降级 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

您需要将其设置为 Android Studio 4.2.1 支持的最新版本。Android gradle 插件也有兼容性考虑。您可以在此处查看兼容性矩阵:

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

请注意,如果您的项目使用依赖于特定版本的 AGP/Gradle 的 compose,您可能需要重写这些部分。可以使用金丝雀版本的 android studio 或最新版本的 intellij - 除非您遇到问题。您可以使用组合和旧视图类一起使用AndroidView

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

于 2021-05-29T03:15:17.967 回答