赞
踩
mavenCentral()
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.13'
具体位置如下:
buildscript { repositories { google() mavenCentral() //choice 1: //jcenter() //choice 2: //change mirror maven{ url'http://maven.aliyun.com/nexus/content/groups/public/' } maven{ url'http://maven.aliyun.com/nexus/content/repositories/jcenter'} } dependencies { classpath 'com.android.tools.build:gradle:4.1.0' classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.13' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }
//apply plugin:'com.android.application'
//apply plugin: 'com.google.protobuf'
plugins {
id 'com.android.application'
id 'com.google.protobuf'//gradle脚本头,声明依赖的插件
}
android{
......//省略其他配置项
sourceSets {
main {
java {
srcDirs 'src/main/java'
}
proto {
srcDirs 'src/main/java/com/demo/protocolbuffer'
}
}
}
}
dependencies {
//....
implementation 'com.google.protobuf:protobuf-java:4.0.0-rc-2'
implementation 'com.google.protobuf:protoc:4.0.0-rc-2'
//....
}
//编写编译任务,调用plugin编译生成java文件 protobuf { protoc { artifact = 'com.google.protobuf:protoc:3.6.1' } generateProtoTasks { all().each { task -> task.builtins { remove java } task.builtins { java {} } } } }
syntax = "proto2"; package com.demo.protocolbuffer; option java_package = "com.demo.protocolbuffer"; option java_outer_classname = "AddressBookProtos"; message Person { optional string name = 1; optional int32 id = 2; optional string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } message PhoneNumber { optional string number = 1; optional PhoneType type = 2 [default = HOME]; } repeated PhoneNumber phones = 4; } message AddressBook { repeated Person people = 1; }
Execution failed for task ‘:protocolbufferdemo:generateDebugProto’.
java.io.IOException: Cannot run program “C:\Users\xxxx.gradle\caches\modules-2\files-2.1\com.google.protobuf\protoc\4.0.0-rc-2\474b3604dbd7dff7aa733a745056dfa2dc946eeb\protoc-4.0.0-rc-2-windows-x86_64.exe”:
CreateProcess error=1392, The file or directory is corrupted and
unreadable
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。