gpt4 book ai didi

java.lang.VerifyError : Verifier rejected class - failed to verify 错误

转载 作者:行者123 更新时间:2023-11-29 04:27:44 63 4
gpt4 key购买 nike

我正在使用 protobuf 自动生成我的 API 服务,在 gRPC 中技术,在我的安卓客户端。自从我一直在毫无问题地工作以来,已经过去了几个月。现在突然之间,AndroidRuntime Verifier 拒绝了我的 API 的一个自动生成的方法。


这是堆栈跟踪:

com.company.companyplayer E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.company.companyplayer, PID: 18181
java.lang.VerifyError: Verifier rejected class company.v1.PlayerEarningsPageDataResponse: void company.v1.PlayerEarningsPageDataResponse.mergeNextDepositDate(com.google.protobuf.Timestamp) failed to verify: void company.v1.PlayerEarningsPageDataResponse.mergeNextDepositDate(com.google.protobuf.Timestamp): [0x26] register v5 has type Precise Reference: com.google.protobuf.Timestamp but expected Reference: com.google.protobuf.GeneratedMessageLiteVerifier rejected class company.v1.PlayerEarningsPageDataResponse: java.lang.Object company.v1.PlayerEarningsPageDataResponse.dynamicMethod(com.google.protobuf.GeneratedMessageLite$MethodToInvoke, java.lang.Object, java.lang.Object) failed to verify: java.lang.Object company.v1.PlayerEarningsPageDataResponse.dynamicMethod(com.google.protobuf.GeneratedMessageLite$MethodToInvoke, java.lang.Object, java.lang.Object): [0x16E] register v8 has type Precise Reference: com.google.protobuf.Timestamp but expected Reference: com.google.protobuf.GeneratedMessageLite (declaration of 'company.v1.PlayerEarningsPageDataResponse' appears in /data/app/com.company.companyplayer-1/split_lib_slice_4_apk.apk)
at company.v1.PlayerEarningsPageDataResponse.getDefaultInstance(PlayerEarningsPageDataResponse.java:0)
at company.v1.APIGrpc.<clinit>(APIGrpc.java:47)
at company.v1.APIGrpc.newStub(APIGrpc.java:0)
at com.company.companyplayer.backend.Client.getAuthAsyncStub(Client.java:103)
at com.company.companyplayer.backend.Client.playerLogin(Client.java:119)
at com.company.companyplayer.ui.activity.LoginActivity.loginAndGoToMainActivity(LoginActivity.java:202)
at com.company.companyplayer.ui.activity.LoginActivity.onActivityResult(LoginActivity.java:127)
at android.app.Activity.dispatchActivityResult(Activity.java:6935)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4086)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4133)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1534)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

以下(类似 SO 帖子中建议的解决方案)无效:

  • 清理并重建(甚至尝试手动清理)
  • 使缓存无效并重新启动 IDE
  • 从 proto 重新生成 API 定义

此外,这里是堆栈跟踪中指出的自动生成的方法:

  private void mergeNextDepositDate(com.google.protobuf.Timestamp value) {
if (nextDepositDate_ != null && nextDepositDate_ != com.google.protobuf.Timestamp.getDefaultInstance()) {
nextDepositDate_ = com.google.protobuf.Timestamp.newBuilder(nextDepositDate_).mergeFrom(value).buildPartial();
} else {
nextDepositDate_ = value;
}
}

可以看出该方法既不是很冗长,也没有带太多参数;已经说过的一些事情是导致此错误的常见原因。


以下是我的应用程序的 build.gradle:(自从上次一切正常以来,gradle 中没有任何更改)

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

android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
defaultConfig {
applicationId "com.company.companyplayer"
minSdkVersion 15
targetSdkVersion 25
versionCode 5
versionName "0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
lintOptions {
disable 'InvalidPackage'
}
}

protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.2.0'
}
plugins {
javalite {
artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
}
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.3.0'
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite {}
grpc {
// Options added to --grpc_out
option 'lite'
}
}
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
/* android support libraries */
compile 'com.google.android:flexbox:0.2.7'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.firebase:firebase-config:11.0.1'
compile 'com.google.firebase:firebase-core:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
compile 'com.google.android.gms:play-services-maps:11.0.1'
compile 'com.google.android.gms:play-services-location:11.0.1'
compile 'com.google.maps.android:android-maps-utils:0.4.4'
compile 'com.google.code.findbugs:jsr305:3.0.1'
compile 'io.grpc:grpc-okhttp:1.3.0'
compile 'io.grpc:grpc-protobuf-lite:1.3.0'
compile 'io.grpc:grpc-stub:1.3.0'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.facebook.android:account-kit-sdk:4.22.0'
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'com.google.api.grpc:googleapis-common-protos:0.0.3' // This is for importing "google/api/annotations.proto" in our proto file
testCompile 'junit:junit:4.12'
androidTestCompile 'com.google.code.findbugs:jsr305:3.0.1'
protobuf 'com.google.protobuf:protobuf-java:3.1.0'
}

apply plugin: 'com.google.gms.google-services'

更新: 该错误肯定与 google.protobuf.Timestamp 有关。这是 link to an MWE重现了这个问题。

最佳答案

您正在混合精简版和完整版 protobuf。

您不能对 googleapis-common-protos 有编译或运行时依赖性,因为它是为完整 protobuf 生成的代码,不适用于 lite protobuf。它还引入了对 protobuf-java 的依赖,当它与 protobuf-lite 混合时会导致重复的类。代替编译依赖项,使用 protobuf 依赖项让 protobuf gradle 插件从 JAR 中包含的 .proto 生成代码。

您目前也没有对 protobuf-lite 的任何依赖,因此如果没有常见的 protos 依赖,您将遇到编译失败。 Common protos 还引入了所需的 grpc-protobuf-lite 依赖项。我建议添加对 io.grpc:grpc-protobuf-lite:1.3.0 的编译时依赖,这也会引入 protobuf-lite

简而言之,对项目进行这些更改并编译:

diff --git a/app/build.gradle b/app/build.gradle
index 8f606bb..2fb997b 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -62,7 +62,8 @@ dependencies {
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'io.grpc:grpc-stub:1.3.0'
compile 'io.grpc:grpc-okhttp:1.3.0'
+ compile 'io.grpc:grpc-protobuf-lite:1.3.0'

- compile 'com.google.api.grpc:googleapis-common-protos:0.0.3'
+ protobuf 'com.google.api.grpc:googleapis-common-protos:0.0.3'
protobuf 'com.google.protobuf:protobuf-java:3.1.0'
}

关于java.lang.VerifyError : Verifier rejected class - failed to verify 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45431743/

63 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com