PerferenceActivity with PreferenceFragment does not work on device with proguard in order without proguard

I am coding my first application targeting ICS (4.0.3 - level 15). I get Action Bars and I think they are great. But this is the first time I'm doing fragments, and I'm still not sure whether they like it or not. The application I'm working on now does not need fragments, as it has quite non-dynamic screen requirements. Standard actions work fine. The big thing, however, is that I have to use PreferenceActivity with PreferencFragment and Headers. The old form of activity right in the preferences xml definition file has been discounted. Therefore, I learned to use preference fragments to display settings using Google. (By the way, did someone understand how to skip heading headers. I used two for training. One pointing to one class of fragment would be enough. But it looks bad that you need to select twice with only one heading ..)

I use the emulator up to 3 days ago and everything works. When I moved the testing to the device, I was able to get the settings screen displaying the headers (PreferenceActivity class). But when I selected the title (which calls the PreferencesFragment class), I received the message "sorry, your application is stopped." Everything worked correctly on the emulator. Finally, I realized that I use Proguard when I create the APK. Since all the views were due to standard actions, except for the activity in the settings, most of them worked. When I turned off Proguard, everything worked, including Settings. In my Crittercism crash report, the error that occurs when you turn on Proguard is not a class. Class not found - this is the built-in class PreferenceFragment.

For example, using the header

android:fragment="com.mycompany.projectname.FragmentPreferences$SettingsFragment" 

the built-in SettingsFragment class was not found in the Android OS running on the device.

Disable Proguard and reinstall the APK, and the above header works fine. With or without Proguard, the FragmentPreferences class of the PreferenceActivity class is always displayed and the headers are displayed. It does not work when selecting the displayed header (invokation of SettingsFragment) ...

I tried -dontoptimize and -dontshrink, but my application still does not work with Proguard. My Proguard settings are standard; those. generated when I create a new application using the Eclipse wizard (ADT R20 is the latest and largest). Here are the settings I'm trying to do with:

In the project properties:

 proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt target=Google Inc.:Google APIs:15 In proguard-project: -keepattributes SourceFile, LineNumberTable -dontshrink -dontoptimize 

All standard actions (without fragments) work fine with the basic settings. -dont were added in an attempt to restrict Proguard to obfuscation only. The settings are still bloated when the inline fragment class is called.

I am currently creating an APK with Proguard turned off. When I am ready to go into production, I would like to turn it back on.

(BTW, I have moved the PreferenceFragment classes to external classes, and they still don't work when Proguard is called.)

I have entered more than enough here, and still have not asked my question. Ok, I will cover this with a question:

Does anyone know the correct Proguard settings needed to make shared preference partition classes visible? And if this problem extends to using a regular fragment, what are these settings?

+4
android android-fragments proguard android-preferences
Jul 20 '12 at 17:13
source share
2 answers

I would use -keep class your.package.goes.here.** { *; } -keep class your.package.goes.here.** { *; } so that ProGuard does not get rid of any of your own classes, including your snippets referenced by layouts or other resources instead of code.

Please note that I am not a ProGuard expert, and therefore it may be a "cheat fly with Buick", but it works for me, including my PreferenceFragments .

+5
Jul 20 '12 at 17:16
source share

Make changes to proguard-project.txt as

 -keep public class * extends android.preference.Preference -keep public class * extends android.preference.PreferenceFragment -keep public class * extends android.preference.PreferenceActivity 
+1
Aug 19 '14 at 6:29
source share



All Articles