3

I've created a new Kotlin Multiplatform project for Andrid and iOS (Mobile shared Library). The project works fine but every time I run Gradle sync, it takes more than 5 minutes every time. It always get stuck on the same line:

Gradle: Build model 'org.jetbrains.kotlin.gradle.KotlinMPPGradleModel' for root project 'MyProject'

Why is it taking so long evey time?

I'm using Gradle version 5.1. Here is my build.gradle file:

buildscript {
    ext.kotlin_version = '1.3.11'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.8.1"
    }
}
plugins {
    id 'kotlin-multiplatform' version '1.3.11'
}
repositories {
    google()
    jcenter()
    mavenCentral()
    maven { url 'https://jitpack.io' }
}
repositories {
    mavenCentral()
}
group 'com.example'
version '0.0.1'

apply plugin: "com.android.library"
apply plugin: "com.jfrog.artifactory"
apply plugin: 'maven-publish'

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName version
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions.incremental = false
}

kotlin {
    targets {
        fromPreset(presets.android, 'android')
        // This preset is for iPhone emulator
        // Switch here to presets.iosArm64 to build library for iPhone device
        fromPreset(presets.iosX64, 'ios') {
            compilations.main.outputKinds('FRAMEWORK')
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
            }
        }
        commonTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test-common'
                implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
            }
        }
        androidMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib'
            }
        }
        androidTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test'
                implementation 'org.jetbrains.kotlin:kotlin-test-junit'
            }
        }
        iosMain {
        }
        iosTest {
        }
    }
}

configurations {
    compileClasspath
}

Screenshot of the problem:

enter image description here

4

3 回答 3

4

有一个已知问题,即每次同步都会重新获取 Kotlin/Native 依赖项,这可能就是您所看到的。您可以在此处查看详细信息并关注它。

正如该问题所发布的那样,您可以尝试一种解决方法,该解决方法基本上涉及添加{ content { excludeGroup("Kotlin/Native" } }repositories块中的每个项目。

于 2019-01-27T13:36:37.513 回答
1

正如@Brucelet 指出的,这是一个已知问题。为了补充他的答案,这里是解决方法的完整实现Groovy

repositories {
    mavenCentral().content() {
        excludeGroup "Kotlin/Native"
    }
    google().content() {
        excludeGroup "Kotlin/Native"
    }
    jcenter() {
        content {
            excludeGroup("Kotlin/Native")
        }
    }
    maven { 
        url 'https://jitpack.io'
        content {
            excludeGroup("Kotlin/Native")
        }
    }
}

并在Kotlin DSL

repositories {
        mavenLocal().apply {
            content {
                excludeGroup("Kotlin/Native")
            }
        }
        maven {
            url = uri("https://dl.bintray.com/soywiz/soywiz")
            content {
                includeGroup("com.soywiz")
                excludeGroup("Kotlin/Native")
            }
        }
        jcenter() {
            content {
                excludeGroup("Kotlin/Native")
            }
        }
        google().apply {
            content {
                excludeGroup("Kotlin/Native")
            }
        }
    }
于 2019-01-28T08:52:46.003 回答
0

尝试使用 --parallel 选项从命令行运行 Gradle 任务。

否则,请按照本指南来分析 Gradle 执行https://guides.gradle.org/performance/

于 2019-01-21T13:15:49.530 回答