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

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

问题描述

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


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


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

 buildscript {
repositories {
mavenCentral()
jcenter()
}
依赖关系{
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
buildToolsVersion22.0。 1
defaultConfig {
minSdkVersion 16
targetSd kVersion 23
versionCode 1
versionName1.0
}
buildTypes {
debug {
minifyEnabled false
}
}
sourceSets {
main {
proto {
srcDir'src / main / protos'
}
java {
srcDir'src / main / java'
}
manifest {
srcFile'src / main / AndroidManifest.xml'
}
}
}
}


存储库{
mavenCentral()
}
依赖项{
编译'com.android.support:support-v4:+'
编译'com.android.support:recyclerview-v7:+'
编译'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-2'
编译项目(': )
}
protobuf {
//配置protoc可执行文件
protoc {
// Do从存储库中下载
artifact ='com.google.protobuf:protoc:3.0.0-alpha-3'
}
}



看起来我以前的gradle插件版本是1.3.0 - 我错过了与sourceSets块相关的一些变化吗?

解决方案

ced的回答让我想到了解决方案。看来更新版本的Gradle,Android Studio gradle插件和google protoc插件不会表现出色。我必须升级谷歌protoc插件,因为注意到了 - 但这与0.7.0相差甚远。 javanano protoc编译器不再推荐(我根本无法使它工作)。这是我最终使用的Javalite解决方案。

  buildscript {
存储库{
mavenCentral()
jcenter()
}
依赖项{
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
buildToolsVersion23.0.2
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName1.0

buildTypes {
debug {
minifyEnabled false
}
}
sourceSets {
main {
proto {
srcDir'src / main / proto'
}
java {
srcDirs = ['src / main / java','$ buildDir / generated-source s / release / javalite']
}
manifest {
srcFile'src / main / AndroidManifest.xml'
}
}
}
}


存储库{
mavenCentral()
}
依赖项{
compile'c​​om.android.support:support-v4: 23.2.0'
compile'c​​om.android.support:recyclerview-v7:23.2.0'
compile'c​​om.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-2'
编译'com.google.protobuf:protoc-gen-javalite:3.0.0'
编译'com.google.protobuf:protobuf-lite:3.0.0'
编译项目(' :wallpaperpicker-resources')
}

protobuf {
generatedFilesBaseDir =$ projectDir / build / generated-sources
protoc {
//下载来自存储库
artifact ='com.google.protobuf:protoc:3.0.0'
}
plugins {
javalite {
// lite的codegen是一个sep arate artifact
artifact ='com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
generateProtoTasks {
all()。each {任务 - >
task.plugins {
javalite {
//删除一些javalite额外的包装
outputSubDir =''
}
}
}



apply plugin:'idea'

idea {
module {
sourceDirs + = file( $ buildDir /生成来源/释放/ javalite);
}
}


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

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

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

解决方案

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天全站免登陆