问题描述
限时送ChatGPT账号..我有一个奇怪的问题.我构建了一个在调试模式下运行良好的应用程序(直接调试到我的手机并在我的手机上安装了调试 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;
}
如果我删除 Cursor 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 '');
Gradle 代码段:
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?
推荐答案
我在 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'
}
}
未创建表完成",因为我试图将两个表创建语句放入单个 db.execSQL()
Table "done" was not created because I tried to put two table create statements into a single db.execSQL()
这篇关于Android 应用仅在发布 APK 时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论