Android Studio 2.1.3 - DefaultSourceDirectorySet问题

时间:2016-08-18 14:32:28

标签: android android-studio gradle

从2.1.2更新Android Studio - > 2.1.3今天早上收到以下gradle sync错误:

  

错误:无法找到方法   ' org.gradle.api.internal.file.DefaultSourceDirectorySet。(Ljava /郎/字符串; Ljava /郎/字符串; Lorg / gradle这个/ API /内部/文件/ FileResolver;)V'

我非常确定它与以下图书馆项目有关:

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'
    }
}

Screenshot

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

2 个答案:

答案 0 :(得分:6)

尝试更新protobuf版本: classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'

答案 1 :(得分:3)

ced的回答让我找到了解决方案。似乎较新版本的gradle,Android Studio gradle插件和google protoc插件不会很好玩。我不得不升级谷歌protoc插件,因为ced注意到 - 但这与0.7.0大不相同。不再推荐使用javanano protoc编译器(我根本无法使用它)。这是我最终使用的javalite解决方案。

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