0

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...

HemangNirmal
  • 621
  • 1
  • 8
  • 24

2 Answers2

3

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.

HemangNirmal
  • 621
  • 1
  • 8
  • 24
0

Just in case if someone still comes to this page, here is my experience. It took me a half a day to figure it out.

I am using a map html file from the assets folder that is getting data (markers) from a sqlite db. The map (html) displayed correctly, but the data got messed up by proguard, so the markers did not show.

You basically need to keep everything that is involved in the data processing from the database. Every class and their private and public stuff. Here is the whole lot from my proguard file:

-keep public class au.com.yourpackage.LocJavaScriptInterface
-keepclassmembers class au.com.yourpackage.LocJavaScriptInterface {
   public *;
   private *;
}
-keepattributes JavascriptInterface

-keep public class au.com.yourpackage.MyLocationsDbHelper
-keepclassmembers class au.com.yourpackage.MyLocationsDbHelper {
   public *;
   private *;
}

-keep public class au.com.yourpackage.MyLocationsListAdapter
-keepclassmembers class au.com.yourpackage.MyLocationsListAdapter {
   public *;
   private *;
}

-keep public class au.com.yourpackage.MyLocationsModel
-keepclassmembers class au.com.yourpackage.MyLocationsModel {
   public *;
   private *;
}

I hope it helps.

Immy
  • 631
  • 1
  • 5
  • 15