Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"/>
like image 921
P. Sohm Avatar asked Mar 23 '16 13:03

P. Sohm


2 Answers

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.

like image 115
saibaba vali Avatar answered Nov 10 '22 04:11

saibaba vali


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

like image 1
P. Sohm Avatar answered Nov 10 '22 04:11

P. Sohm