Android Studio 2.1.3 - DefaultSourceDirectorySet issue

前端 未结 2 2042
深忆病人
深忆病人 2021-02-06 08:21

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.inte

2条回答
  •  北海茫月
    2021-02-06 09:20

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

提交回复
热议问题