【问题标题】:Why Can't I import PreferenceFragmentCompat using AndroidX library?为什么我不能使用 AndroidX 库导入 PreferenceFragmentCompat?
【发布时间】:2019-02-15 06:33:50
【问题描述】:

我正在尝试设置我的 SettingsFragment,但是

import PreferenceFragmentCompat 一直没有工作。

有没有办法用 AndroidX 做到这一点?

依赖关系

implementation 'androidx.preference:preference:1.0.0-rc02'

摇篮飞翔

    apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.idealorb.payrollapp"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        android.defaultConfig.vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0-rc02'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0-rc02'
    implementation 'com.google.android.gms:play-services-auth:16.0.0'
    implementation 'com.google.firebase:firebase-auth:16.0.3'
    implementation 'com.google.firebase:firebase-core:16.0.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc02'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-rc01'
    implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha05'
    implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha05'
    implementation 'androidx.preference:preference:1.0.0-rc02'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}

【问题讨论】:

  • 您的意思是写Framgment?这是Fragment
  • 是的。我的错误,它不起作用
  • 所以你的代码中有PreferenceFragmentCompat,而不是PreferenceFramgmentCompat,对吧?
  • 是的。 import androidx.preference.PreferenceFragmentCompat;
  • 成功了!在多次尝试同步 Gradle 代码之后。

标签: android android-studio androidx


【解决方案1】:
compileSdkVersion 28

您必须将 compileSdkVersion 设置为 29 才能使用 androidx 命名空间库

【讨论】:

    猜你喜欢
    • 2021-06-02
    • 2018-08-30
    • 2020-12-23
    • 2018-01-12
    • 2021-11-24
    • 2020-04-24
    • 2017-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多