java.lang.VerifyError: Operand stack overflow for google-ads API and SBT

java.lang.VerifyError: Operand stack overflow for google-ads API and SBT

我正在尝试从 Google-AdWords 迁移到 EMR 中 spark 3.1.1 中的 google-ads-v10 API。 由于与现有罐子的冲突,我面临一些依赖性问题。 最初,我们面临着与 Protobuf jar 相关的依赖:

Exception in thread "grpc-default-executor-0" java.lang.IllegalAccessError: tried to access field com.google.protobuf.AbstractMessage.memoizedSize from class com.google.ads.googleads.v10.services.SearchGoogleAdsRequest
    at com.google.ads.googleads.v10.services.SearchGoogleAdsRequest.getSerializedSize(SearchGoogleAdsRequest.java:394)
    at io.grpc.protobuf.lite.ProtoInputStream.available(ProtoInputStream.java:108)

为了解决这个问题,尝试遮蔽 Protobuf jar 并改用 uber-jar。着色后,运行在 IntelliJ 中本地化我的项目工作正常,但是当尝试 运行 我创建的可执行 jar 时,我收到以下错误:

Exception in thread "main" io.grpc.ManagedChannelProvider$ProviderNotFoundException: No functional channel service provider found. Try adding a dependency on the grpc-okhttp, grpc-netty, or grpc-netty-shaded artifact

我尝试在 --spark.jars.packages 中添加所有这些库,但没有帮助。

java.lang.VerifyError: Operand stack overflow
Exception Details:
  Location:
    io/grpc/internal/TransportTracer.getStats()Lio/grpc/InternalChannelz$TransportStats; ...
...
...

    at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.<init>(NettyChannelBuilder.java:96)
    at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.forTarget(NettyChannelBuilder.java:169)
    at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.forAddress(NettyChannelBuilder.java:152)
    at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:38)
    at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:24)
    at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:39)
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:348)

有没有人遇到过这样的问题?

Build.sbt



lazy val dependencies = new {
  val sparkRedshift = "io.github.spark-redshift-community" %% "spark-redshift" % "5.0.3" % "provided" excludeAll (ExclusionRule(organization = "com.amazonaws"))
  val jsonSimple = "com.googlecode.json-simple" % "json-simple" % "1.1" % "provided"
  val googleAdsLib = "com.google.api-ads" % "google-ads" % "17.0.1"
  val jedis = "redis.clients" % "jedis" % "3.0.1" % "provided"
  val sparkAvro = "org.apache.spark" %% "spark-avro" % sparkVersion % "provided"
  val queryBuilder = "com.itfsw" % "QueryBuilder" % "1.0.4" % "provided" excludeAll (ExclusionRule(organization = "com.fasterxml.jackson.core"))
  val protobufForGoogleAds = "com.google.protobuf" % "protobuf-java" % "3.18.1"
  val guavaForGoogleAds = "com.google.guava" % "guava" % "31.1-jre"
}

libraryDependencies ++= Seq(
  dependencies.sparkRedshift, dependencies.jsonSimple, dependencies.googleAdsLib,dependencies.guavaForGoogleAds,dependencies.protobufForGoogleAds
  ,dependencies.jedis, dependencies.sparkAvro,
  dependencies.queryBuilder
)


dependencyOverrides ++= Set(
  dependencies.guavaForGoogleAds
)

assemblyShadeRules in assembly := Seq(
  ShadeRule.rename("com.google.protobuf.**" -> "repackaged.protobuf.@1").inAll
)


assemblyMergeStrategy in assembly := {
 case PathList("META-INF", xs@_*) => MergeStrategy.discard
 case PathList("module-info.class", xs@_*) => MergeStrategy.discard
 case x => MergeStrategy.first
}

我遇到了类似的问题,我将程序集合并策略更改为:

assemblyMergeStrategy in assembly := {
  case x if x.contains("io.netty.versions.properties") => MergeStrategy.discard
  case x =>
    val oldStrategy = (assemblyMergeStrategy in assembly).value
    oldStrategy(x)
}

通过使用 google-ads-shadowjar 作为外部 jar 而不是依赖 google-ads 库解决了这个问题。这解决了必须手动处理依赖项的问题,但会使您的 jar 大小变大。