Android design support library for API 28 (P) not working
Asked Answered
O

18

119

I've configured android-P SDK environment successfully. When I attempt to use the android design support library I face project build errors. Project configurations are:

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

And build failed error is:

Manifest merger failed : Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.0.0-alpha3] AndroidManifest.xml:22:18-86 is also present at [com.android.support:support-compat:28.0.0-alpha3] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:6:5-40:19 to override.

Opprobrious answered 10/6, 2018 at 9:47 Comment(2)
Have you checked this answer : https://mcmap.net/q/119238/-manifest-merger-fails-for-appcomponentfactory-duplicateLavery
Find what new AndroidX library you should use: developer.android.com/jetpack/androidx/migrate/…Caiman
S
103

You can either use the previous API packages version of artifacts or the new Androidx, never both.

If you wanna use the previous version, replace your dependencies with

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

if you want to use 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'
}
Scherle answered 11/6, 2018 at 15:5 Comment(2)
This answer should be the accepted one. More info on medium.com/mindorks/…Rosalbarosalee
Why is it the com was not replace in material in the implementation ?Homosexuality
R
62

Important Update

Android will not update support libraries after 28.0.0.

This will be the last feature release under the android.support packaging, and developers are encouraged to migrate to AndroidX 1.0.0.

So use library AndroidX.

  • Don't use both Support and AndroidX in project.
  • Your library module or dependencies can still have support libraries. Androidx Jetifier will handle it.
  • Use stable version of androidx or any library, because alpha, beta, rc can have bugs which you dont want to ship with your app.

In your case

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'
}
Ramshackle answered 28/9, 2018 at 13:2 Comment(3)
its weird, my project was on P since a long time, but it started giving support library errors today when I build. Is there anything I am missing here?Exchequer
It is common error we all facing now a days, I face it every few days in running project. Just do Invalidate cache and restart.Ramshackle
@Exchequer Try from menu Build > Clear Project then Build > Make Project first, sometimes this is sufficient, if not then do Invalidate cache and restart, as invalidate cache and restart takes lots of time and clears cache for all projects.Ona
C
44

Add this:

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

to your manifest application

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

hope it helps

Colloid answered 21/6, 2018 at 9:24 Comment(7)
What do you have in @string/action_settings?Baily
I had a problem: More than one file was found with OS independent path 'META-INF/androidx.core_core.versionBaily
Error after adding 2 lines: * What went wrong: Execution failed for task ':app:generateDebugBuildConfig'. > org.xml.sax.SAXParseException; systemId: file:/C:/D/code/js/emps_app/android/app/src/main/AndroidManifest.xml; lineNumber: 14; columnNumber: 52; The prefix "tools" for attribute "tools:replace" associated with an element type "application" is not bound.Ginn
Did you add the xmlns:tools="schemas.android.com/tools" inside AndroidManifest.xml header?Colloid
I added xmlns:tools="schemas.android.com/tools" inside AndroidManifest.xml (under android/app) and it has a new error: > Task :app:processDebugManifest FAILED C:\D\code\js\emps_app\android\app\src\debug\AndroidManifest.xml:2:11-50 Error: Attribute manifest@tools value=(http://schemas.android.com/tools) from AndroidManifest.xml:2:11-50 is also present at AndroidManifest.xml:2:11-50 value=(schemas.android.com/tools). Attributes of <manifest> elements are not merged. Ginn
The manifest under android/src/debug/ has a similar header: <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">Ginn
you shoud add " xmlns:tools="schemas.android.com/tools" " tooSeacock
R
19

I've used that option:

With Android Studio 3.2 and higher, you can quickly migrate an existing project to use AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

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

Resolutive answered 8/11, 2018 at 9:44 Comment(0)
T
13

Google has introduced new AndroidX dependencies. You need to migrate to AndroidX, it's simple.

I replaced all dependencies to AndroidX dependencies

Old design dependency

implementation 'com.android.support:design:28.0.0'

New AndroidX design dependency

implementation 'com.google.android.material:material:1.0.0-rc01'

you can find AndroidX dependencies here https://developer.android.com/jetpack/androidx/migrate


Automatic AndroidX migration option (supported on android studio 3.3+)

Migrate an existing project to use AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

Terraqueous answered 16/2, 2019 at 15:25 Comment(2)
implementation 'com.google.android.material:material:1.1.0-alpha05' this is new versionStesha
what to put instead of 'import android.support.design.widget.TabLayout;' ?Ebony
F
6

1.Added these codes to your app/build.gradle:

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

2.Modified sdk and tools version to 28:

compileSdkVersion 28
buildToolsVersion '28.0.3'
targetSdkVersion  28

2.In your AndroidManifest.xml file, you should add two line:

<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">

Thanks for the answer @Carlos Santiago : Android design support library for API 28 (P) not working

Florentinoflorenza answered 9/10, 2018 at 10:31 Comment(3)
This solution is not future compliant, as you should be using AndroidX now. Old Applications that are published should be upgraded now. If there is a lot of rework, those changes should still be made.Heber
@Abhinav Saxena You are right, we should update our project to 28 better than solved this problem with old SDK version. :)Florentinoflorenza
this is the accepted answer, After lot of suggestions, nothing helped me, But this helped me as configurations.all {} . You saved my day, thanks.Kristopherkristos
A
6

Design support library for androidX is implementation 'com.google.android.material:material:1.0.0'

Autolithography answered 24/6, 2019 at 10:21 Comment(0)
X
6

First of all, you should look gradle.properties and these values have to be true. If you cannot see them you have to write.

android.useAndroidX = true
android.enableJetifier = true

After that you can use AndroidX dependencies in your build.gradle (Module: app). Also, you have to check compileSDKVersion and targetVersion. They should be minimum 28. For example I am using 29.

So, an androidx dependency example:

implementation 'androidx.cardview:cardview:1.0.0'

However be careful because everything is not start with androidx like cardview dependency. For example, old design dependency is:

implementation 'com.android.support:design:27.1.1'

But new design dependency is:

implementation 'com.google.android.material:material:1.3.0'

RecyclerView is:

implementation 'androidx.recyclerview:recyclerview:1.1.0'

So, you have to search and read carefully.

Xl answered 6/4, 2020 at 10:0 Comment(0)
O
5

open file gradle.properties and add these two lines to it:

android.useAndroidX = true
android.enableJetifier = true

clean and build

Obstinacy answered 7/11, 2018 at 17:50 Comment(2)
useAndroidX tells the compiler to user androidx. files instead of old android support packageObstinacy
This directs Studio 3.2 and above to migrate to AndroidX. All the libraries that have migrated to AndroidX shall be corrected in dependencies.Heber
B
3

I cross that situation by replacing all androidx.* to appropiate package name.

change your line

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'

to

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'

NOTED

  • remove tools:replace="android:appComponentFactory" from AndroidManifest
Bringhurst answered 11/6, 2018 at 4:55 Comment(0)
S
3

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

Add Material Components for Android in your build.gradle(app) file

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

If your app currently depends on the original Design Support Library, you can make use of the Refactor to AndroidX… option provided by Android Studio. Doing so will update your app’s dependencies and code to use the newly packaged androidx and com.google.android.material libraries.

If you don’t want to switch over to the new androidx and com.google.android.material packages yet, you can use Material Components via the com.android.support:design:28.0.0-alpha3 dependency.

Scenarist answered 11/9, 2018 at 7:29 Comment(0)
D
0

Below code worked perfectly with me:

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'
}
Damien answered 11/6, 2018 at 21:4 Comment(0)
R
0

Try this:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
Rajah answered 8/10, 2018 at 6:52 Comment(0)
Z
0

Android documentation is clear on this.Go to the below page.Underneath,there are two columns with names "OLD BUILD ARTIFACT" and "AndroidX build artifact"

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

Now you have many dependencies in gradle.Just match those with Androidx build artifacts and replace them in the gradle.

That won't be enough.

Go to your MainActivity (repeat this for all activities) and remove the word AppCompact Activity in the statement "public class MainActivity extends AppCompatActivity " and write the same word again.But this time androidx library gets imported.Until now appcompact support file got imported and used (also, remove that appcompact import statement).

Also,go to your layout file. Suppose you have a constraint layout,then you can notice that the first line constraint layout in xml file have something related to appcompact.So just delete it and write Constraint layout again.But now androidx related constraint layout gets added.

repeat this for as many activities and as many xml layout files..

But don't worry: Android Studio displays all such possible errors while compiling.

Zacharie answered 5/7, 2019 at 17:50 Comment(0)
C
0

Had similar problem. Added in build.gradle and it worked for me.

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
Chainman answered 25/7, 2019 at 6:10 Comment(0)
S
0

if you want to solve this problem without migrating to AndroidX (I don't recommend it)

this manifest merger issue is related to one of your dependency using androidX.

you need to decrease this dependency's release version. for my case :

I was using google or firebase

api 'com.google.android.gms:play-services-base:17.1.0'

I have to decrease it 15.0.1 to use in support library.

Sherl answered 14/2, 2020 at 12:37 Comment(0)
I
0

Adding androidTestImplementation 'androidx.test:runner:1.2.0-alpha05' works for me.

Inroad answered 1/7, 2020 at 10:5 Comment(0)
E
0
  1. Go to gradle.properties
  2. Write

android.useAndroidX=true

and

android.enableJetifier=true

  1. Change your dependency from

implementation 'com.androidx.support:design:28.0.0'

to

implementation 'com.androidx.support:design:28.0.0'

Everest answered 5/12, 2021 at 10:2 Comment(1)
they both litrally are same librariesAlbata

© 2022 - 2024 — McMap. All rights reserved.