Manifest merger failed after import a module - java

Hi I am developing a sdk, and when I add these SDK into a app proyect I get the following 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.1] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:22:5-125:19 to override.
The build.gradle are the followings
App build.gradle
dependencies {
implementation project(':sdkA')
implementation project(':sdkB')
implementation 'org.webrtc:google-webrtc:1.0.28032'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'com.android.support:preference-v14:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:gridlayout-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'io.michaelrocks:libphonenumber-android:8.4.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android:flexbox:1.0.0'
implementation 'com.github.woxthebox:draglistview:1.6.3'
implementation 'com.balysv:material-ripple:1.0.2'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.16'
implementation('com.crashlytics.sdk.android:crashlytics:2.8.0#aar') {
transitive = true
}
// Google Lifecycle Components
implementation "android.arch.lifecycle:extensions:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
}
build.gradle of sdkA
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'org.webrtc:google-webrtc:1.0.28032'
implementation('io.socket:socket.io-client:1.0.0') {
exclude group: 'org.json', module: 'json'
}
implementation('com.crashlytics.sdk.android:crashlytics:2.8.0#aar') {
transitive = true
}
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
// Google Lifecycle Components
implementation "android.arch.lifecycle:extensions:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
build.gradle of sdkB
dependencies {
implementation "com.android.support:appcompat-v7:27.1.1"
implementation "com.android.support:recyclerview-v7:27.1.1"
}
How can solve it?
Thanks

Ok I've been tackling this issue myself for the last day or so. nightmare.
but I have it working now at least for the project I've been working on which is quite large and with lots of additional android dependencies.
See this issue where Mike Hardy has been a great help. https://github.com/mikehardy/jetifier/issues/27
I would recommend to avoid AndroidX until 0.60.0 has landed.
SOURCE OF THE PROBLEM
the source of the problem for most of us is the + range selector in gradle dependencies.
as shown here as an example in react-native-google-analytics-bridge:
compile "com.google.android.gms:play-services-analytics:${safeExtGet('googlePlayServicesVersion', '+')}"
compile "com.google.android.gms:play-services-tagmanager-v4-impl:${safeExtGet('googlePlayServicesVersion', '+')}"
for most of us we're not setting a googlePlayServicesVersion value in the top level android/build.gradle
so we'll want to specify googlePlayServicesVersion = "16.+" + because theres various other google service packages available and they're not all at the same version number. this will capture 16.X.X and not go above. 17.X.X holds further issues.
And we also want to set supportLibVersion to 28.0.0 which is used by the android support libraries: com.android.support:appcompat-v7 the most common.
SOLUTION
android/build.gradle
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 21
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
googlePlayServicesVersion = "16.+"
}
...
AndroidManifest.xml
top line:
<manifest
xmlns:tools="http://schemas.android.com/tools"
application tag:
tools:replace="android:appComponentFactory"
android:appComponentFactory="android.support.v4.app.CoreComponentFactory"
ensure your gradle-wrapper.properties using 4.10.1
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
and finally ensure you are not using android X.
gradle.properties:
android.enableJetifier=false
android.useAndroidX=false
Additional Step (You might need this)
failing that doesn't work try adding jetifier as well. We'll use this to run through your node_modules and ensure everything is using the non androidx libraries.
npm i jetifier --save-dev or yarn add jetifier --dev
then add to postinstall script
"scripts": {
"postinstall": "jetify -r"
}

Try applying the suggestion, adding
tools:replace="android:appComponentFactory"
to the application tag

Related

Mapbox services refuses to import

I have the following in my app build gradle:
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "com.mapbox.navigation:ui:1.4.0"
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:5.8.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-locationlayer:0.11.0'}
and have successfully run things such as a map and placing markers down etc. However, when I go to import anything from services, such as import com.mapbox.services.android.navigation.ui.v5.NavigationLauncher; Android Studio cannot find anything. I've tried different versions in case the imports I needed were deprecated but to no avail. Any ideas? All the tutorials and example code in the documentation and third-party all use these imports and I don't really see a way around them.
Thanks!
In the module-level build.gradle file, add the following dependencies:
// in addition to the rest of your build.gradle contents
// you should include the following repository and dependencies
repositories {
mavenCentral()
maven { url 'https://mapbox.bintray.com/mapbox' }
}
dependencies {
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.42.6'
}

Implementation 'com.google.android.gms:play-services-ads:18.1.0'

I want to add ads to my project but when i add the line below, it doesn't work:
implementation 'com.google.android.gms:play-services-ads:18.1.0'
these are the dependencies from the build.gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'com.google.android.gms:play-services-ads:18.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
It is likely, that you might not have added the Google Services Gradle Plugin to the project, as well as the google-services.json file (which can be downloaded from the Firebase console) - and so your application fails to authenticate.
Adding the com.google.android.gms.ads.APPLICATION_ID into the AndroidManifest.xml has the same effect, because the Play Services plugin adds the values from google-services.json at build-time.
... when only using AdMob, the second option should be preferred.
Do you have inside top-level build.gradle file reference to the google() repo or to maven { url "https://maven.google.com" }? Do you have some specific error inside log?
Try to create a new project and copy old project files and paste in a new one. If it should help!

How to fix "error: package android.support.v7.widget does not exist" problem?

I want to add an Action Bar to my app. And there is a problem appearing
error: package android.support.v7.widget does not exist.
I cannot fix that problem whatever i tried. Any solution on internet does not work on me.I do not know why this is happening and i am really tired of it. I am the beginner and this problem drives me crazy.I've tried to change
android.useAndroidX=true --> to false
and
android.enableJetifier=true --> false on gradle.properties
Yeah, its work!But here is another problem appearing:
java.lang.RuntimeException: 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
Here is my build.gradle:
compileSdkVersion 29
buildToolsVersion '29.0.1'
minSdkVersion 21
targetSdkVersion 29
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'com.google.android.material:material:1.1.0-alpha07'
testİmplementation 'junit:junit:4.13-beta-3'
androidTestİmplementation 'androidx.test:runner:1.3.0-alpha01'
androidTestİmplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:support-v13:28.0.0'
}
Could be problem on implementation methods, i do not know. May be i have a problem on SDK versions. I have tried migrate to AndroidX and not worked.
Try replacing
android.support.v7.widget
with
androidx.appcompat.widget
Welcome to stackoverflow!
You have both support library and androidx library in one project...that's your issue...
Change the support libraries to the preferred AndroidX library...
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'com.google.android.material:material:1.1.0-alpha07'
testİmplementation 'junit:junit:4.13-beta-3'
androidTestİmplementation 'androidx.test:runner:1.3.0-alpha01'
androidTestİmplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
}
Or you can probably Migrate to AndroidX and it can be done right in Android Studio
Simply go to Refactor > Migrate to AndroidX > Migrate
Adding an Action Bar
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/yourColor"/>
I hope this helps....
Please try this:
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

How to install lettuce library on Android Studio?

How to install lettuce library on Android studio in Gradle files ?
https://lettuce.io
is there any solution to compile the library ?
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0’
}
In the lettuce's getting started section there is a section called For Gradle Users on how to add the library from gradle. I think just adding:
implementation 'io.lettuce:lettuce-core:5.1.3.RELEASE'
would work. You must check if you must adjust your current dependencies and/or modify your proguard rules.
Hope I helped.

Program type already present com.google.gson.FieldAttributes

My android app refuses to build with the following error:
Program type already present: com.google.gson.FieldAttributes
Message{kind=ERROR, text=Program type already present: com.google.gson.FieldAttributes, sources=[Unknown source file], tool name=Optional.of(D8)}
My build.gradle dependencies
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:animated-vector-drawable:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:support-media-compat:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
api 'com.github.Steveice10:MCProtocolLib:1.12.2-2'
api 'com.github.Steveice10:OpenNBT:1.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation 'com.google.android.ads.consent:consent-library:1.0.6'
implementation 'com.github.GrenderG:Prefs:1.3' //Propably this cause problem
implementation('com.crashlytics.sdk.android:answers:1.4.2#aar') {
transitive = true
}
implementation('com.crashlytics.sdk.android:crashlytics:2.9.4#aar') {
transitive = true
}}
It probably started to happen when I added com.github.GrenderG:Prefs dependency
Add this line to build.gradle file.
configurations {
all*.exclude group: 'com.google.code.gson'
}
After 3 hours of googling around I finnaly found an Answer:
GPDR compilance library caused the problem
implementation ('com.google.android.ads.consent:consent-library:1.0.6') {
exclude module: 'gson'
}
add this code to your build.gradle(app) -
dependencies {
configurations {
all*.exclude group: 'com.google.code.gson'
}
This should solve your problem.
Add Dependency to build.gradle file
implementation 'com.google.code.gson:gson:2.8.2'

Categories

Resources