收缩 Android 使崩溃
Shrink Android make Crash
我已经升级了 Android Studio。
因此,在将其升级到最新版本后,我更新了我的应用程序:
"shrinkResources true"
、"minifyEnabled true"
不幸的是,我在某些设备上崩溃了,没有收缩一切正常。
以下是崩溃日志:
java.lang.RuntimeException:
at android.os.AsyncTask.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.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.call (AsyncTask.java:333)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
下面是发生崩溃的名为 WallpaperPreference
的 class。
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'
可能的解决方案是什么?谢谢。
- 在发布模式中添加"debuggable true"
或
- 更改proguard-android-将proguard优化为"proguard-android"
它适合我
我已经升级了 Android Studio。
因此,在将其升级到最新版本后,我更新了我的应用程序:
"shrinkResources true"
、"minifyEnabled true"
不幸的是,我在某些设备上崩溃了,没有收缩一切正常。
以下是崩溃日志:
java.lang.RuntimeException:
at android.os.AsyncTask.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.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.call (AsyncTask.java:333)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
下面是发生崩溃的名为 WallpaperPreference
的 class。
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'
可能的解决方案是什么?谢谢。
- 在发布模式中添加"debuggable true"
或
- 更改proguard-android-将proguard优化为"proguard-android"
它适合我