【问题标题】:Shrink Android make CrashShrink Android 使 Crash
【发布时间】:2020-02-28 11:12:32
【问题描述】:

我已经升级了 Android Studio。

因此,将其升级到最新版本后,我更新了我的应用程序: "shrinkResources true""minifyEnabled true"

不幸的是,我在某些设备上崩溃了,没有缩小一切都可以完美运行。

以下是崩溃日志:

java.lang.RuntimeException: 

  at android.os.AsyncTask$3.done (AsyncTask.java:354)
  at java.util.concurrent.FutureTask.finishCompletion (FutureTask.java:383)
  at java.util.concurrent.FutureTask.setException (FutureTask.java:252)
  at java.util.concurrent.FutureTask.run (FutureTask.java:271)
  at android.os.AsyncTask$SerialExecutor$1.run (AsyncTask.java:245)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
  at java.lang.Thread.run (Thread.java:764)
Caused by: java.lang.ClassCastException: 
  at android.app.SharedPreferencesImpl.getInt (SharedPreferencesImpl.java:302)
  at com.testApp.preference.WallpaperPreference.getLWPDay (WallpaperPreference.java:66)
  at com.testApp.managerLWP.GetLWP.downloadHouseAds (GetLWP.java:64)
  at com.testApp.managerLWP.GetLWP.doInBackground (GetLWP.java:40)
  at com.testApp.managerLWP.GetLWP.doInBackground (GetLWP.java:22)
  at android.os.AsyncTask$2.call (AsyncTask.java:333)
  at java.util.concurrent.FutureTask.run (FutureTask.java:266)

下面是发生崩溃的名为WallpaperPreference 的类。

public class WallpaperPreference {
private Context context;
private SharedPreferences sharedPreferences;

public WallpaperPreference(Context context) {
    this.context = context;

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
}

public void setLWPDay(int value) {
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putInt(Base.LWP_JSON_DAY, value);
    editor.apply();
}

public int getLWPDay() {
    return sharedPreferences.getInt(Base.LWP_JSON_DAY, 0);
}

}

我用过:

compileSdkVersion 29
buildToolsVersion '29.0.3'

可能的解决方案是什么?谢谢。

【问题讨论】:

  • 您是否为您的应用设置了shrinking 的proguard 规则。如果没有,那就是您解决此问题的起点。检查媒体上的this article 是否有帮助

标签: android android-studio exception classcastexception


【解决方案1】:
  1. 在发布模式下添加“debuggable true”

  1. 将 proguard-android-optimize proguard 更改为“proguard-android”

它对我有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 2020-11-11
    相关资源
    最近更新 更多