2017-11-16 36 views
0

컴파일되지 않습니다,하지만 난 다음 오류 얻을 :protobuf Gradle을 플러그인 내가 Gradle을 플러그인을 사용하여 파일을 protobuf 컴파일하기 위해 노력하고있어

java.io.IOException: Can't write [/Users/elavi/dev/sdk3/android/showcaseapp/build/intermediates/multi-dex/debug/componentClasses.jar] 
(Can't read [/Users/elavi/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protobuf-java/3.0.0/6d325aa7c921661d84577c0a93d82da4df9fa4c8/protobuf-java-3.0.0.jar(;;;;;;**.class)] 
(Duplicate zip entry [protobuf-java-3.0.0.jar:com/google/protobuf/ExperimentalApi.class])) 

하지 이런 확실한 이유를 ... protobuf 파일이 생성됩니다 예상대로 올바르게 수행되지만이 마지막 단계는 이상한 오류로 인해 실패합니다.

이 내 Gradle을 파일 : 나는 단순히 어떤 멋진 물건을하지 않았다는 protobuf의 추가 정보 (https://github.com/google/protobuf-gradle-plugin)에 기록 무엇을 추가

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

group = GROUP 
version = VERSION_NAME 

apply from: 'versioning.gradle' 

buildscript { 
    repositories { 
    mavenCentral() 
    } 
} 

android { 
    compileSdkVersion 26 
    buildToolsVersion '26.0.2' 
    flavorDimensions "default" 

    defaultConfig { 
    minSdkVersion 15 
    targetSdkVersion 26 
    versionCode buildVersionCode() 
    versionName VERSION_NAME 
    consumerProguardFiles 'tangram-proguard-rules.txt' 
    } 

    // Add proto files location to be used with the protobuf plugin 
    sourceSets { 
    main { 
     proto { 
     srcDir '../../common/vendored/proto' 
     } 
    } 
    } 
} 

dependencies { 
    compile 'com.google.protobuf:protobuf-lite:3.0.0' 
    compile 'io.grpc:grpc-stub:1.6.1' 
    compile 'io.grpc:grpc-protobuf:1.0.0-pre2' 
    compile 'javax.annotation:javax.annotation-api:1.2' 

    compile 'com.squareup.okhttp3:okhttp:3.9.0' 
    compile 'com.android.support:support-annotations:27.0.0' 

    implementation project(':core') 
} 

// Protobuf configuration. Taken from the documentation: https://github.com/google/protobuf-gradle-plugin 
protobuf { 

    protoc { 
    artifact = 'com.google.protobuf:protoc:3.0.0' } plugins { 
    javalite { 
     artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0' 
    } 
    grpc { 
     artifact = 'io.grpc:protoc-gen-grpc-java:1.0.0-pre2' 
    } } generateProtoTasks { 
    all().each { task -> 
     task.builtins { 
     remove java 
     } 
     task.plugins { 
     javalite { } 
     grpc { 
      option 'lite' 
     } 
     } 
    } } generatedFilesBaseDir = "$projectDir/build/gen" } 

clean { delete protobuf.generatedFilesBaseDir } 

idea { module { 
    sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java"); 
    sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/grpc"); } } 

//apply from: file('gradle-mvn-push.gradle') 

...

답변

2

어쩌면 당신은 compile 'com.google.protobuf:protobuf-lite:3.0.0' 항목을 제거해야합니다 종속성 섹션에서 중복 된 항목이 있고 마지막 버전의 일부 설정이 누락되었습니다. 다른면에는 프로토 소스에 대한 경로가 문제가있을 수 있습니다. 내 프로토는 src/main/proto이지만 나는 proto만을 선언했습니다. 내 간단한 설정은 다음과 같습니다

응용 프로그램 build.gradle :

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

android { 
    ... 
    sourceSets { 
     main { 
      proto { 
      } 
     } 
    } 
    ... 
    configurations.all { 
     resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9' 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 

    compile 'com.android.support:appcompat-v7:27.0.0' 
    ... 
    compile 'io.grpc:grpc-okhttp:1.1.2' 
    compile 'io.grpc:grpc-protobuf-lite:1.1.2' 
    compile 'io.grpc:grpc-stub:1.1.2' 
    compile 'javax.annotation:javax.annotation-api:1.2' 
    ... 
    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'com.android.support.test:runner:1.0.1' 
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 
} 

protobuf { 
    protoc { 
     artifact = "com.google.protobuf:protoc:3.0.2" 
    } 
    plugins { 
     grpc { 
      artifact = 'io.grpc:protoc-gen-grpc-java:1.1.2' 
     } 
     javalite { 
      artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0" 
     } 
    } 
    generateProtoTasks { 
     all().each { task -> 
      task.plugins { 
       javalite {} 
       grpc { 
        // Options added to --grpc_out 
        option 'lite' 
       } 
      } 
     } 
    } 
    generatedFilesBaseDir = "$projectDir/build/generated" 
} 

주요 프로젝트 build.gradle :

buildscript { 
    repositories { 
     google() 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:3.0.0' 
     classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.2" 
     ... 
    } 
}