Android Studio 2.1.3 - DefaultSourceDirectorySet 问题 [英] Android Studio 2.1.3 - DefaultSourceDirectorySet issue

查看:33
本文介绍了Android Studio 2.1.3 - DefaultSourceDirectorySet 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天早上从 2.1.2 -> 2.1.3 更新了 Android Studio,并收到以下 gradle 同步错误:

Updated Android Studio from 2.1.2 -> 2.1.3 this morning and receiving the following gradle sync error:

错误:无法找到方法'org.gradle.api.internal.file.DefaultSourceDirectorySet.(Ljava/lang/String;Ljava/lang/String;Lorg/gradle/api/internal/file/FileResolver;)V'.

Error:Unable to find method 'org.gradle.api.internal.file.DefaultSourceDirectorySet.(Ljava/lang/String;Ljava/lang/String;Lorg/gradle/api/internal/file/FileResolver;)V'.

我很确定它与以下库项目有关:

I'm pretty sure it's related to the following library project:

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.0'
    }
}

apply plugin: 'com.android.library'
apply plugin: 'com.google.protobuf'

android {
    compileSdkVersion 23
    buildToolsVersion "22.0.1"
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        debug {
            minifyEnabled false
        }
    }
    sourceSets {
        main {
            proto {
                srcDir 'src/main/protos'
            }
            java {
                srcDir 'src/main/java'
            }
            manifest {
                srcFile 'src/main/AndroidManifest.xml'
            }
        }
    }
}


repositories {
    mavenCentral()
}
dependencies {
    compile 'com.android.support:support-v4:+'
    compile 'com.android.support:recyclerview-v7:+'
    compile 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-2'
    compile project(':wallpaperpicker-resources')
}
protobuf {
    // Configure the protoc executable
    protoc {
        // Download from repositories
        artifact = 'com.google.protobuf:protoc:3.0.0-alpha-3'
    }
}

看起来我之前的 gradle 插件版本是 1.3.0 - 我是否遗漏了一些与 sourceSets 块相关的更改?

Looks like my previous gradle plugin version was 1.3.0 - am I missing some change that occurred related to the sourceSets block?

推荐答案

ced 的回答让我找到了解决方案.似乎较新版本的 gradle、Android Studio gradle 插件和 google protoc 插件不会很好用.我不得不按照 ced 的说明升级 google protoc 插件 - 但这与 0.7.0 有很大的不同.不再推荐 javanano protoc 编译器(我根本无法让它工作).这是我最终使用的 javalite 解决方案.

ced's answer led me to the solution. It appears that newer versions of gradle, the Android Studio gradle plugin, and the google protoc plugin wouldn't play nice. I had to upgrade the google protoc plugin as ced noted - but this was a large departure from 0.7.0. The javanano protoc compiler is no longer recommended (and I couldn't get it to work at all). This is the javalite solution that I ended up using.

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'
    }
}

apply plugin: 'com.android.library'
apply plugin: 'com.google.protobuf'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        debug {
            minifyEnabled false
        }
    }
    sourceSets {
        main {
            proto {
                srcDir 'src/main/proto'
            }
            java {
                srcDirs = ['src/main/java','$buildDir/generated-sources/release/javalite']
            }
            manifest {
                srcFile 'src/main/AndroidManifest.xml'
            }
        }
    }
}


repositories {
    mavenCentral()
}
dependencies {
    compile 'com.android.support:support-v4:23.2.0'
    compile 'com.android.support:recyclerview-v7:23.2.0'
    compile 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-2'
    compile 'com.google.protobuf:protoc-gen-javalite:3.0.0'
    compile 'com.google.protobuf:protobuf-lite:3.0.0'
    compile project(':wallpaperpicker-resources')
}

protobuf {
    generatedFilesBaseDir = "$projectDir/build/generated-sources"
    protoc {
        // Download from repositories
        artifact = 'com.google.protobuf:protoc:3.0.0'
    }
    plugins {
        javalite {
            // The codegen for lite comes as a separate artifact
            artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.plugins {
                javalite {
                    //remove some of the javalite extra packaging
                    outputSubDir = ''
                }
            }
        }
    }
}

apply plugin: 'idea'

idea {
    module {
        sourceDirs += file("$buildDir/generated-sources/release/javalite");
    }
}

这篇关于Android Studio 2.1.3 - DefaultSourceDirectorySet 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆