gpt4 book ai didi

库模块中的 lamdas 的 Android Proguard 问题

转载 作者:行者123 更新时间:2023-12-01 05:52:24 30 4
gpt4 key购买 nike

我有一个 android 项目,它依赖于一个库模块。我的模块中有一个这样的接口(interface):

   public interface SimpleAnimationListener extends Animation.AnimationListener {
@Override
default void onAnimationStart(Animation animation) {
onAnimation(Type.START);
}

@Override
default void onAnimationEnd(Animation animation) {
onAnimation(Type.END);
}

@Override
default void onAnimationRepeat(Animation animation) {
onAnimation(Type.REPEAT);
}

void onAnimation(Type type);

enum Type {
START,
END,
REPEAT
}
}

用法:
public static void fadeViewOut(@NonNull View view, int duration) {
view.setVisibility(View.VISIBLE);
AlphaAnimation anim = new AlphaAnimation(1.0f, 0.0f);
anim.setDuration(duration);
anim.setAnimationListener((SimpleAnimationListener) type -> {
if (type == SimpleAnimationListener.Type.END) {
view.setVisibility(View.INVISIBLE);
}
});
view.startAnimation(anim);
}

每当我在我的应用项目中使用这个接口(interface)时。我得到以下异常:
FATAL EXCEPTION: main
java.lang.AbstractMethodError: abstract method not implemented
at Zt.onAnimationStart(lambda)

在我的 mappings.txt 我有这个:
com.example.mymodule.interfaces.SimpleAnimationListener -> Wt:
<...>
com.example.mymodule.utils.-$$Lambda$AnimationUtils$rrH5aPAPZuoC__1-9DiD10TFdgY -> Zt:
android.view.View f$0 -> a

尝试将以下内容添加到 proguard-rules.pro
-keep public class com.example.mymodule.utils.AnimationUtils
-keep public interface com.example.mymodule.interfaces.SimpleAnimationListener

然后在我的映射中我会得到:
com.example.mymodule.interfaces.SimpleAnimationListener -> com.example.mymodule.interfaces.SimpleAnimationListener:
<...>
com.example.mymodule.utils.-$$Lambda$AnimationUtils$rrH5aPAPZuoC__1-9DiD10TFdgY -> Yt:
android.view.View f$0 -> a

这也会失败。但错误会指向 .如果我停止使用覆盖某些方法的接口(interface),则应用程序正在工作,但由于原始接口(interface)有多种方法,我不能将 lamdas 与它们一起使用。关于如何解决这个问题的任何想法?

最佳答案

你也保留枚举吗?
因为我们不想正确剥离枚举。

如果没有尝试以下
-keepclassmembers enum * { *; }
-keep public class com.example.mymodule.utils.AnimationUtils { *; }
-keep public interface com.example.mymodule.interfaces.SimpleAnimationListener { *; }

关于库模块中的 lamdas 的 Android Proguard 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52681685/

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