在 Eclipse 中新導入 Android 專案後,編輯器提示 R cannot be resolved to a variable,且 gen/ 目錄下缺少 R.java。嘗試 Clean 專案、Fix Project Properties 等常規手段均無效。
錯誤訊息顯示:This resource is private in Android platform source code。這表示專案引用了 Android 內部 private 屬性的資源(如 *android:style/Theme.Dialog.Alert),這類資源在每次編譯時產生的整數 ID 都不固定,導致 R.java 無法正常生成。
styles.xml(通常位於 res/values/)。<style name="Dialog" parent="*android:style/Theme.Dialog.Alert">* 移除,或改為公開父樣式:<style name="Dialog" parent="android:style/Theme.Dialog.Alert"><style name="XWindowTitle" parent="*android:WindowTitle"> → <style name="XWindowTitle" parent="android:WindowTitle">R.java 即可正常生成。Android 建議開發者僅使用公開 API(android:style/...、android:attr/...),避免依賴以 * 開頭的私有資源,以免跨版本相容性問題。