This question already has an answer here:
play-services-ads conflicts with appcompat
(1 answer)
Closed 3 years ago.
Iv have an immediate conflict on an empty project once I implement gplay services.
On the latest android studio on mac, i create a simple activity app:
mainactivity:
package semy.apps.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
then once i add implementation 'com.google.android.gms:play-services-ads:18.1.1' on build.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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.google.android.gms:play-services-ads:18.1.1'
}
i get
ERROR: Manifest merger failed : Attribute application#appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.
i try to add those tags on manifest to no avail, still doesnt work
A quick solution to your problem could be to add the following 3 lines in your AndroidMannifest.xml
xmlns:tools="http://schemas.android.com/tools"
tools:replace="android:appComponentFactory"
android:appComponentFactory="#string/app_name"
So, after adding the above 3 lines your AndroidMannifest.xml should look like,
AndroidMannifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<!--Add the following 3 lines-->
<application
xmlns:tools="http://schemas.android.com/tools"
tools:replace="android:appComponentFactory"
android:appComponentFactory="#string/app_name"
...
>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
</application>
</manifest>
EDIT: Update your dependencies to the latest version as play-services-ads is using androidx version of support library and you are using the traditional one.
build.gradle (Module: app)
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
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.google.android.gms:play-services-ads:18.2.0'
}
I hope it will fix your build error. Let me know if it works?
Related
I'm developing an app and I want to add an admob banner add to it. I asked the permissions in the manifest file for Internet and for the network state. Then I added the dependency for admob. After entering the dependency to the gradle file, the app in my phone app crashes during testing.
It happens when I add the dependency. I want to find the correct dependency or some how fix this if this happens because of another reason.
Here are the dependencies I added:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.gms:play-services-ads:18.3.0'
}
You need to add below Meta tag inside of Aplication in your Manifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
//Add this
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="#string/admob_app_id" /> //Add here your admob app id
...
</application>
I hope this can help you!
Thank You.
I think you need to add 2 meta-data tags inside the manifest xml of your application.
<application>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="#string/admob_app_id" /> // put your admob app id in quotes
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
Hope this helps
I added MaterialAlertDialog to my project which was not using androidx. This caused errors during the next build. So i removed the 'implementation' statement from app level build gradle. But still i am having manifest merge error when i try to build my project.
This is the error i get during build time
Manifest merger failed : Attribute application#appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:19:5-152:19 to override.
So far i have tried the following solutions,Close and reload my project. Do a clean and rebuild .delete the .gradle and .idea folders in my project and build it again
These are the dependencies in my project
dependencies
{
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation "com.android.support:appcompat-v7:${android_support_version}"
implementation "com.android.support:design:${android_support_version}"
implementation 'com.github.lzyzsd:circleprogress:1.1.0#aar'
implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1#aar'
implementation 'commons-net:commons-net:3.3'
implementation('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true
}
implementation "de.hdodenhof:circleimageview:${circle_imageview}"
implementation "com.github.bumptech.glide:glide:${glide_version}"
implementation "com.android.support:recyclerview-v7:${android_support_version}"
implementation "com.android.support:cardview-v7:${android_support_version}"
implementation "com.squareup.retrofit2:retrofit:${retrofit_service_version}"
implementation "com.squareup.retrofit2:converter-gson:${retrofit_gson_convertor}"
implementation "com.clough.android.androiddbviewer:androiddbviewer:${dbviewer_version}"
implementation "com.android.support:multidex:${multidex_version}"
implementation "com.github.crosswall:Android-Coverflow:${viewPager_version}"
implementation "com.squareup.okhttp3:logging-interceptor:3.4.0"
implementation project(':sdkui')
implementation 'com.github.ronaldsmartin:Material-ViewPagerIndicator:1.0.4'
implementation 'com.google.android.gms:play-services-base:16.0.1'
implementation 'com.google.android.gms:play-services-identity:16.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-auth-api-phone:16.0.0'
implementation 'com.google.firebase:firebase-config:16.1.0'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-messaging:20.0.0'
}
apply plugin: 'com.google.gms.google-services'
I am answering this just to specify the step it took to clear my issue.
I removed the gradle dependency for the MaterialDesign.
The cashe issue was solved by doing File-> Invalidate Cache & restart
Since Firebase was changed to ver 20 before restart the issue persisted.
Reduced Firebase version to 17.3.4 this fixed everything.
Add these lines in your Manifest file.
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Manifest File
<application
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="false"
android:theme="#style/AppTheme"
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString">
Try this
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.
If you have any Maven dependencies that have not been migrated to the AndroidX namespace, the Android Studio build system also migrates those dependencies for you when you set the following two flags to true in your gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
Add these lines in your Manifest file in Application TAG.
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
I have a problem about android manifest file in my android project after adding ButterKnife dependency in gradle file.
When I run the program, it throws an error shown below.
Manifest merger failed : Attribute application#appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:6:5-21:19 to override.
Here is my file.
<application
tools:replace="android:allowBackup,android:icon,android:label,android:roundIcon,android:supportsRtl,android:theme"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Build.gradle file
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testİmplementation 'junit:junit:4.12'
androidTestİmplementation 'com.android.support.test:runner:1.0.2'
androidTestİmplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// TODO 1) ButterKnife Library Defined
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
}
You cannot use butterknife:10.x.x unless you also migrated to AndroidX. If you haven't migrated, you'll need to stick to 9.0.0 for now. Once you migrate, then you can update to 10.1.0 (or whatever is latest at that time). –
I am working on my app.Everything was ok but i do not know why i got this error when i tried to run the application:
Execution failed for task ':inteligentestate:processDebugManifest'.
> Manifest merger failed : Attribute application#appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:6:5-28:19 to override.
from the error suggestion i added tools:replace="android:appComponentFactory" in my main application manifest:
<application
android:name=".application.App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:appComponentFactory">
When i run my app i got this error:
Task :inteligentestate:processDebugManifest FAILED
/mnt/main/Project/.../AndroidManifest.xml:6:5-29:19 Error:
tools:replace specified at line:6 for attribute android:appComponentFactory, but no new value specified
/mnt/main/Tutorial/Android/project/.../AndroidManifest.xml Error:
Validation failed, exiting
I googled and I found this post .
I'm not using androidX
This is my project dependencies:
dependencies {
// Support
implementation "com.android.support:design:${versions.supportLib}"
implementation "com.android.support:recyclerview-v7:${versions.supportLib}"
implementation "com.android.support:cardview-v7:${versions.supportLib}"
implementation "com.android.support:gridlayout-v7:${versions.supportLib}"
implementation "com.android.support:customtabs:${versions.supportLib}"
// room
implementation "android.arch.persistence.room:runtime:${versions.room}"
annotationProcessor "android.arch.persistence.room:compiler:${versions.room}"
implementation "android.arch.persistence.room:rxjava2:${versions.room}"
// Network
implementation "com.google.code.gson:gson:${versions.gson}"
implementation "com.squareup.retrofit2:retrofit:${versions.retrofit}"
implementation "com.squareup.retrofit2:converter-gson:${versions.retrofit}"
implementation "com.squareup.okhttp3:logging-interceptor:${versions.interceptor}"
//rx java
implementation "io.reactivex.rxjava2:rxandroid:${versions.rxAndroidVersion}"
implementation "io.reactivex.rxjava2:rxjava:${versions.rxJavaVersion}"
//Other
implementation "com.jakewharton.timber:timber:${versions.timber}"
implementation "com.jakewharton:butterknife:${versions.butterknife}"
annotationProcessor "com.jakewharton:butterknife-compiler:${versions.butterknife}"
implementation "com.google.dagger:dagger:${versions.dagger}"
annotationProcessor "com.google.dagger:dagger-compiler:${versions.dagger}"
// Testing
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 project(path: ':map')
}
And library dependancies:
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
api "com.android.support.constraint:constraint-layout:${versions.constraintLayout}"
api "com.android.support:appcompat-v7:${versions.supportLib}"
api "com.android.support:support-v4:${versions.supportLib}"
// Mapbox
api "com.mapbox.mapboxsdk:mapbox-android-sdk:${versions.mapboxMapSdk}"
api "com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v7:${versions.mapboxPluginLocalization}"
I found this post anber mentioned that
project has different versions of the same library
But i think my project's library is the same!!!
Solution: Android Studio => Refactor Menu => Migrate to AndroidX.
Yes it's easy.
Go to your application manifest and at bottom you'll see mergedManifest option
navigate to mergedManifest bottom where it will tell your what you've error and in what file
See you error closer. It's mostly error in our layout file that's why merged Manifest don't works
Hope so it will solve your error!!!
please try downgrade your gradle version and restart Android studio
When I'm building Gradle with androidx I get the following error. Please help me to solve this issue.
Error Message: Manifest merger failed : Attribute
application#appComponentFactory
value=(android.support.v4.app.CoreComponentFactory) from
[com.android.support:support-compat:28.0.0]
AndroidManifest.xml:22:18-91 is also present at
[androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86
value=(androidx.core.app.CoreComponentFactory).
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.kanwarpreet.dealmybook">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".activities.SplashActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.LoginActivity" />
<activity android:name=".activities.RegisterActivity" />
<activity
android:name=".activities.HomeActivity"
android:label="#string/title_activity_home"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".activities.BookDetailsActivity"
android:label="#string/title_activity_book_details"
android:theme="#style/AppTheme.NoActionBar"/>
<activity android:name=".activities.AddBookActivity" />
</application>
</manifest>
Build.Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.kanwarpreet.dealmybook"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
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'
}
Put these flags in your gradle.properties
android.enableJetifier=true
android.useAndroidX=true
After hours of struggling, I solved it by including the following within app/build.gradle:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Put these flags in your gradle.properties
android.enableJetifier=true
android.useAndroidX=true
Changes in build.gradle:
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha04'
Refer to: https://developer.android.com/jetpack/androidx/migrate
Reason of this error-
Because after upgrade, androidx.core:core is accessed somewhere, when your project is still not using androidx. So classes like CoreComponentFactory and many others are now found at two places - androidx.core:core and com.android.support:support-compat. That's why this error occured.
What is solution?
You should migrate to AndroidX. If you don't know about AndroidX. Please read What is AndroidX?
How to migrate your project
After Android Studio 3.2 (September 2018), there is direct option to migrate existing project to AndroidX. This refract all packages automatically.
Before you migrate, it is strongly recommended to backup your project.
Existing project
Android Studio > Refactor Menu > Migrate to AndroidX...
It will analysis and will open Refractor window in bottom. Accept changes to be done.
New project
Put these flags in your gradle.properties
android.enableJetifier=true
android.useAndroidX=true
Check #Library mappings for equal AndroidX package.
Check #Official page of Migrate to AndroidX
Error explicitly says-
[com.android.support:support-compat:28.0.0]
AndroidManifest.xml:22:18-91 is also present at
[androidx.core:core:1.0.0]
AndroidX is the latest support library from Google. It contains all previous components from all older appcompat versions. Do NOT use appcompat-v-any number. Instead, use a similar component from AndroidX libraries. Remove the numbered support libraries from your Gradle and your code wherever it is imported. Then sync your gradle.
Component similarity table can be found here. Also, follow the steps mentioned in Migrating to AndroidX.
Again, stop using any previous appcompat numbered versions. There's only AndroidX now.
Hope this helps.
you have to move on the Androidx because your project is using some feature
from there.so you need to migrate to AndroidX
follow these snippets
look at this second snippet
One suggestion to find out the exact reason is to open the manifest file and in bottom you will see a Merge Manifest option where you will see exact reason for failure.
See below image
Just add a line into gradle.properties
android.enableJetifier=true
android.useAndroidX=true
Project-wide Gradle settings.
IDE (e.g. Android Studio) users:
Gradle settings configured through the IDE will override any settings specified in this file. For more details on how to configure your build environment visit http://www.gradle.org/docs/current/userguide/build_environment.html
Specifies the JVM arguments used for the daemon process. The setting is particularly useful for tweaking memory settings
org.gradle.jvmargs=-Xmx1536m
android.enableJetifier=true
android.useAndroidX=true
When configured, Gradle will run in incubating parallel mode. This option should only be used with decoupled projects. More details, visit http://www.gradle.org/docs/current/userguide/multi_project_builds.html
sec:decoupled_projectsvorg.gradle.parallel=true
I also faced this problem because I was using some external library in my project and one of them was not converted into AndroidX.
add below code to android/build.gradle under buildscript ext
googlePlayServicesVersion = "16.0.0"
googlePlayServicesVisionVersion = "17.0.2"
and below code to gradle.properties
android.enableJetifier=true
android.useAndroidX=true
I let Android Studio convert my Relative layout views to Constraint layout. So Android Studio added one of the com.andriod.support... while I added the androidx... dependency when I removed the second one the error was gone.
dependencies {
implementation "androidx.constraintlayout:constraintlayout:2.1.0"
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
}
This was my error:
Manifest merger failed : Attribute application#appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.3.2] AndroidManifest.xml:24:18-86
is also present at [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:7:3-26:17 to override.
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:one.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
In manifest add tools:replace="android:theme" to your application
I have resolve problem by removing
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
from app build.gradle and using
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha04'
instead of it.