gpt4 book ai didi

java - NoClassDefFoundError Proguard Activity

转载 作者:太空宇宙 更新时间:2023-11-04 13:52:19 25 4
gpt4 key购买 nike

我正在使用 Proguard 来混淆我的 Android 应用程序。除了一个 Activity 之外,一切都运行良好。

java.lang.NoClassDefFoundError: com.myapp.android.MediaActivity

当我不使用 Proguard 时,Activity 工作正常。我只在使用 Proguard 时遇到这个问题。

我的 Activity 已在 AndroidManifest 上声明,我的所有其他 Activity 都工作正常,我只在这个特定的 Activity 上遇到问题。

这是我的 Proguard 配置:

-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

-keep class com.myapp.android.MediaActivity { *; }

-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.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}

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

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

-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
public static <fields>;
}

-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}

# Also keep - Enumerations. Keep the special static
# methods that are required in enumeration classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}


# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

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

-keepclassmembers class **.R$* {
public static <fields>;
}

如您所见,我还添加了此特定行以尝试使其正常工作,但事实并非如此:

-keep class com.myapp.android.MediaActivity { *; }

编辑:以下是 MediaActivity 的导入:

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.myapp.android.fragment.places.FragmentSupportPlacesBase;
import com.myapp.android.fragment.grid.BaseCursorGridFragmentSupport;
import com.myapp.android.fragment.grid.SupportScreenShotCursorGridFragment;
import com.myapp.android.fragment.grid.SupportTimelineCursorGridFragment;
import com.myapp.android.model.Place;
import com.myapp.android.model.SelectedInfo;

import java.util.ArrayList;
import java.util.List;

有人知道为什么会发生这种情况以及如何解决这个问题吗?

最佳答案

感谢安东尼奥为我指明了正确的方向。我的 Activity 正在实现接口(interface) PlacesCallbacks(无缘无故)

public interface PlacesCallbacks{
void onPlaceSelected(long quadKey, short zoomLevel);
void onPlaceSelected(Place place);
}

但是此 Activity 中未使用此Interface,并且我的应用程序中的任何位置均未使用此Interface,并且实现的方法留空。

所以我猜 Proguard 删除了这个Interface,因为它没有在任何地方使用,但它是在我的Activity中实现的。

我所要做的就是删除Interface

关于java - NoClassDefFoundError Proguard Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30174638/

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