首页 文章

API 28(P)的Android设计支持库无法正常工作

提问于
浏览
35

我已经成功配置了android-P SDK环境 . 当我尝试使用android设计支持库时,我面临项目构建错误 . 项目配置是:

IDE: 3.2 Canary 17 Target API: 28 Compile API: 28

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.app.navigationpoc"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'

    implementation 'com.android.support:design:28.0.0-alpha3'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
}

并且构建失败的错误是:

清单合并失败:来自[androidx.core:core:1.0.0-alpha3] AndroidManifest.xml:22:18-86的属性应用程序@ appComponentFactory值=(androidx.core.app.CoreComponentFactory)也出现在[com . android.support:support-compat:28.0.0-alpha3] AndroidManifest.xml:22:18-91 value =(android.support.v4.app.CoreComponentFactory) . 建议:在AndroidManifest.xml:6:5-40:19中添加'tools:replace =“android:appComponentFactory”'来覆盖 .

11 回答

  • 2

    下面的代码与我完美配合:

    dependencies {
        api 'com.android.support:design:28.0.0-alpha3'
    
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    
        testImplementation 'junit:junit:4.12'
    
        androidTestImplementation 'androidx.test:runner:1.1.0-alpha2'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha2'
    }
    
  • 35

    试试这个:

    implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
    
  • 5

    您既可以使用先前的API包版本的工件,也可以使用新的Androidx,而不是两者 .

    如果您想使用以前的版本,请将依赖项替换为

    dependencies {
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
        implementation 'com.android.support.constraint:constraint-layout:1.1.1'
    
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    
        implementation 'com.android.support:design:28.0.0-alpha3'
        implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
    }
    

    如果你想使用Androidx:

    dependencies {
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
    
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
    
        implementation 'com.google.android.material:material:1.0.0-alpha3'
        implementation 'androidx.cardview:cardview:1.0.0-alpha3'
    }
    
  • 1

    重要更新

    28.0.0 之后,Android不会更新支持库 .

    这将是android.support包装下的最后一个功能版本,鼓励开发人员迁移到AndroidX 1.0.0 .

    所以使用库AndroidX .

    • Don't use both support and androidx in app gradle.

    • Your library module or dependencies can still have support libraries. Androidx Jetifier will handle it.

    • 使用稳定版本的 androidx 或任何库,因为alpha,beta,rc可能存在您不希望随应用程序提供的错误 .

    在你的情况下

    dependencies {
        implementation 'androidx.appcompat:appcompat:1.0.0'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
    
        implementation 'com.google.android.material:material:1.0.0'
        implementation 'androidx.cardview:cardview:1.0.0'
    }
    
  • 0

    添加这个:

    tools:replace="android:appComponentFactory"
    android:appComponentFactory="whateverString"
    

    到您的清单应用程序

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        tools:replace="android:appComponentFactory"
        android:appComponentFactory="@string/action_settings">
    

    希望它能够解决

  • 2

    1.将这些代码添加到app / build.gradle:

    configurations.all {
       resolutionStrategy.force 'com.android.support:support-v4:26.1.0' // the lib is old dependencies version;       
    }
    

    2.修改了sdk和工具版本到28:

    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    targetSdkVersion  28
    

    2.在AndroidManifest.xml文件中,您应该添加两行:

    <application
        android:name=".YourApplication"
        android:appComponentFactory="anystrings be placeholder"
        tools:replace="android:appComponentFactory"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
    

    谢谢你的答案@Carlos Santiago:Android design support library for API 28 (P) not working

  • 5

    我用过那个选项:

    使用Android Studio 3.2及更高版本,您可以通过从菜单栏中选择“重构”>“迁移到AndroidX”,快速迁移现有项目以使用AndroidX .

    https://developer.android.com/jetpack/androidx/migrate

  • 0

    我通过将所有 androidx.* 替换为 appropiate package name 来跨越这种情况 .

    改变你的路线

    implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
    
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
    

    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.1'
    
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    

    风陵渡

    • 从AndroidManifest中删除 tools:replace="android:appComponentFactory"
  • 22

    在我的情况下,这是完美的工作..我在清单文件中添加了下面两行代码

    tools:replace="android:appComponentFactory"
    android:appComponentFactory="whateverString"
    

    Manifest file Example

  • 1

    Note: You should not use the com.android.support and com.google.android.material dependencies in your app at the same time.

    添加Android的Material Components

    dependencies {
    // ...
    implementation 'com.google.android.material:material:1.0.0-beta01'
    // ...
    

    }

    如果您的应用目前依赖于原始设计支持库,则可以使用Android Studio提供的Refactor to AndroidX ...选项 . 这样做会更新您的应用程序的依赖项和代码,以使用新打包的androidx和com.google.android.material库 .

    如果您还不想切换到新的androidx和com.google.android.material包,可以通过com.android.support:design:28.0.0-alpha3依赖项使用Material Components .

  • 6

    打开文件gradle.properties并将这两行添加到它:

    android.useAndroidX = true
    android.enableJetifier = true
    

    清洁和建设

相关问题