No static field list_container of type I in class Landroid/support/v7/preference/R$id
Asked Answered
L

2

17

I migrated a project of 2 years old to Android Studio (and the new lib), I have a lot of problems when I call a 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)

My build.gradle is :

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')
}

My Fragment is :

public class Settings extends android.support.v7.preference.PreferenceFragmentCompat implements
    OnSharedPreferenceChangeListener {

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.settings2);

My AppBaseTheme is :

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
  </style>

I really don't understand how to resolve it. I tried to:

  • delete gradle cache
  • change gradle version (2.10 et 2.12)
  • uses-sdk add: < uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" xmlns:tools="http://schemas.android.com/tools" tools:overrideLibrary="android.support.v14.preference"/>
Lehmbruck answered 23/3, 2016 at 13:41 Comment(0)
K
44

This problem will happen whenever in one application has two files with the same name in two different modules.

For example in a STACK application. 2 modules are there 1. stac1 2. stac2 in stac1->res->layout has miniactivity.xml in stac2->res->layout has miniactivity.xml

then you will get this problem. If you delete any one xml file it will works fine.

Kathie answered 12/5, 2016 at 7:57 Comment(3)
I had a similiar problem, I had 2 SDK which had same class names.Predispose
Live long life my friend, between i have a wonderful scenario with a huge project, how can i figure out which file is duplicate.Provided
Is there any API or plugins that finds such issues?Longeron
L
1

I finally found the problem. I had a layout which was called preference_list_fragment.xml. It works after deleting the file.

Lehmbruck answered 23/3, 2016 at 16:1 Comment(2)
Thanks for saving my time. Was stuck with similar kind of issue.Casaleggio
It's à pleasure for me to share the tip :)Lehmbruck

© 2022 - 2024 — McMap. All rights reserved.