Android App仅在发布APK时崩溃 [英] Android App crashes only with release APK

查看:87
本文介绍了Android App仅在发布APK时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题.我构建了一个在调试模式下可以正常运行的应用程序(直接调试手机并在手机上安装了调试APK),但是如果我使用发布版本的APK,则该应用程序会在某一时刻崩溃.我发现该应用因发布APK而崩溃的地步,但我不知道为什么以及我能做什么:

I have a curious issue. I built an app that works fine in debug mode (direkt debugging to my phone and with debug APK installed on my phone) but the app crashes at one point if I use the release build APK. I found the point where the app crashes with release APK, but I don't know why and what I can do:

protected final String TABLE = "done";
protected final String COL_ID = "_id";
protected final String COL_TASK = "taskid";
protected final String COL_DATE = "donedate";

protected String getLastDoneDate(String id) {
    String date = "";

    String filter = COL_TASK + " LIKE ?";
    String[] filterArgs = new String[] {id};
    String sortOrder = COL_DATE + " DESC";
    String[] columns = new String[] {COL_DATE};
    Cursor c = MyTime.db.query(TABLE, columns, filter, filterArgs, null, null, sortOrder, "1");
    if (c.moveToFirst()) {
        date = c.getString(c.getColumnIndex(COL_DATE));
    }
    c.close();

    return date;
}

如果我删除游标c = ...(以及所有根据c组成的行),它将起作用.

If I remove the line Cursor c = ... (and all according to c) it works.

数据库如下所示:

CREATE TABLE IF NOT EXISTS done (
                _id INTEGER PRIMARY KEY autoincrement,
                taskid INTEGER,
                donedate TEXT DEFAULT '');

成绩段:

buildTypes {
    release {
        shrinkResources false
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        shrinkResources false
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

我无法调试以查找问题,因为在调试时不会发生崩溃.

I can not debug to find the problem because the crash does'nt happen while debugging.

有人可以帮我解决这个问题吗?

Can somebody help me to solve this issue?

推荐答案

我在gradle文件中添加了debuggable = true,并找到了造成问题的原因.

I added debuggable = true to my gradle file and found the reason of my problem.

buildTypes {
release {
    shrinkResources false
    debuggable true
    minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
    shrinkResources false
    minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

未创建表完成",因为我试图将两个表create语句放入单个db.execSQL()

Table "done" was not created because I tried to put two table create statements into a single db.execSQL()

这篇关于Android App仅在发布APK时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆