Android app crashes after generating signed apk - android

UPDATE:
When I delete app storage, it starts to work. I don´t understand...
When I generate a signed APK for my project and I install it to my phone, app crashes.
When I debug the app, it works correctly.
I use Android Studio 3 and I disabled instant run.
Using logcat, I get the following exception:
2019-01-15 19:19:30.594 7317-7317/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: me.agomezgz.bng.programa, PID: 7317
java.lang.RuntimeException: Unable to start activity ComponentInfo{me.agomezgz.bng.programa/me.agomezgz.bng.programa.SplashActivity}: android.database.sqlite.SQLiteException: no such table: comentario (code 1 SQLITE_ERROR):  

it complains about no such table: comentario ...which means that table comentario had not been previously created - and that the stack-trace is just a follow-up error. see the build output for the ProGuard warnings (or even add them to the question); there might something obfuscated, which should not have been obfuscated. the code of the database class is completely irrelevant (simply because it works, while not being obfuscated); only the build-log matters. adding -verbose into the ProGuard configuration might help to obtain some more details.

UPDATE: When I delete app storage, it starts to work. I don´t understand...
You had an earlier version of the database file around that did not have that table. Clearing app storage removed the database file and forced sqlite helper onCreate() to run again.
See When is SQLiteOpenHelper onCreate() / onUpgrade() run?
Why it worked in debug is that the debug package is another application id and has a separate private directory where the database files are stored. That database file did not have this problem.

change your database onCreate method to this :
db.execSQL("CREATE TABLE IF NOT EXISTS comentario(_id integer,
nome text not null,
correo text not null,
texto text not null,
idLoc integer not null, primary key (_id));");

Related

Room Database migration crash

I have an DB migration:
val MIGRATION_8_9 = object : Migration(8, 9) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE RideEntity RENAME frontVideoPresent TO frontVideoState")
database.execSQL("ALTER TABLE RideEntity RENAME rearVideoPresent TO rearVideoState")
}
}
When testing this migration on local Samsung phones it worked fine. The in production with help of craslytics I seen this crash:
Fatal Exception: java.lang.RuntimeException
Exception while computing database live data.
Caused by android.database.sqlite.SQLiteException
near "frontVideoPresent": syntax error (Sqlite code 1 SQLITE_ERROR): , while
compiling: ALTER TABLE RideEntity RENAME frontVideoPresent TO frontVideoState, (OS
error - 11:Try again)
This is happened on Huawei Mate 20 phone. How to understand better this crash? This is OS related?
I can not remove the rename now, because many users that updated the app the column renaming worked, but users with Huawei phones may suffer this crash.
I am open to your suggestions...
Looks like version of sqlite on some devices doesn't support column renaming because android app use build-in version on sqlite library to android OS. That's why version of sqlite depends on android's api level version (where app running). According to sqlite release notes (paragraph 2) the support for renaming columns was added in version 3.25.0 and according to google docs (and other answer on stackoverflow)the column's renaming on android supports since android api level 30.
To solve the problem of fragmentation of slqlite library you can use android-requery which allows to use last version of sqlile in all android versions(since API level 14). It's easy to use this library with room.

Unable to update database in android using SQLiteAssetHelper

I'm using SQLiteAssetHelper. I tried to upgrade the database by adding few insertions into the testdb.db file then according to instructions on
https://github.com/jgilfelt/android-sqlite-asset-helper
I renamed this new file to testdb.db_upgrade_1-2.sql and added to the asset folder in the android app. I changed the database version to 2 in the Databasehandler, but still there is an error as shown in the stacktrace which is as follows
I/SQLiteAssetHelper: successfully opened database testdb.db
W/SQLiteAssetHelper: Upgrading database testdb.db from version 1 to 2...
W/SQLiteAssetHelper: processing upgrade: databases/testdb.db_upgrade_1-2.sql
E/SQLiteLog: (1) near "SQLite": syntax error
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
After this the app crashes.
My asset folder contains both /databases/testdb.db
and /databases/testdb.db_upgrade_1-2.sql
I'm using sqlite3 on my computer to generate the database file
I renamed this new file to testdb.db_upgrade_1-2.sql
That is incorrect. testdb.db_upgrade_1-2.sql is supposed to be a text file containing SQL statements to apply to your schema v1 database to convert it into a schema v2 database.
Quoting the documentation, with emphasis added:
Update the initial SQLite database in the project's assets/databases directory with the changes and create a text file containing all required SQL commands to upgrade the database from its previous version to it's current version and place it in the same folder.

SQLiteException not an error at net.sqlcipher.database.SQLiteDatabase.dbopen(Native Method)

I am facing an issue while running the junit test cases in android studio.
The issue is very strange as when I run the test cases for the first time in the phone it works perfectly fine, but if the app is already installed and when I run the test cases I get following error:-
net.sqlcipher.database.SQLiteException: not an error
at net.sqlcipher.database.SQLiteDatabase.dbopen(Native Method)
at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1942)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:875)
at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:907)
at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:132)
at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:99)
All the sqlcipher dependencies are correctly configured.
The database might not be properly closed after you run your app the first time. Try using Close method from SQLiteConnection class:
db.Close()
I found the solution for this issue.
When I saw in the logs, I found that the actual issue was
Unable to copy icudt46l.zip file
It was happening because i was not calling the loadlibs of SQLiteCipher inside the test suites.
So I added the following line in setup() method of my test class
SQLiteDatabase.loadLibs(getContext(), getContext().getFilesDir());

SQLite-db corrupt only on Android 2.2

I'm using this method to copy a pre-existing sqlite-database from my assets-directory to the app's /databases/-directory on the first app launch. This works fine on emulators with different SDK-levels and on my 4.4 devices, but fails on a 2.2.2 device with the following logcat message:
sqlite returned: error code = 11, msg = database corruption found by source line 40107
and further on SELECT locale FROM android_metadata failed
There are other SO-questions with this error, but my database definitely contains an android_metadata-table with a locale column and an en_US entry (which is why the app works on many other emulators and higher-SDK devices) and isn't large (32KB), which I read can be an issue.
Update: I switched to using the SQLiteAssetHelper-library, but am still getting the same error:
copying database from assets...
database copy complete
sqlite returned: error code = 11, msg = database corruption found by source line 40107
sqlite returned: error code = 11, msg = database disk image is malformed
CREATE TABLE android_metadata failed
Failed to setLocale() when constructing, closing the database
It seems the SQLiteOpenHelper (not the AssetHelper) is trying to create the android_metadata table (even though it's already present) and fails because of this?
Update 2: The full stacktrace can be found here
and add a new android_metadata-table with a locale-column and an en_us-row
Now that you are using SQLiteAssetHelper, and given the error message (CREATE TABLE android_metadata failed), remove your manual android_metadata table from your packaged copy of the database. This will be created for you as part of unpacking the database via SQLiteAssetHelper.

Content Provider Resources$NotFoundException

Created a profile using content provider. After running it correctly, added 3 fields to the table. But now its not working correctly.It shows an error like android.content.res.Resources$NotFoundException: String resource ID #0x4d2.Any solution?
If you are using Eclipse, try to do Project|Force Clean. If you are working outside of Eclipse, run ant clean. Your error message is probably because your resources, the generated R.java file, and some of your other compiled code are collectively out of sync.

Categories

Resources