Android工作室和Protobuf集成(Android studio and Protobuf integration)

编程入门 行业动态 更新时间:2024-10-26 12:24:45
Android工作室和Protobuf集成(Android studio and Protobuf integration)

我有一个需要使用protobuf的项目(从服务器获取对象并解析它们)。 为此,我配置了以下内容:

项目级别gradle.build

buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.1.0' classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.0' classpath 'com.google.protobuf:protobuf-java:2.6.1' } } allprojects { repositories { jcenter() mavenCentral() } } task clean(type: Delete) { delete rootProject.buildDir }

应用程序级别gradle.build

apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.protobuf' android { ... } protobuf { protoc { artifact = 'com.google.protobuf:protoc:2.6.1' } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.support:design:23.4.0' compile 'com.google.protobuf:protobuf-java:2.6.1' compile 'com.google.protobuf:protobuf-gradle-plugin:0.7.0' }

我把我的proto文件放在.../app/src/main/proto/FILE.proto 。 一旦我正在尝试构建该项目,我收到以下错误:

Error:Execution failed for task ':app:generateDebugProto'. > protoc: stdout: . stderr: /Users/XX/YY/app/build/extracted-protos/main: warning: directory does not exist. /Users/XX/YY/app/build/extracted-include-protos/main: warning: directory does not exist. ... protoc-gen-javanano: program not found or is not executable --javanano_out: protoc-gen-javanano: Plugin failed with status code 1.

任何想法为什么是这样? 它应该使用repo中的protoc,并且应该支持该纳米编译。

谢谢。

I have a project that need to use protobuf (Getting the objects from server and parsing them). For that I configured the following things:

Project level gradle.build

buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.1.0' classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.0' classpath 'com.google.protobuf:protobuf-java:2.6.1' } } allprojects { repositories { jcenter() mavenCentral() } } task clean(type: Delete) { delete rootProject.buildDir }

App level gradle.build

apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.protobuf' android { ... } protobuf { protoc { artifact = 'com.google.protobuf:protoc:2.6.1' } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.support:design:23.4.0' compile 'com.google.protobuf:protobuf-java:2.6.1' compile 'com.google.protobuf:protobuf-gradle-plugin:0.7.0' }

I put my proto file under .../app/src/main/proto/FILE.proto. Once i am trying to build the project I am getting the following error:

Error:Execution failed for task ':app:generateDebugProto'. > protoc: stdout: . stderr: /Users/XX/YY/app/build/extracted-protos/main: warning: directory does not exist. /Users/XX/YY/app/build/extracted-include-protos/main: warning: directory does not exist. ... protoc-gen-javanano: program not found or is not executable --javanano_out: protoc-gen-javanano: Plugin failed with status code 1.

Any idea why is that? It should use the protoc from the repo and is should support that nano compilation.

Thanks.

最满意答案

最后我从GitHub下载了源代码并编译了它。 它解决了这个问题,因为它包含缺少的二进制文件

Finally i downloaded the source from GitHub and compiled it. It fixed the issue because it includes the missing binary.

更多推荐

本文发布于:2023-04-27 16:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327215.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作室   Android   Protobuf   integration   studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!