android - protobuf Android 导入文件
问题描述
更多文件导入构建会出错,android build.gradle:
Cause: protoc: stdout: . stderr: C:\Users\admin\Desktop\WxDemo\app\build\extracted-include-protos\main: warning: directory does not exist.
C:\Users\admin\Desktop\WxDemo\app\src\debug\proto: warning: directory does not exist.
./app/src/main/java/proto/protobuf.proto: Backslashes, consecutive slashes, ".", or ".." are not allowed in the virtual path
./app/src/main/java/proto/protobuf_request_response.proto: Backslashes, consecutive slashes, ".", or ".." are not allowed in the virtual path
protobuf_main.proto: Import "./app/src/main/java/proto/protobuf.proto" was not found or had errors.
protobuf_main.proto: Import "./app/src/main/java/proto/protobuf_request_response.proto" was not found or had errors.
protobuf_main.proto:10:14: "CMD_SERVICE" seems to be defined in "protobuf.proto", which is not imported by "protobuf_main.proto". To use it here, please add the necessary import.
Build.gradle
:
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.haha.dot.chat"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
java {
srcDir 'src/main/java'
}
proto {
srcDir 'src/main/proto'
include '**/*.proto'
}
}
}
//android studio默认so文件加载目录为:src/main/jniLibs
//如在module的build.gradle按照如下方式,自定义了so文件加载目录请确保对应目录下只有armeabi目录
sourceSets {
main{
jniLibs.srcDirs = ['libs']
}
}
}
protobuf {
//这里配置protoc编译器
protoc {
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'
}
}
//这里配置生成目录,编译后会在build的目录下生成对应的java文件
generateProtoTasks {
all().each { task ->
all()*.plugins {
javalite { }
}
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestImplementation 'com.android.support.test:runner:0.5'
implementation 'com.android.support:support-v4:28.0.0-alpha1'
androidTestImplementation 'com.android.support:support-annotations:28.0.0-alpha1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
implementation 'io.netty:netty-all:4.1.16.Final'
implementation 'com.google.protobuf:protobuf-lite:3.0.0'
// implementation 'com.google.protobuf:protobuf-java:3.2.0' //依赖的protobuf-java lib
}
解决方案
推荐阅读
- database - 前向乐观并发控制的正确性
- java - 是否可以转储(计数)事件调度线程上当前的内容?
- c# - 在 asp.net core web 项目中允许 windows 和基本身份验证
- sql - Can I Create a Macro Name from a Macro Variable
- python - 根据条件从其他数据框创建新的熊猫
- java - 如何在不使用 Java 数组的情况下获得标准偏差?
- sql - max语句中的SQL多个条件不起作用
- pandas - 如何根据布尔值对数据求和?
- javascript - 发出第一个值,然后忽略计时器内发出的值
- c++ - 如何修复编译错误“此函数或变量可能不安全”(strcpy)