gpt4 book ai didi

android - Android Gradle 插件测试 apk 生成器是否自动对我的测试 apk 进行多索引处理?如果是这样,为什么会生成 "NoSuchMethodError"

转载 作者:太空狗 更新时间:2023-10-29 14:37:46 24 4
gpt4 key购买 nike

这一切都是从运行仪器测试时的这个错误开始的:

java.lang.NoSuchMethodError: No static method closeQuietly(Ljava/net/ServerSocket;)V in class Lokhttp3/internal/Util; or its super classes (declaration of 'okhttp3.internal.Util' appears in /data/app/com.example-vKdPJoTLl49ntRbZfsRBqQ==/base.apk!classes2.dex)
at okhttp3.mockwebserver.MockWebServer$2.execute(MockWebServer.java:333)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)

我查看生成的 test.apk 以查看 dex 文件中存在/缺失的内容。

我注意到的第一件事是测试 apk 有两个 .dex 文件。为什么?我没有使用 multidex(并且 IIRC multidex 无论如何都不适用于测试 apk)。然后我将两个“引用的方法计数”相加,果然超过了 65k 的限制。 AGP auto-multi-dexing 是我的测试 apk 吗?

classes.dex classes2.dex

此外,我在 first dex 中看到了“缺失”方法。

为什么它被列为“引用”而不是“定义”方法?它不像框架提供的 OkHttp Util 类。

在最初的崩溃中,它说它无法在 classes2.dex 中找到方法。为什么要查看 classes2.dex?为什么不同时查看两者?

我将一切保留在我的测试apk中(使用proguard但保留一切)(也许这解释了+65k ref方法)。那么,为什么这首先会被剥离/搞砸。

更新:

事实证明我的应用程序 .apk(不是测试 .apk)需要这个方法。当我更新应用程序 apk 的 proguard 规则时,一切正常。我仍然不知道为什么应用内需要这个类?

最佳答案

java.lang.NoSuchMethodError:

No static method closeQuietly(java.net.ServerSocket) in class okhttp3.internal.Util;

方法 closeQuietly(java.net.ServerSocket) 可能未在使用中。

明确保留它:

-keep class okhttp3.internal.Util {
public static void closeQuietly(java.net.ServerSocket);
}

关于android - Android Gradle 插件测试 apk 生成器是否自动对我的测试 apk 进行多索引处理?如果是这样,为什么会生成 "NoSuchMethodError",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53233105/

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