I have to display some data from database even after un-install the app. For that I am writing script for that insert operations. And at Re-installation I am executing that script saved on sdcard with db.execSQL(toExec); statement. Using following code snipt
//write code to execute script from file
SQLiteDatabase db = helper.getWritableDatabase();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(Constants.DIR_PATH+"/"+Constants.SCRIPT_FILE_NAME));
String line;
while((line = reader.readLine())!=null)
{
line.trim();
AppLog.d(TAG, "Execute script with line: "+line);
try
{
db.execSQL(line);
}
catch(SQLiteException e)
{
AppLog.d(TAG, "Sqlite Excp with Line: "+line+e);
}
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
AppLog.d(TAG, "File Not Found to execute Script"+e1);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
This works fine in normal build. But insertion is not done in Proguard build. Also note that for Database operations I am using ORMLite. And at the time of executing script database is already created
I have added following properties in proguard-project.txt
-keep class com.j256.**
-keepclassmembers class com.j256.** {
*;
}
-keep public class android.database.sqlite.**
I can not figure out what is happening.
Please help...
I found that DB classes and other fields are being renamed by Proguard. As @jim commented. So I added following configuration statements in proguard-project.txt file to resolved issue
-keep class com.db.models.**
-keepclassmembers class com.db.models.** { *; }
where com.db.models is a package name where your database entity classes are saved.