gpt4 book ai didi

android - fragment 计数无法按预期使用 ProGuard

转载 作者:行者123 更新时间:2023-11-29 17:01:13 28 4
gpt4 key购买 nike

我的 AppCompatActivity 上有一个函数,它确定 fragment 列表中 fragment 的数量 - 下面是代码:

if (getSupportFragmentManager().getBackStackEntryCount() > 0) {

List<Fragment> fragmentList = getSupportFragmentManager().getFragments();

if (fragmentList != null) {
for (Fragment fragment : fragmentList) {
if (fragment != null) {
if (fragment.getClass().getSimpleName().equals("SelfCBaseFragment")) {

if (fragment.getChildFragmentManager().getBackStackEntryCount() > 1) {
fragment.getChildFragmentManager().popBackStack();

} else {
getSupportFragmentManager().popBackStack();
hideActionBar();
}
} else if (fragment.getClass().getSimpleName().equals("ABCFragment")) {

getSupportFragmentManager().popBackStackImmediate();
} else {
MyLog.d("FragmentName:", fragment.getClass().getSimpleName());
getSupportFragmentManager().popBackStack();
}
}

}
}
} else {
hideActionBar();
}

代码在调试时完美运行,即 ProGuard 关闭。但是当导出已签名的 APK 时,它没有按预期工作,即它没有命中 hideActionBar。当我回到初始屏幕时,我可以看到 hideActionBar() 没有被调用。我需要再次在操作栏中单击返回,然后它会隐藏操作栏。任何提示可能是什么原因造成的?

我的 ProGuard 文件中是否缺少我需要添加的内容?

附加的 ProGuard 文件:

# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}


## Square Picasso specific rules ##
## https://square.github.io/picasso/ ##

-dontwarn com.squareup.okhttp.**
#json
# gson
-keepattributes *Annotation*
-keepattributes Signature
-keepattributes Exceptions

# Gson specific classes
-keep class sun.misc.Unsafe { *; }

-keep class com.flurry.** { *; }
-dontwarn com.flurry.**
-keepattributes *Annotation*,EnclosingMethod
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**
-dontwarn android.support.**

-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
@butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}

-assumenosideeffects class android.util.Log {
public static boolean isLoggable(java.lang.String, int);
public static int v(...);
public static int i(...);
public static int w(...);
public static int d(...);
public static int e(...);
}

最佳答案

这是使用 Proguard 和类名的预期行为。你在做:

fragment.getClass().getSimpleName().equals("MyFragmentClassName")

但是MyFragmentClassName是用Proguard改变的,所以如果要解析原来的类名就得保留。

最优化的版本是只保留需要它的类的名称。在这种特定情况下,您必须添加到您的 Proguard 文件中:

-keepnames package.of.this.fragment.SelfCBaseFragment
-keepnames package.of.this.other.fragment.ABCFragment

关于android - fragment 计数无法按预期使用 ProGuard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42874199/

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