gpt4 book ai didi

android - java.lang.NoSuchMethodError in external java dependency inside the java dependency from Kotlin on Android 5

转载 作者:行者123 更新时间:2023-12-01 14:02:24 25 4
gpt4 key购买 nike

我从包含来自 Kotlin 上的 android 应用程序的另一个外部依赖项(retro stream)的存储库中实现外部 JAVA 依赖项,结果我遇到了崩溃在 android 5 上由 java.lang.NoSuchMethodError: No static method 根据 JAVA-library 内的跟踪(跟踪附在下面) .问题出现在 retro stream 库的 Stream 类中(方法“of”)。我已经检查过该库是否存在于外部依赖项中,并且所有类和方法都可以从代码中看到,最有趣的是,它不会在 android> = 7 设备上崩溃。

我已经尝试从 kotlin 代码中显式调用方法 - 没问题。

Versions: 
Kotlin 1.3.50
Gradle plugin 3.4.2
Gradle 5.4.1
Android studio 3.5

问题代码:

    EmptyUtils.getLastNotNullGotValue(Supplier { "" })

E/AndroidRuntime( 5699): FATAL EXCEPTION: main E/AndroidRuntime( 5699): Process: com.jetruby.kotlindslgradleexample, PID: 5699 E/AndroidRuntime( 5699): java.lang.NoSuchMethodError: No static method of([Ljava/lang/Object;)Ljava9/util/stream/Stream; in class Ljava9/util/stream/Stream; or its super classes (declaration of 'java9.util.stream.Stream' appears in /data/app/com.jetruby.kotlindslgradleexample-2/base.apk) E/AndroidRuntime( 5699): at ru.m4bank.mpos.service.network.utils.EmptyUtils.getLastNotNullGotValueOrDefault(EmptyUtils.java:40) E/AndroidRuntime( 5699): at ru.m4bank.mpos.service.network.utils.EmptyUtils.getLastNotNullGotValue(EmptyUtils.java:51) E/AndroidRuntime( 5699): at com.jetruby.kotlindslgradleexample.MainActivity.onCreate(MainActivity.kt:33) E/AndroidRuntime( 5699): at android.app.Activity.performCreate(Activity.java:5990) E/AndroidRuntime( 5699): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) E/AndroidRuntime( 5699): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) E/AndroidRuntime( 5699): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) E/AndroidRuntime( 5699): at android.app.ActivityThread.access$800(ActivityThread.java:151) E/AndroidRuntime( 5699): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) E/AndroidRuntime( 5699): at android.os.Handler.dispatchMessage(Handler.java:102) E/AndroidRuntime( 5699): at android.os.Looper.loop(Looper.java:135) E/AndroidRuntime( 5699): at android.app.ActivityThread.main(ActivityThread.java:5254) E/AndroidRuntime( 5699): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime( 5699): at java.lang.reflect.Method.invoke(Method.java:372) E/AndroidRuntime( 5699): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) E/AndroidRuntime( 5699): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

在尝试了各种汇编选项后,我发现如果你在本地(通过文件)实现JAVA依赖,在5-th android 上不会崩溃!! 。此外,如果从 JAVA 而不是从 kotlin 编译,则不会发生掉落。它只适用于接口(interface)中的静态方法

在下图中,有 2 个依赖项变体(第一个是我从 gradle 缓存中复制的,当我拉出第二个并在本地将其实现为 file 时,第二个刚刚从存储库中提取)。

Implementation variants

结果:

On android <7:  1-st variant - all ok, 2-nd variant - crashes.
On android >=7 - 1,2 variants - ok

我已经反编译了应用程序并注意到 kotlin 来自接口(interface)的静态方法 被收集在一个单独的类中(辅助内部类 ClassName.CC 被创建并在其中放置了静态方法)。因此,当从存储库实现依赖时,反编译的外部类引用原始类和原始方法,当从本地源实现时> (从拉取的仓库复制到libs文件夹),它指的是辅助XX.CC。怀疑是 java.lang.NoSuchMethodError crashes: No static method 的原因。

Decompiled classes of the problem class

下面的代码是“helper”类的反编译代码,“missing”了方法。成功和不成功的构建都是一样的:

    .class public final synthetic Ljava9/util/stream/Stream$-CC;
.super Ljava/lang/Object;
.source "Stream.java"


# direct methods
.method public static $default$dropWhile(Ljava9/util/stream/Stream;Ljava9/util/function/Predicate;)Ljava9/util/stream/Stream;
.locals 3
.param p0, "_this" # Ljava9/util/stream/Stream;
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava9/util/function/Predicate<",
"-TT;>;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation

.line 630
.local p0, "this":Ljava9/util/stream/Stream;, "Ljava9/util/stream/Stream<TT;>;"
.local p1, "predicate":Ljava9/util/function/Predicate;, "Ljava9/util/function/Predicate<-TT;>;"
invoke-static {p1}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;

.line 633
new-instance v0, Ljava9/util/stream/WhileOps$UnorderedWhileSpliterator$OfRef$Dropping;

.line 634
invoke-interface {p0}, Ljava9/util/stream/Stream;->spliterator()Ljava9/util/Spliterator;

move-result-object v1

const/4 v2, 0x1

invoke-direct {v0, v1, v2, p1}, Ljava9/util/stream/WhileOps$UnorderedWhileSpliterator$OfRef$Dropping;-><init>(Ljava9/util/Spliterator;ZLjava9/util/function/Predicate;)V

.line 635
invoke-interface {p0}, Ljava9/util/stream/Stream;->isParallel()Z

move-result v1

.line 633
invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;

move-result-object v0

.line 635
invoke-static {p0}, Ljava9/util/stream/StreamSupport;->closeHandler(Ljava9/util/stream/BaseStream;)Ljava/lang/Runnable;

move-result-object v1

invoke-interface {v0, v1}, Ljava9/util/stream/Stream;->onClose(Ljava/lang/Runnable;)Ljava9/util/stream/BaseStream;

move-result-object v0

check-cast v0, Ljava9/util/stream/Stream;

return-object v0
.end method

.method public static $default$takeWhile(Ljava9/util/stream/Stream;Ljava9/util/function/Predicate;)Ljava9/util/stream/Stream;
.locals 3
.param p0, "_this" # Ljava9/util/stream/Stream;
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava9/util/function/Predicate<",
"-TT;>;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation

.line 564
.local p0, "this":Ljava9/util/stream/Stream;, "Ljava9/util/stream/Stream<TT;>;"
.local p1, "predicate":Ljava9/util/function/Predicate;, "Ljava9/util/function/Predicate<-TT;>;"
invoke-static {p1}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;

.line 567
new-instance v0, Ljava9/util/stream/WhileOps$UnorderedWhileSpliterator$OfRef$Taking;

.line 568
invoke-interface {p0}, Ljava9/util/stream/Stream;->spliterator()Ljava9/util/Spliterator;

move-result-object v1

const/4 v2, 0x1

invoke-direct {v0, v1, v2, p1}, Ljava9/util/stream/WhileOps$UnorderedWhileSpliterator$OfRef$Taking;-><init>(Ljava9/util/Spliterator;ZLjava9/util/function/Predicate;)V

.line 569
invoke-interface {p0}, Ljava9/util/stream/Stream;->isParallel()Z

move-result v1

.line 567
invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;

move-result-object v0

.line 569
invoke-static {p0}, Ljava9/util/stream/StreamSupport;->closeHandler(Ljava9/util/stream/BaseStream;)Ljava/lang/Runnable;

move-result-object v1

invoke-interface {v0, v1}, Ljava9/util/stream/Stream;->onClose(Ljava/lang/Runnable;)Ljava9/util/stream/BaseStream;

move-result-object v0

check-cast v0, Ljava9/util/stream/Stream;

return-object v0
.end method

.method public static builder()Ljava9/util/stream/Stream$Builder;
.locals 1
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">()",
"Ljava9/util/stream/Stream$Builder<",
"TT;>;"
}
.end annotation

.line 1148
new-instance v0, Ljava9/util/stream/Streams$StreamBuilderImpl;

invoke-direct {v0}, Ljava9/util/stream/Streams$StreamBuilderImpl;-><init>()V

return-object v0
.end method

.method public static concat(Ljava9/util/stream/Stream;Ljava9/util/stream/Stream;)Ljava9/util/stream/Stream;
.locals 3
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">(",
"Ljava9/util/stream/Stream<",
"+TT;>;",
"Ljava9/util/stream/Stream<",
"+TT;>;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation

.line 1387
.local p0, "a":Ljava9/util/stream/Stream;, "Ljava9/util/stream/Stream<+TT;>;"
.local p1, "b":Ljava9/util/stream/Stream;, "Ljava9/util/stream/Stream<+TT;>;"
invoke-static {p0}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;

.line 1388
invoke-static {p1}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;

.line 1391
new-instance v0, Ljava9/util/stream/Streams$ConcatSpliterator$OfRef;

.line 1392
invoke-interface {p0}, Ljava9/util/stream/Stream;->spliterator()Ljava9/util/Spliterator;

move-result-object v1

invoke-interface {p1}, Ljava9/util/stream/Stream;->spliterator()Ljava9/util/Spliterator;

move-result-object v2

invoke-direct {v0, v1, v2}, Ljava9/util/stream/Streams$ConcatSpliterator$OfRef;-><init>(Ljava9/util/Spliterator;Ljava9/util/Spliterator;)V

.line 1393
.local v0, "split":Ljava9/util/Spliterator;, "Ljava9/util/Spliterator<TT;>;"
invoke-interface {p0}, Ljava9/util/stream/Stream;->isParallel()Z

move-result v1

if-nez v1, :cond_1

invoke-interface {p1}, Ljava9/util/stream/Stream;->isParallel()Z

move-result v1

if-eqz v1, :cond_0

goto :goto_0

:cond_0
const/4 v1, 0x0

goto :goto_1

:cond_1
:goto_0
const/4 v1, 0x1

:goto_1
invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;

move-result-object v1

.line 1394
.local v1, "stream":Ljava9/util/stream/Stream;, "Ljava9/util/stream/Stream<TT;>;"
invoke-static {p0, p1}, Ljava9/util/stream/Streams;->composedClose(Ljava9/util/stream/BaseStream;Ljava9/util/stream/BaseStream;)Ljava/lang/Runnable;

move-result-object v2

invoke-interface {v1, v2}, Ljava9/util/stream/Stream;->onClose(Ljava/lang/Runnable;)Ljava9/util/stream/BaseStream;

move-result-object v2

check-cast v2, Ljava9/util/stream/Stream;

return-object v2
.end method

.method public static empty()Ljava9/util/stream/Stream;
.locals 2
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">()",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation

.line 1158
invoke-static {}, Ljava9/util/Spliterators;->emptySpliterator()Ljava9/util/Spliterator;

move-result-object v0

const/4 v1, 0x0

invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;

move-result-object v0

return-object v0
.end method

.method public static generate(Ljava9/util/function/Supplier;)Ljava9/util/stream/Stream;
.locals 3
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">(",
"Ljava9/util/function/Supplier<",
"+TT;>;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation

.line 1345
.local p0, "s":Ljava9/util/function/Supplier;, "Ljava9/util/function/Supplier<+TT;>;"
invoke-static {p0}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;

.line 1346
new-instance v0, Ljava9/util/stream/StreamSpliterators$InfiniteSupplyingSpliterator$OfRef;

const-wide v1, 0x7fffffffffffffffL

invoke-direct {v0, v1, v2, p0}, Ljava9/util/stream/StreamSpliterators$InfiniteSupplyingSpliterator$OfRef;-><init>(JLjava9/util/function/Supplier;)V

const/4 v1, 0x0

invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;

move-result-object v0

return-object v0
.end method

.method public static iterate(Ljava/lang/Object;Ljava9/util/function/Predicate;Ljava9/util/function/UnaryOperator;)Ljava9/util/stream/Stream;
.locals 8
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
"S:TT;>(TS;",
"Ljava9/util/function/Predicate<",
"TS;>;",
"Ljava9/util/function/UnaryOperator<",
"TS;>;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation

.line 1287
.local p0, "seed":Ljava/lang/Object;, "TS;"
.local p1, "hasNext":Ljava9/util/function/Predicate;, "Ljava9/util/function/Predicate<TS;>;"
.local p2, "next":Ljava9/util/function/UnaryOperator;, "Ljava9/util/function/UnaryOperator<TS;>;"
invoke-static {p2}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;

.line 1288
invoke-static {p1}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;

.line 1289
new-instance v7, Ljava9/util/stream/Stream$2;

const-wide v1, 0x7fffffffffffffffL

const/16 v3, 0x410

move-object v0, v7

move-object v4, p2

move-object v5, p0

move-object v6, p1

invoke-direct/range {v0 .. v6}, Ljava9/util/stream/Stream$2;-><init>(JILjava9/util/function/UnaryOperator;Ljava/lang/Object;Ljava9/util/function/Predicate;)V

.line 1331
.local v0, "spliterator":Ljava9/util/Spliterator;, "Ljava9/util/Spliterator<TT;>;"
const/4 v1, 0x0

invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;

move-result-object v1

return-object v1
.end method

.method public static iterate(Ljava/lang/Object;Ljava9/util/function/UnaryOperator;)Ljava9/util/stream/Stream;
.locals 7
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
"S:TT;>(TS;",
"Ljava9/util/function/UnaryOperator<",
"TS;>;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation

.line 1224
.local p0, "seed":Ljava/lang/Object;, "TS;"
.local p1, "f":Ljava9/util/function/UnaryOperator;, "Ljava9/util/function/UnaryOperator<TS;>;"
invoke-static {p1}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;

.line 1225
new-instance v6, Ljava9/util/stream/Stream$1;

const-wide v1, 0x7fffffffffffffffL

const/16 v3, 0x410

move-object v0, v6

move-object v4, p1

move-object v5, p0

invoke-direct/range {v0 .. v5}, Ljava9/util/stream/Stream$1;-><init>(JILjava9/util/function/UnaryOperator;Ljava/lang/Object;)V

.line 1244
.local v0, "spliterator":Ljava9/util/Spliterator;, "Ljava9/util/Spliterator<TT;>;"
const/4 v1, 0x0

invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;

move-result-object v1

return-object v1
.end method

.method public static of(Ljava/lang/Object;)Ljava9/util/stream/Stream;
.locals 2
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">(TT;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation

.line 1169
.local p0, "t":Ljava/lang/Object;, "TT;"
new-instance v0, Ljava9/util/stream/Streams$StreamBuilderImpl;

invoke-direct {v0, p0}, Ljava9/util/stream/Streams$StreamBuilderImpl;-><init>(Ljava/lang/Object;)V

const/4 v1, 0x0

invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;

move-result-object v0

return-object v0
.end method

.method public static varargs of([Ljava/lang/Object;)Ljava9/util/stream/Stream;
.locals 1
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">([TT;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation

.line 1196
.local p0, "values":[Ljava/lang/Object;, "[TT;"
invoke-static {p0}, Ljava9/util/J8Arrays;->stream([Ljava/lang/Object;)Ljava9/util/stream/Stream;

move-result-object v0

return-object v0
.end method

.method public static ofNullable(Ljava/lang/Object;)Ljava9/util/stream/Stream;
.locals 2
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">(TT;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation

.line 1183
.local p0, "t":Ljava/lang/Object;, "TT;"
if-nez p0, :cond_0

invoke-static {}, Ljava9/util/stream/Stream$-CC;->empty()Ljava9/util/stream/Stream;

move-result-object v0

goto :goto_0

:cond_0
new-instance v0, Ljava9/util/stream/Streams$StreamBuilderImpl;

invoke-direct {v0, p0}, Ljava9/util/stream/Streams$StreamBuilderImpl;-><init>(Ljava/lang/Object;)V

const/4 v1, 0x0

.line 1184
invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;

move-result-object v0

:goto_0
return-object v0
.end method

JAVA库的反编译方法调用了缺少的方法(Build with crash):

    .method public static varargs getLastNotNullValue([Ljava/lang/Object;)Ljava/lang/Object;
.locals 2
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">([TT;)TT;"
}
.end annotation

.annotation runtime Ljava/lang/SafeVarargs;
.end annotation

.line 56
.local p0, "values":[Ljava/lang/Object;, "[TT;"
invoke-static {p0}, Ljava9/util/stream/Stream;->of([Ljava/lang/Object;)Ljava9/util/stream/Stream;

move-result-object v0

sget-object v1, Lru/m4bank/mpos/service/network/utils/-$$Lambda$h24iVvNNOyPAWTyqI3I8dzCunHY;->INSTANCE:Lru/m4bank/mpos/service/network/utils/-$$Lambda$h24iVvNNOyPAWTyqI3I8dzCunHY;

invoke-interface {v0, v1}, Ljava9/util/stream/Stream;->filter(Ljava9/util/function/Predicate;)Ljava9/util/stream/Stream;

move-result-object v0

invoke-interface {v0}, Ljava9/util/stream/Stream;->findFirst()Ljava9/util/Optional;

move-result-object v0

sget-object v1, Lru/m4bank/mpos/service/network/utils/-$$Lambda$EmptyUtils$2lJJnncNhWO5-cW1nB8g96aMo4M;->INSTANCE:Lru/m4bank/mpos/service/network/utils/-$$Lambda$EmptyUtils$2lJJnncNhWO5-cW1nB8g96aMo4M;

invoke-virtual {v0, v1}, Ljava9/util/Optional;->orElseGet(Ljava9/util/function/Supplier;)Ljava/lang/Object;

move-result-object v0

return-object v0
.end method

同样的反编译方法(Build without crash):

    .method public static varargs getLastNotNullValue([Ljava/lang/Object;)Ljava/lang/Object;
.locals 2
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">([TT;)TT;"
}
.end annotation

.annotation runtime Ljava/lang/SafeVarargs;
.end annotation

.line 56
.local p0, "values":[Ljava/lang/Object;, "[TT;"
invoke-static {p0}, Ljava9/util/stream/Stream$-CC;->of([Ljava/lang/Object;)Ljava9/util/stream/Stream;

move-result-object v0

sget-object v1, Lru/m4bank/mpos/service/network/utils/-$$Lambda$h24iVvNNOyPAWTyqI3I8dzCunHY;->INSTANCE:Lru/m4bank/mpos/service/network/utils/-$$Lambda$h24iVvNNOyPAWTyqI3I8dzCunHY;

invoke-interface {v0, v1}, Ljava9/util/stream/Stream;->filter(Ljava9/util/function/Predicate;)Ljava9/util/stream/Stream;

move-result-object v0

invoke-interface {v0}, Ljava9/util/stream/Stream;->findFirst()Ljava9/util/Optional;

move-result-object v0

sget-object v1, Lru/m4bank/mpos/service/network/utils/-$$Lambda$EmptyUtils$2lJJnncNhWO5-cW1nB8g96aMo4M;->INSTANCE:Lru/m4bank/mpos/service/network/utils/-$$Lambda$EmptyUtils$2lJJnncNhWO5-cW1nB8g96aMo4M;

invoke-virtual {v0, v1}, Ljava9/util/Optional;->orElseGet(Ljava9/util/function/Supplier;)Ljava/lang/Object;

move-result-object v0

return-object v0
.end method

问题:这是 kotlin 错误还是我做错了什么,然后如何使用存储库中的JAVA-库(其中包含带有静态方法的接口(interface))在 android <7 上并且不会崩溃?

最佳答案

您正在尝试在 Android API 级别 < 24 中使用 Java Stream Api,这是不可能的。

根据 Android API 级别检查您可以使用和不能使用的内容 here

关于android - java.lang.NoSuchMethodError in external java dependency inside the java dependency from Kotlin on Android 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58737497/

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