更多文件导入版本会出错,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
}