Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 2.1.3 - DefaultSourceDirectorySet issue

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

Screenshot

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

like image 408
Ryan Moore Avatar asked Aug 18 '16 14:08

Ryan Moore


2 Answers

Try to update the protobuf version: classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'

like image 94
ced Avatar answered Nov 18 '22 08:11

ced


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");
    }
}
like image 34
Ryan Moore Avatar answered Nov 18 '22 08:11

Ryan Moore