Android Studio多模块项目Gradle同步失败

时间:2020-03-03 20:36:36

标签: android android-studio gradle kotlin intellij-idea

我正在创建一个包含应用程序模块,服务器模块和共享模块的多模块项目。当我在LetsGo根目录中运行./gradlew build时,它将返回而没有任何错误。 如果我在android studio中打开项目,但遇到一些奇怪的错误,并且由于不正确的同步,我的设计编辑器未显示任何内容。即使“同步”选项卡中的所有内容均显示为绿色的选中标记,它仍会吐出错误。我已经使缓存无效,但这无济于事。我正在尝试提供尽可能多的信息,因此下一部分可能会有点长。但是我想我按照最不相关的顺序对它们进行排序。

同步错误:

在LetsGo项目上:

Gradle Daemon started in 876 ms
<ij_msg_gr>Other<ij_msg_gr><ij_nav>/Users/koen/Vakken/Architecture_and_design/letsgo/LetsGo/app/build.gradle<ij_nav><i><b>project ':app': Unable to resolve all content root directories</b><eol>Details: java.lang.NullPointerException: null</i>
<ij_msg_gr>Tests model errors<ij_msg_gr><ij_nav>/Users/koen/Vakken/Architecture_and_design/letsgo/LetsGo/app/build.gradle<ij_nav><i><b>project ':app'</b><eol>Details: java.lang.NullPointerException: null</i>

CONFIGURE SUCCESSFUL in 9s

在项目:server上(即使我不认为这应该是另一个同步)

Task 'wrapper' not found in project ':server'.

错误日志位于https://pastebin.com/nq6HpmGi

在gradle.properties中,我设置了以下变量:

kotlin_version=1.3.61
gradle_version=3.6.1

./gradlew projects输出

Root project 'LetsGo'
+--- Project ':app'
+--- Project ':common'
\--- Project ':server'

我的gradle文件的快速转储:

settings.gradle

include ':app', ':common', ':server'
rootProject.name='LetsGo'

build.gradle

LetsGo

buildscript {
    ...

    dependencies {
        // Gradle/Kotlin Core
        classpath "com.android.tools.build:gradle:$gradle_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        ...
    }
}

allprojects {
    group 'com.kvw.letsgo'
    version '0.0.1'
    repositories {
        ...
    }
}

project(':app') {
    repositories {
        ...
    }
}

project(':server'){
    repositories {
        ...
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

:服务器

plugins{
    id 'kotlin'
    id 'application'
    ...
}

mainClassName = "io.ktor.server.netty.EngineMain"

sourceSets {
    main.kotlin.srcDirs = main.java.srcDirs = ['src']
    test.kotlin.srcDirs = test.java.srcDirs = ['test']
    main.resources.srcDirs = ['resources']
    test.resources.srcDirs = ['testresources']
}

dependencies {
    implementation project(':common')
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    ...
}

:app

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    ...
}

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.kvw.letsgo.client"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        ...
    }
    ...
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }

    ...
}

dependencies {
    // Local
    implementation project(':common')
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    ...
}

最后,为了完整起见,这是tree LetsGo -L 2

的输出
LetsGo
├── LetsGo.iml
├── app
│   ├── app.iml
│   ├── build
│   ├── build.gradle
│   ├── libs
│   ├── proguard-rules.pro
│   └── src
├── build
│   ├── intermediates
│   └── kotlin
├── build.gradle
├── common
│   ├── build
│   ├── build.gradle
│   ├── common.iml
│   ├── libs
│   └── src
├── gradle
│   └── wrapper
├── gradle.properties
├── gradlew
├── gradlew.bat
├── local.properties
├── server
│   ├── build
│   ├── build.gradle
│   ├── resources
│   ├── server.iml
│   ├── src
│   └── test
├── settings.gradle
└── versions.gradle

0 个答案:

没有答案