最近、プロジェクトを分割し、ライブラリ プロジェクトとメイン プロジェクトを作成しました。カスタム属性を持つ設定画面を持っているので、カスタム属性を持つ設定を Preferences.xml から削除し、それらを独自の xml ファイルに入れ、それらを Preferences.xml ファイルに戻し、メイン プロジェクトの個々のファイルを再定義しました (プロセスについては、別の質問への回答で詳しく説明しています。
プロジェクトが正しくビルドおよび実行されます。ただし、設定画面を開こうとするたびに RuntimeException が発生します。カスタムattrsで設定を削除すると問題が解決するので、そこまでさかのぼります。残念ながら、例外には有用な情報はありません。
attrs.xml (lib プロジェクトに存在)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="numberpickerPref">
<attr name="maxValue" format="integer" />
<attr name="minValue" format="integer" />
</declare-styleable>
</resources>
Preferences.xml (lib プロジェクトにもあります)
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/pref_VibrationSettingsTitle">
<CheckBoxPreference android:key="@string/pref_vibrateFlagKey"
android:title="@string/pref_VibrateTitle"
android:summary="@string/pref_VibrateSummary"
android:defaultValue="false" />
<include layout="@layout/pref_vibrate_on" />
<include layout="@layout/pref_vibrate_off" />
</PreferenceCategory>
</PreferenceScreen>
pref_vibrate_off.xml (lib プロジェクトとメイン プロジェクトの両方で定義) (diff のみが私の名前空間で、1 つは lib を指し、もう 1 つはメイン プロジェクトを指します)
<?xml version="1.0" encoding="utf-8"?>
<!-- Stupid workaround because Android still has a bug where custom attributes in a library cause the executable project
problems when building:
https://stackoverflow.com/questions/4461407/help-with-a-custom-view-attributes-inside-a-android-library-project -->
<com.me.numberpicker.NumberPickerPreference
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:my="http://schemas.android.com/apk/res/com.me.myapp.lib"
android:key="@string/pref_vibrateOffPeriodKey"
android:title="@string/pref_VibrateOffTitle"
android:summary="@string/pref_VibrateOffSummary"
my:maxValue="@string/MaxVibratorOffPeriodInS"
my:minValue="@string/MinVibratorOffPeriodInS"
android:defaultValue="@string/DefaultVibratorOffPeriodInS" />
MyPreferencesActivity.java
public class MegalarmPreferencesActivity extends PreferenceActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
すべての文字列は lib プロジェクトで適切に定義されています。
何か不足している場合は、お知らせください。プロジェクトをライブラリとメインに分割するまで、設定は正常に機能していました。
どうもありがとう!ショーン