AndroidStudio 2.0 预览生成的 APK 在 Dalvik 上显示错误

AndroidStudio 2.0 preview generated APK shows error on Dalvik

来自 AudioPlayService class onCreate() 我在第 168 行调用以下代码。-

line168- CustomAuxEffectStats aa = CustomAuxEffectStats.getInstance();
    if (aa == null) {
        createCustomAuxEffect();
    }

CustomAuxEffectStats class-

public class CustomAuxEffectStats implements Serializable {
    private static CustomAuxEffectStats customAuxEffectStats = null;
    public static int CustomPresetID = -100;

    public static final int DEFAULT_BASS_BOOST_STRENGTH = 900;

    private boolean isEnabled;

    private int numBands;
    private int actualNumPreset;

    private short selectedPreset;
    private short minBandLevel;
    private short maxBandLevel;
    private short bassboostStrength;

    private short[] bandLevels;

    private String[] bandFreq;
    private String[] presetNames;

    private CustomAuxEffectStats(short curPreset, String[] presetNamesArr, String[] bandFreqs, short[] bandLevelRange, short[] bandlevels, boolean isEnabled) {
        this.isEnabled = isEnabled;
        selectedPreset = curPreset;

        minBandLevel = bandLevelRange[0];
        maxBandLevel = bandLevelRange[1];

        numBands = bandlevels.length;

        bandFreq = bandFreqs;

        actualNumPreset = presetNamesArr.length - 1;
        CustomPresetID = presetNamesArr.length;

        presetNames = presetNamesArr;

        this.bandLevels = bandlevels;
        bassboostStrength = 1000;
    }

    public static CustomAuxEffectStats getInstance() {
        return customAuxEffectStats;
    }

    public static CustomAuxEffectStats createInstance(short curPreset, String[] presetNamesArr, String[] bandFreqs, short[] bandLevelRange, short[] bandlevels, boolean isEnabled) {
        if (customAuxEffectStats == null) {
            customAuxEffectStats = new CustomAuxEffectStats(curPreset, presetNamesArr, bandFreqs, bandLevelRange, bandlevels, isEnabled);
        }
        return customAuxEffectStats;
    }

    public boolean isEnabled() {
        return isEnabled;
    }

    public void setEnabled(boolean isEnabled) {
        this.isEnabled = isEnabled;
    }

    public int getNumBands() {
        return numBands;
    }

    public void setNumBands(int numBands) {
        this.numBands = numBands;
    }

    public short getSelectedPreset() {
        return selectedPreset;
    }

    public void setSelectedPreset(short selectedPreset) {
        this.selectedPreset = selectedPreset;
    }

    public short getMinBandLevel() {
        return minBandLevel;
    }

    public void setMinBandLevel(short minBandLevel) {
        this.minBandLevel = minBandLevel;
    }

    public short getMaxBandLevel() {
        return maxBandLevel;
    }

    public void setMaxBandLevel(short maxBandLevel) {
        this.maxBandLevel = maxBandLevel;
    }

    public short[] getBandLevels() {
        return bandLevels;
    }

    public void setBandLevels(short[] bandLevels) {
        this.bandLevels = bandLevels;
    }

    public String[] getBandFreq() {
        return bandFreq;
    }

    public void setBandFreq(String[] bandFreq) {
        this.bandFreq = bandFreq;
    }

    public static int getCustompresetid() {
        return CustomPresetID;
    }

    public short getBassBoostStrength() {
        return bassboostStrength;
    }

    public void setBandLevel(short band, short progress) {
        bandLevels[band] = progress;
    }

    public short getbandLevel(short band) {
        return bandLevels[band];
    }

    public int getNumberOfPresets() {
        return actualNumPreset;
    }

    public String[] getPresetNames() {
        return presetNames;
    }

    public void setPresetNames(String[] presetNames) {
        this.presetNames = presetNames;
    }

    public void setBassboostStrength(short bassboostStrength) {
        this.bassboostStrength = bassboostStrength;
    }
}

当我 运行 我的应用程序时,这总是在 kitkat(dalvik 运行 时间)设备上崩溃。 但它在 L+(ART) 设备和模拟器中运行良好。

错误日志-

FATAL EXCEPTION: main Process: com.newwave.musicsquare, PID: 26143 java.lang.VerifyError: com/newwave/musicsquare/audio/data/CustomAuxEffectStats at com.newwave.musicsquare.services.AudioPlayService.onCreate(AudioPlayService.java:168) at android.app.ActivityThread.handleCreateService(ActivityThread.java:2574) at android.app.ActivityThread.access00(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5113) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) at dalvik.system.NativeStart.main(Native Method)

所以我想通了.. 当我维护这个遗留项目时.. 序列化的 class CustomAuxEffectStats 在构造函数中有很多参数导致问题,还有很多 getters、setters... 我删除了方法并将所有字段设置为 class 级别。 从构造函数中删除所有参数... 一切正常。