我将一个2岁的项目迁移到Android Studio(以及新的lib),当我调用PreferenceScreen时遇到很多问题。
java.lang.NoSuchFieldError: No static field list_container of type I in class Landroid/support/v7/preference/R$id; or its superclasses (declaration of 'android.support.v7.preference.R$id' appears in /data/app/com.sh.inv-1/base.apk)
at android.support.v7.preference.PreferenceFragmentCompat.onCreateView(PreferenceFragmentCompat.java:260)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1988)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:754)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1653)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:364)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:602)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)
我的build.gradle是:
apply plugin: 'com.android.application'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.sh.inv"
targetSdkVersion 23
versionCode 66
versionName "2.5.0"
}
buildTypes {
debug {
}
release {
minifyEnabled true
proguardFiles 'proguard-project.txt'
}
}
productFlavors {
dev {
minSdkVersion 21
}
prod {
minSdkVersion 14
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
repositories {
maven { url "http://jzaccone.github.io/SlidingMenu-aar" }
}
dependencies {
compile files('libs/ormlite-android-4.48.jar')
compile files('libs/ormlite-core-4.48.jar')
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:preference-v7:23.2.1'
compile 'com.android.support:preference-v14:23.2.1'
compile "com.android.support:appcompat-v7:23.2.1"
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.google.android.gms:play-services-drive:8.4.0'
compile 'org.apache.commons:commons-io:+'
compile 'com.cocosw:undobar:1.8.1@aar'
compile project(':afilechooser')
compile project(':simplecropimage')
}
我的片段是:
public class Settings extends android.support.v7.preference.PreferenceFragmentCompat implements
OnSharedPreferenceChangeListener {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.settings2);
我的AppBaseTheme是:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style>
我真的不明白如何解决它。我试着:
< uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" xmlns:tools="http://schemas.android.com/tools" tools:overrideLibrary="android.support.v14.preference"/>
答案 0 :(得分:31)
只要一个应用程序在两个不同的模块中有两个具有相同名称的文件,就会发生此问题。
例如在STACK应用程序中。有2个模块 stac1 stac2 在stac1-&gt; res-&gt;布局中有miniactivity.xml 在stac2-&gt; res-&gt;布局中有miniactivity.xml
那么你会遇到这个问题。如果删除任何一个xml文件,它将正常工作。答案 1 :(得分:1)
我终于找到了问题。我有一个名为preference_list_fragment.xml的布局。它在删除文件后起作用。