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

AndroidAndroid StudioAndroid Design-LibraryAndroid 9.0-Pie

Android Problem Overview


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.

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

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

Solution 3 - Android

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

Solution 4 - Android

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

Solution 5 - Android

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.

Solution 6 - Android

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 : https://stackoverflow.com/questions/50782435/android-design-support-library-for-api-28-p-not-working

Solution 7 - Android

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

Solution 8 - Android

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.

Solution 9 - Android

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

android.useAndroidX = true
android.enableJetifier = true

clean and build

Solution 10 - Android

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

Solution 11 - Android

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.

Solution 12 - Android

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

Solution 13 - Android

Try this:

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

Solution 14 - Android

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.

Solution 15 - Android

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

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

Solution 16 - Android

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.

Solution 17 - Android

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

Solution 18 - Android

  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'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRahul RastogiView Question on Stackoverflow
Solution 1 - AndroidDanfengView Answer on Stackoverflow
Solution 2 - AndroidKhemraj SharmaView Answer on Stackoverflow
Solution 3 - AndroidCarlos SantiagoView Answer on Stackoverflow
Solution 4 - AndroidDouglas MesquitaView Answer on Stackoverflow
Solution 5 - AndroidAmir Dora.View Answer on Stackoverflow
Solution 6 - AndroidCodiosView Answer on Stackoverflow
Solution 7 - AndroidN DroidevView Answer on Stackoverflow
Solution 8 - AndroidNamelessView Answer on Stackoverflow
Solution 9 - AndroidLena BruView Answer on Stackoverflow
Solution 10 - AndroidamlwinView Answer on Stackoverflow
Solution 11 - AndroidAshutoshView Answer on Stackoverflow
Solution 12 - AndroidHasan A YousefView Answer on Stackoverflow
Solution 13 - AndroidMr. LemonView Answer on Stackoverflow
Solution 14 - Androidbhargav ramView Answer on Stackoverflow
Solution 15 - AndroidHoliday FunView Answer on Stackoverflow
Solution 16 - AndroidelifyView Answer on Stackoverflow
Solution 17 - AndroidSanket ParchandeView Answer on Stackoverflow
Solution 18 - AndroidShoaib YousufView Answer on Stackoverflow