简体   繁体   English

如何在完整的Android项目(渐变)中包含“ com.google.protobuf”,而不是精简的形式?

[英]How do you include 'com.google.protobuf' on android project (gradle) as full but not as lite?

I am trying to use a protobuf generated code to decode messages coming from the network. 我正在尝试使用protobuf生成的代码来解码来自网络的消息。 I have a .proto file which looks like this : 我有一个.proto文件,看起来像这样:

syntax = "proto3";

message CanData {
  string id = 1; // name
  Data data1 = 2;
  Data data2 = 3;     
}
message Data {
    oneof data1 {
        int32 int_type = 2; // Magic and other int types
        float float_type = 3; // Timestamp and other float types
        uint32 unsigned_type = 4; // unsigned types
    }
}

When I generate the code using the protoc command. 当我使用protoc命令生成代码时。 It works succesfully. 它成功地工作。 But then I open the android project and it does not work as expected. 但是然后我打开了android项目,它没有按预期工作。 I get errors looking as on the following line: 我在以下行中看到错误:

Error:(11, 26) error: cannot find symbol class ExtensionRegistry
Error:(1719, 43) error: package com.google.protobuf.GeneratedMessageV3 does not exist
Error:(1716, 55) error: package com.google.protobuf.Descriptors does not exist
Error:(1724, 43) error: package com.google.protobuf.GeneratedMessageV3 does not exist
Error:(1721, 55) error: package com.google.protobuf.Descriptors does not exist

There is many more errors. 还有更多错误。 But for simplicity and clarity I kept them away. 但是为了简单明了起见,我将其保留。

Then looking on the internet, we came accross a bunch of solutions that do not work for us as for exemple what we tried to do in the build.gradle : 然后在互联网上浏览,我们遇到了很多对我们不起作用的解决方案,例如我们在build.gradle中尝试做的事情:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And build.gradle(Module app) 和build.gradle(模块应用程序)

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

android {
    compileSdkVersion 25
    defaultConfig {
        applicationId "oronos.oronosmobileapp"
        minSdkVersion 25
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:25.4.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.protobuf:protobuf-lite:3.0.0'
    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'
}

I think that the lite version: 我认为精简版:

com.google.protobuf:protobuf-lite:3.0.0 com.google.protobuf:protobuf-lite:3.0.0

is not the one I am looking for, But I am unable to find the solution. 不是我要寻找的那个,但是我找不到解决方案。

Try this one here 在这里尝试这个

// https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java
compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.5.1'

or 要么

compile 'com.google.protobuf:protobuf-java:3.5.1'

You can simply google it https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java 您可以简单地用谷歌搜索它https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:无法在Android Studio导入的项目中找到:com.google.protobuf:protobuf-java:2.5 - Error:Failed to find: com.google.protobuf:protobuf-java:2.5 in Android Studio imported project Android Gradle Protobufs:如何编译完整的protobuf,而不是“精简版”? - Android Gradle Protobufs: How to compile the full protobuf and not the “lite” version? Android Studio和protobuf错误:(7,0)找不到ID为'com.google.protobuf'的插件 - Android Studio and protobuf Error:(7, 0) Plugin with id 'com.google.protobuf' not found 如何在带有Gradle的Android Studio中包含romainguy的ViewServer? - How do you include romainguy's ViewServer in Android Studio with Gradle? Android:如何在Settings.gradle中包含项目 - Android: How To include project in Settings.gradle 如何在android库gradle项目中包含依赖项? - How to include dependencies in android library gradle project? RC,Lite和Full app的Android项目结构 - Android project structure for RC, Lite and Full app 如何使用Gradle构建在Android Studio中导入com.google.android.gms。*? - How do I import com.google.android.gms.* in Android Studio using a Gradle build? 如何在android gradle项目中包含lvl-license项目 - how to include lvl-license project with android gradle project 如何在 gradle 多项目构建中包含 Android 项目? - How to include Android project in a gradle multi-project build?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM