118

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.

BlackBlind
  • 772
  • 9
  • 26
Rahul Rastogi
  • 4,486
  • 5
  • 32
  • 51

18 Answers18

102

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'
}
Danfeng
  • 1,023
  • 1
  • 7
  • 6
  • 2
    This answer should be the accepted one. More info on https://medium.com/mindorks/whats-new-in-android-support-library-db0ec7a8ad1 – Rawa Aug 17 '18 at 09:30
  • Why is it the `com` was not replace in `material` in the `implementation` ? – RoCkDevstack Nov 26 '18 at 14:49
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'
}
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
  • 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? – Talha Nov 15 '18 at 08:44
  • 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. – Khemraj Sharma Nov 15 '18 at 10:39
  • @Talha 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. – John Apr 16 '19 at 09:52
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

Carlos Santiago
  • 590
  • 5
  • 13
  • What do you have in `@string/action_settings`? – Aliton Oliveira Jun 07 '19 at 17:10
  • I had a problem: **More than one file was found with OS independent path 'META-INF/androidx.core_core.version** – Aliton Oliveira Jun 07 '19 at 17:46
  • 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.` – user938363 Jun 19 '19 at 02:42
  • 2
    Did you add the xmlns:tools="http://schemas.android.com/tools" inside AndroidManifest.xml header? – Carlos Santiago Jun 19 '19 at 09:54
  • 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 elements are not merged. ` – user938363 Jun 23 '19 at 05:38
  • 2
    The manifest under android/src/debug/ has a similar header: `` – user938363 Jun 23 '19 at 05:40
  • you shoud add " xmlns:tools="http://schemas.android.com/tools" " too – Ali Ziaee Nov 03 '19 at 19:04
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

Douglas Mesquita
  • 860
  • 1
  • 13
  • 30
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.

Amir Dora.
  • 2,831
  • 4
  • 40
  • 61
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

Codios
  • 378
  • 4
  • 11
  • 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. – Abhinav Saxena Nov 23 '18 at 06:04
  • @Abhinav Saxena You are right, we should update our project to 28 better than solved this problem with old SDK version. :) – Codios Nov 26 '18 at 02:30
  • this is the accepted answer, After lot of suggestions, nothing helped me, But this helped me as configurations.all {} . You saved my day, thanks. – Noor Hossain Jul 27 '19 at 14:25
6

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

Samir Alakbarov
  • 1,120
  • 11
  • 21
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.

canerkaseler
  • 6,204
  • 45
  • 38
5

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

android.useAndroidX = true
android.enableJetifier = true

clean and build

Lena Bru
  • 13,521
  • 11
  • 61
  • 126
  • 1
    useAndroidX tells the compiler to user androidx. files instead of old android support package – Lena Bru Nov 18 '18 at 21:49
  • This directs Studio 3.2 and above to migrate to AndroidX. All the libraries that have migrated to AndroidX shall be corrected in dependencies. – Abhinav Saxena Nov 23 '18 at 06:00
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
amlwin
  • 4,059
  • 2
  • 15
  • 34
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.

Carlosgub
  • 111
  • 5
Ashutosh
  • 186
  • 1
  • 8
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'
}
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
0

Try this:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
Zoe
  • 27,060
  • 21
  • 118
  • 148
Đốc.tc
  • 530
  • 4
  • 12
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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
0

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

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
Holiday Fun
  • 385
  • 3
  • 7
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.

elify
  • 440
  • 1
  • 7
  • 15
0

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

Sanket Parchande
  • 894
  • 9
  • 14
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'

Shoaib Yousuf
  • 71
  • 1
  • 2