使用方法引用进行混淆后,会出现 NoSuchMethodError 崩溃

2023-11-28

编译&proguard之前的源代码:

public class IntentSession extends BaseIntentSession {
    @Override
    public void onResume() {
        super.onResume();
        mExecutor.exec(getIntent(), this::finish);
    }
}

编译 proguard 后的反编译代码:(使用 CFR 0_118 反编译)

public class a extends superA {

    public void e() {
        super.e();
        this.c.a(this.j(), b.a((a)this)); // the problematic code here
    }
}

现在是compile&proguard之后的关键代码,b类的反编译代码:

final class b implements c.a {
    private a a;

    b (a a1) {
        this.a = a1;
    }

    static /* synthetic */ b a(final a a) {
        return new b(a);
    }

    @LambdaForm.Hidden
    public void a() {
        this.a.finish();
    }
}

它仍然引用了finish()方法已经被混淆为m()由混淆者。

我希望引用 finish() 方法被混淆为 m(),但这不是正在发生的事情,这就是我的问题。

Proguard 没有警告我,它只会崩溃NoSuchMethodError在运行时一旦遇到错误的代码。所以不要告诉我添加一个混淆器配置,例如-不警告java.lang.invoke.*我尝试过但没有成功。

也许混淆时涉及的类的处理顺序是错误的,谁知道呢?

我不想添加@Keepfinish() 方法上的注释,这是一个糟糕的解决方案,我必须担心它并在将来小心使用方法引用,所以我正在寻找最好的解决方案。

以下是我的 gradle 配置:

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    classpath 'me.tatarka:gradle-retrolambda:3.4.0'
    classpath "com.fernandocejas.frodo:frodo-plugin:0.8.3"
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}

下面是我的proguard-rules.pro:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-ignorewarnings

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-dontwarn java.util.**
-keep class java.util.** {*; }

-dontwarn com.android.**
-keep class com.android.** { *; }

-dontwarn android.support.**
-keep class android.support.** { *; }

-keepattributes SourceFile, LineNumberTable

# end common config

##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }

-dontwarn com.google.gson.**
-keep class com.google.gson.** { *; }

-dontwarn com.baidu.util.audiocore.**
-keep class com.baidu.util.audiocore.** { *; }

# Application classes that will be serialized/deserialized over Gson
##---------------End: proguard configuration for Gson  ----------

# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

-keep public class * implements java.io.Serializable {*;}
# end Serializable

#  ----------------------------
-dontnote
-dontwarn com.xiaomi.push.service.XMPushService

#for speech sdk
-keep class com.orion.speech.** {*;}
-keep class com.orion.speech.audio.** {*;}
#end for speech sdk

#for xiaomi
-keep class PushReceiver {*;}
-keep class com.xiaomi.push.**{*;}
#end for xiaomi

#for retrofit
-dontwarn sun.misc.Unsafe
-dontwarn okio.**
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
#end for retrofit

#for lambda
-dontwarn java.lang.invoke.*
#end for lambda

#for okhttp
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
#end for okhttp

#for RxJava
-keep class rx.schedulers.Schedulers {
    public static <methods>;
}
-keep class rx.schedulers.ImmediateScheduler {
    public <methods>;
}
-keep class rx.schedulers.TestScheduler {
    public <methods>;
}
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
   long producerIndex;
   long consumerIndex;
}

-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode producerNode;
}

-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
# end for RxJava

#for bugly
-dontwarn com.tencent.bugly.**
-keep public class com.tencent.bugly.**{*;}
#end for bugly

#----------------android

# this indicate the case of using APIs higher than minSDK (API 8)
-dontwarn android.**

# ---------------------------------------

# TODO: can be reduce if we have more understanding about Service and AIDL
-keep public class android.service.notification.** {*;}

-keepattributes *Annotation*,EnclosingMethod
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}


-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepattributes *Annotation*,EnclosingMethod,Signature

-keep interface android.content.pm.**{*;}
-keep class android.content.pm.**{*;}
-keep class android.os.Process{*;}

-dontwarn com.android.internal.os.*

-keep class android.support.v4.os.**{*;}

-keepclassmembers class * {
    @android.support.v4 *;
}

# cmcm support
-keep class com.cmcm.support.jni.** { *; }

解决这些错误-keep不修复的是REAL痛苦,而我在这些问题上取得进展的唯一方法就是遵循以下策略:

  1. 找出在 proguard 周期的哪个阶段引入错误(缩小、优化或混淆)
  2. 添加/删除该步骤的例外情况,从最广泛的排除范围到最窄的排除范围,直到问题重新出现

E.G.

验证这是否是优化问题

  1. Add -dontoptimize而不是-optimizations字符串重建和测试
  2. 如果崩溃得到缓解,则向后处理最高级别的优化排除类别!method/*, !code/*, !class/*, !field/*直到您确定哪种排除可以解决问题
  3. 确定该排除类别中的最小排除是什么(假设它是!method/*,从它去!method/marking/*然后如果这也有效尝试!method/marking/final。如果有效,那么您就找到了最小排除)

这很可能是Proguard 规则中的一个错误您正在使用的库之一或在您使用的 Proguard 版本中(我都看过)所以也尝试更新两者。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用方法引用进行混淆后,会出现 NoSuchMethodError 崩溃 的相关文章

随机推荐

  • 查找字符串中子字符串的出现次数

    为什么以下算法不会对我停止 在下面的代码中 str是我正在搜索的字符串 并且findStr是我要查找的字符串出现次数 String str helloslkhellodjladfjhello String findStr hello int
  • scipy.sparse 默认值

    稀疏矩阵格式 dok 假设不在字典中的键的值等于零 有什么办法让它使用除零之外的默认值吗 另外 有没有办法计算稀疏矩阵的对数 类似于常规 numpy 矩阵中的 np log 该功能不是内置的 但如果您确实需要此功能 您应该能够编写自己的功能
  • 使用 javascript 模拟文档上的点击

    是否可以使用 javascript 模拟网页上的点击 但无需定义特定元素 而只是指定文档 我本来想做这样的事情 如果该位置碰巧有一个链接 那么就会按下这个 function simulateClick x y var evt window
  • Spark Streaming中batch间隔、滑动间隔和窗口大小的区别

    我是新火花流 我知道窗口大小需要是批处理间隔的倍数 但滑动区间是如何运作的呢 如果我有 3 作为窗口大小 2 作为滑动间隔 那么当我计算字数时不会有重叠吗 或者滑动间隔和批次间隔应该相同吗 Here是文档的链接 让我们来看看这些概念 批次间
  • 从 shell 脚本编辑属性文件中的属性值

    标题说明了一切 我需要将我不知道的属性值替换为不同的值 我正在尝试这个 bin bash sed i s myprop myprop newvalue g file properties i get sed e expression 1 c
  • C# 中的 ref 和 out 与 C++ 中的指针相同吗?

    我刚刚用 C 创建了一个交换例程 如下所示 static void Swap ref int x ref int y int temp x x y y temp 它与此 C 代码执行相同的操作 void swap int d1 int d2
  • Windows 如何创建目录符号链接

    我正在尝试创建指向 Windows 8 1 目录的符号链接 使用 git bash 命令窗口以管理员身份运行 具有如下文件夹结构 magento plugin magento 我的插件是一个 git 存储库 我想将其符号链接到 magent
  • 列出Oracle中给定用户的所有表

    我是 Oracle 新手 想要查找用户 john 创建的所有表 我通过命令行连接到 Oracle 数据库 命令如下 sqlplus john passwd 如何列出给定用户创建的所有表 例如约翰 这将获取 JOHN 用户是所有者的所有表 S
  • Platform::String 真的那么没用吗?

    我正在尝试在 Windows Store 又名 Metro Style 应用程序中用 C CX 编写几行代码 我惊讶地发现平台 字符串缺少许多基本的字符串操作 例如 代替 or 指数 我想我可以使用内部数据 将其传递给 std string
  • 将 Access DB 表加载到数据表

    我有一个 ACCDB 格式的数据库 其中包含一些表 我使用以下代码成功将其加载到 OleDbDataReader 中 string connectionString Provider Microsoft ACE OLEDB 12 0 dat
  • Eclipse 插件的延迟激活

    我想知道 Eclipse 清单编辑器中的 加载其类之一时激活此插件 复选框有何用处 我认为 Eclipse 总是使用 延迟初始化 方法 这个选项与插件的 BundleActivator 类有关系吗 初始化与激活有什么不同吗 Here是一个类
  • 我可以在配备英特尔高清显卡的笔记本电脑上实现深度学习模型吗

    我目前正在为我的硕士学位做一个关于深度学习的项目 我想安装 keras 库 所以当我开始安装 Theano 和 tensorflow 时 我发现我必须安装 CUDA 但我的笔记本电脑配备了英特尔高清显卡 所以我的问题是 如果我安装它们 它会
  • Nuxt.js - 在所有网址末尾强制添加斜杠

    我正在寻找一种方法来确保我的所有网址都以尾随斜杠结尾 因此首先检查末尾是否已经有尾随斜杠 如果没有则添加一个 我尝试过nuxt 重定向模块 它可以添加斜杠 但随后会导致无限重定向 redirect from to from req gt l
  • Internet Explorer、Json.Net JavaScript 日期和毫秒问题

    我不确定是否是我遗漏了某些东西 或者 IE 或 Json Net 但基本上这是有效的 new Date 2012 08 03T12 36 54 743Z 此操作失败并出现 无效日期 错误 new Date 2012 08 03T12 36
  • Xcode - 警告:函数的隐式声明在 C99 中无效

    收到警告 函数 Fibonacci 的隐式声明在 C99 中无效 怎么了 include
  • 在 Windows Azure 上运行 Fleck(或任何)Websocket 服务器

    我想在 Azure 中以辅助角色运行 WebSocket 服务器 这在模拟器本地工作得很好 但是第一次运行套接字服务器时会出现 Windows 防火墙提示 我想知道是否有人知道如何克服 Azure 上套接字的连接问题 我的套接字服务器实现
  • 从嵌套文件夹导入模块[重复]

    这个问题在这里已经有答案了 我有这样的文件夹结构 main folder done test1 init py check py init py class Tries object def init self print Test 检查
  • 如何在 iframe 中查找 div

    我正在尝试使用 jquery 在 iframe 中查找 div 有没有比我下面使用的方法更好的方法 Iframe contents find MyDiv function atmslidein customer ready function
  • Flex 的 FXG 编辑器

    我见过的唯一适用于 Flex 的 FXG 编辑器是由 7jigen 制作 在线工作或 作为 Flex 应用程序 有人知道另一种吗 我认为它可以在 Illustrator 中完成 但这并没有真正提供简单的导出到 Flex 类型选项 只是给出坐
  • 使用方法引用进行混淆后,会出现 NoSuchMethodError 崩溃

    编译 proguard之前的源代码 public class IntentSession extends BaseIntentSession Override public void onResume super onResume mExe