Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android App crashes only with release APK

Tags:

android

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;
}

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

Database looks like that:

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

Gradle Snippet:

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?

like image 641
yvi Avatar asked Sep 01 '25 04:09

yvi


2 Answers

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'
}
}

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

like image 58
yvi Avatar answered Sep 07 '25 16:09

yvi


Except for the SQLite, you can check proguard-rules.pro file, it maybe makes release.apk crash. if you want to lean more, click https://developer.android.com/studio/build/shrink-code.html

like image 35
chen Avatar answered Sep 07 '25 15:09

chen