PerferenceActivity with PreferenceFragment fails on device with proguard okay without proguard
<p>I'm coding my first app targeting ICS (4.0.3 - level 15). I get Action Bars and I think they're great. But I'm trying fragments for the first time, and I'm still not sure if I like 'em or not. The app I'm currently working on doesn't need fragments since it has pretty undynamic on screen requirements. Standard activities are working fine. The big However is that I have to use PreferenceActivity with PreferencFragment and Headers. The old form of the activity straight to the preference definition xml file has been depreciated. So I learned to use preference fragments for the preferences display by force of Google. (By the way, has anybody figured out how to skip displaying headers. I used two for a learning experience. One pointing to a single fragment class would have been sufficient. But it looks bad to have to double select with only one header...)</p>

<p>I have been using the emulator thing until about 3 days ago and everything was working. When I moved testing to the device, I could get the preferences screen that displayed the headers (PreferenceActivity class). But, when I selected a header (which calls the PreferencesFragment class), I received the "sorry your app stopped' message. Back on the emulator, everything worked correctly. It finally dawned on me that I was using Proguard when I generate my APK. Since all the views were driven by standard activities except for my Settings activity most everything worked. When I turned off Proguard, everything worked including Settings. In my Crittercism crash report, the error generated when Proguard is on is class not found. The class not found is the inline PreferenceFragment class.</p>

<p>For instance, using the header</p>

<p>android:fragment="com.mycompany.projectname.FragmentPreferences$SettingsFragment" </p>

<p>the inline class SettingsFragment is not found by the Android OS running on the device.</p>

<p>Turn off Proguard and reinstall the APK and the above header works fine. With or without Proguard, the PreferenceActivity class FragmentPreferences is always found and the headers display. It fails when selecting a displayed header (invokation of SettingsFragment)...</p>

<p>I tried -dontoptimize and -dontshrink, but my app still wont work with Proguard on. My Proguard settings are standard; i.e., generated when I create a new app using the Eclipse wizard (ADT R20 - latest and greatest). Here are the settings I'm trying to run with:</p>

<p>In project-properties:</p>

<p>proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt</p>

<p>target=Google Inc.:Google APIs:15</p>

<p>In proguard-project:</p>

<p>-keepattributes SourceFile, LineNumberTable</p>

<p>-dontshrink</p>

<p>-dontoptimize</p>

<p>All standard activities (no fragments) work fine with the basic settings. The -dont's were added in an attempt to limit Proguard to obfuscation only. Settings still blowup when the inline fragment class is called.</p>

<p>Currently I'm generating the APK with Proguard turned off. When I'm ready to go production, I would like to turn it back on.</p>

<p>(BTW, I moved the PreferenceFragment classes to external classes and they still don't work when Proguard is invoked.)</p>

<p>I've entered more than enough stuff here and still haven't asked my question. Okay, I'll shut this down with the question:</p>

<p>Does anybody know the correct Proguard settings required to make shared preference fragment classes visible? And if this problem extends to regular fragment use, what are those settings?</p>
