After attaching Firebase: Duplicate class com.google.android.gms.measurement.AppMeasurement - android

I'm programming Androidjava application displaying the map. Everything worked fine, until I decided to connect the application to Firebase. I followed the steps to edit the two gradle files.
Top gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath 'com.google.gms:google-services:4.3.10' // Google Services plugin
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App gradle file:
plugins {
id 'com.android.application'
}
apply plugin: 'com.google.gms.google-services' // Google Services plugin
android {
compileSdk 32
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.afs"
minSdkVersion 23
targetSdkVersion 30
versionCode 3163
versionName "3.0.163"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lint {
checkReleaseBuilds false
}
namespace 'com.afs'
}
dependencies {
// Firebase
implementation platform('com.google.firebase:firebase-bom:30.0.2')
implementation 'com.google.firebase:firebase-analytics'
// Play-services
implementation 'com.google.android.gms:play-services-maps:18.0.2'
implementation 'com.google.android.gms:play-services-base:18.0.1'
implementation 'com.google.android.gms:play-services-tasks:18.0.1'
implementation 'com.google.android.gms:play-services-ads:20.6.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'org.osmdroid:osmdroid-android:6.1.10'
implementation 'org.osmdroid:osmdroid-third-party:6.0.1'
implementation 'com.android.support:support-compat:28.0.0'
implementation 'androidx.work:work-runtime:2.7.1'
implementation 'com.android.volley:volley:1.2.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Error messages
Duplicate class com.google.android.gms.measurement.AppMeasurement found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-21.0.0-runtime (com.google.android.gms:play-services-measurement-impl:21.0.0)
Duplicate class com.google.android.gms.measurement.AppMeasurement$ConditionalUserProperty found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-21.0.0-runtime (com.google.android.gms:play-services-measurement-impl:21.0.0)
Duplicate class com.google.android.gms.measurement.AppMeasurement$EventInterceptor found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-21.0.0-runtime (com.google.android.gms:play-services-measurement-impl:21.0.0)
Duplicate class com.google.android.gms.measurement.AppMeasurement$OnEventListener found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-21.0.0-runtime (com.google.android.gms:play-services-measurement-impl:21.0.0)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-api-21.0.0-runtime (com.google.android.gms:play-services-measurement-api:21.0.0)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Event found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-api-21.0.0-runtime (com.google.android.gms:play-services-measurement-api:21.0.0)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Param found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-api-21.0.0-runtime (com.google.android.gms:play-services-measurement-api:21.0.0)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$UserProperty found in modules jetified-firebase-analytics-impl-12.0.1-runtime (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-api-21.0.0-runtime (com.google.android.gms:play-services-measurement-api:21.0.0)
Do you have any ideas how I can solve it? I stuck for two days and completely lost ideas of what to change :|

Related

I am getting lot of errors while setting up google maps API in my android Application

I am trying to integrate google maps API in my android application but getting lot of errors. I went through lot of questions online for solving the problem but couldn't find a single post which could help me. For this specific errors lot of solution recommended to toggle the offline button and I have already done that but it didn't help me. So anyone could help me in giving different solution. I am hereby attaching my build.gradle file for your reference
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
classpath 'com.google.gms:google-services:4.3.13'
classpath 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}
apply plugin: 'com.google.gms.google-services'
android {
compileSdk 31
defaultConfig {
applicationId "com.example.mppolice"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation "androidx.cardview:cardview:1.0.0"
}
dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
implementation 'com.google.firebase:firebase-auth:21.0.7'
implementation 'com.google.android.gms:play-services-maps:18.0.0'
implementation 'com.google.android.gms:play-services-location:18.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation platform('com.google.firebase:firebase-bom:30.3.1')
implementation 'com.google.firebase:firebase-analytics'
}
Following is the list of error I am getting while building my application
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugCompileClasspath'.
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve com.google.android.gms:play-services-maps:18.0.0.

Cannot resolve class androidx.drawerlayout.widget.DrawerLayout or com.google.android.material.navigation.navigationview

I have an app that works properly. Anyway, I have a "strange" behaviour of Android studio, in fact for the xml files it is not able to solve some classes, i.e. drawerLayout, constraintLayout, CircleImage etc. (see the image below)
Before opening android studio I have a warning about adding project dependencies:
Problem: Inconsistencies in the existing project dependencies found.
Version incompatibility between:
androidx.navigation:navigation-ui:2.5.1#aar and:
androidx.appcompat:appcompat:1.5.0#aar
With the dependency:
androidx.annotation:*1.1.0
androidx.annotation:*.2.0.0
What I tried:
invalidating caches and restarting app
update my gradle file, as shown below:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
id 'androidx.navigation.safeargs'
}
apply plugin: "androidx.navigation.safeargs"
sourceSets {
main {
java {
}
}
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.frangela"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation "androidx.navigation:navigation-fragment:2.5.1"
implementation "androidx.navigation:navigation-ui:2.5.1"
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.firebase:firebase-database:20.0.5'
implementation 'com.google.firebase:firebase-common-ktx:20.1.1'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'com.google.android.gms:play-services-location:20.0.0'
implementation 'com.google.firebase:firebase-crashlytics-buildtools:2.9.1'
implementation platform('com.google.firebase:firebase-bom:30.3.1')
implementation 'com.google.firebase:firebase-functions'
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation 'com.firebaseui:firebase-ui-database:8.0.1'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.android.gms:play-services-auth:20.2.0'
implementation 'com.squareup.picasso:picasso:2.8'
implementation 'com.google.firebase:firebase-messaging'
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.1"
}
My gradle Module:
buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://repo1.maven.org/maven2' }
}
dependencies {
def nav_version = "2.5.1"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
classpath 'com.android.tools.build:gradle:7.2.2'
classpath 'com.google.gms:google-services:4.3.13'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I think that there could be problems with the dependencies, but for example I cannot find any of that regarding annotation in my gradle file.
Thank you in advance for anyone that could help me.
You're applying androidx.navigation.safeargs twice and srcDirs += 'build/generated/source/navigation-args' also is useless. With high probability, this project is lacking a proper repositories configuration, while the question complete ignores this part. In case there should be any jcenter() repository, replace that with mavenCentral() or google().
After hours of works, I solved in a pretty easy way:
Copy all the project in another location on my PC
Reopen the project
After opening it from Android Studio, everything works fine

android butterknife not showing Generate butterknife generate injections in Android Studio4.1.2

I am trying to use butter knife in updated android studio 4.1.2 but not getting generate butterknife injection in Generate option.
I have already added Plugin: Android ButterKnife Zelezny
build gradle(Project)
/
/ Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(Module)
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.a.b"
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:26.3.0')
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-auth'
//butterknnife
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
}
after adding all this and restart android studio not getting butterknife injection option in generate
After trying and searching I found Butterknife is deprecated so it will not show
generate butterknife injection
from Generate option when click R.layout.abc.xml.
Solution 1
but it still works only you have to declare it manually like as below
import butterknife.BindView;
import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity {
#BindView(R.id.iv_upload)
ImageView ivUpload;
#BindView(R.id.textView)
TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.abc);
ButterKnife.bind(this);
}
}
Solution 2
as #CommonsWare recommendation in comment that use something else,
View binding is the current leading alternative.
All dependency declarations look fine. Please do a clean build that should solve the issue.
FYI You do not need to apply the butterknife plugin and the
classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
You just need to have the following dependencies in app build.gradle
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'

Gradle: How to get rid of duplicate classes error

I am getting the following duplicate class error when I run my Android application (I didn't include all the errors, but the duplicate errors are all coming from org.apache.commons.lang3.* and org.apache.commons.logging.*):
Duplicate class org.apache.commons.lang3.AnnotationUtils found in modules commons-lang3-3.4.jar (org.apache.commons:commons-lang3:3.4) and commons-lang3-3.7.jar (commons-lang3-3.7.jar)
Duplicate class org.apache.commons.lang3.AnnotationUtils$1 found in modules commons-lang3-3.4.jar (org.apache.commons:commons-lang3:3.4) and commons-lang3-3.7.jar (commons-lang3-3.7.jar)
...........
Duplicate class org.apache.commons.logging.impl.WeakHashtable found in modules commons-logging-1.2.jar (commons-logging-1.2.jar) and commons-logging-1.2.jar (commons-logging:commons-logging:1.2)
Duplicate class org.apache.commons.logging.impl.WeakHashtable$1 found in modules commons-logging-1.2.jar (commons-logging-1.2.jar) and commons-logging-1.2.jar (commons-logging:commons-logging:1.2)
Duplicate class org.apache.commons.logging.impl.WeakHashtable$Entry found in modules commons-logging-1.2.jar (commons-logging-1.2.jar) and commons-logging-1.2.jar (commons-logging:commons-logging:1.2)
Duplicate class org.apache.commons.logging.impl.WeakHashtable$Referenced found in modules commons-logging-1.2.jar (commons-logging-1.2.jar) and commons-logging-1.2.jar (commons-logging:commons-logging:1.2)
Duplicate class org.apache.commons.logging.impl.WeakHashtable$WeakKey found in modules commons-logging-1.2.jar (commons-logging-1.2.jar) and commons-logging-1.2.jar (commons-logging:commons-logging:1.2)
The error stems from this line of code in the gradle (I need to use the docx4j library because my app has to read in the contents of MS Word files selected by the user):
implementation "org.docx4j:docx4j:3.3.0"
Below is the complete code of my gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.diffchecker"
minSdkVersion 21
targetSdkVersion 29
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.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.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'io.github.java-diff-utils:java-diff-utils:4.5'
// For developers using AndroidX in their applications
implementation 'pub.devrel:easypermissions:3.0.0'
// For developers using the Android Support Library
implementation 'pub.devrel:easypermissions:2.0.1'
implementation 'com.google.android.gms:play-services-ads:18.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation files('libs/commons-text-1.2.jar')
//Thanks for using https://jar-download.com
implementation 'org.webjars.bowergithub.telecomsante:pdf-viewer:2.2.0'
implementation 'com.tom_roush:pdfbox-android:1.8.10.1'
implementation 'com.bskim:maxheightscrollview:1.0.0#aar'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation files('libs/commons-logging-1.2.jar')
implementation files('libs/commons-lang3-3.7.jar')
// Docx4j is the library used to read Word documents
// https://mvnrepository.com/artifact/org.docx4j/docx4j
implementation "org.docx4j:docx4j:3.3.0"
}
How do I use the docx4j library in my gradle without running into duplicate conflicts with the commons-lang3 and commons-logging libraries?
I think I found a similar way of what we did at the beginning but this time with both exclusions.
Try this:
implementation ('org.docx4j:docx4j:3.3.0') {
['org.apache.commons','commons-logging'].each {
exclude group: "$it"
}
}
Erase local lib and put this on the gradle
https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'

What does "duplicate class" mean?

I have problem with running my app. All of a sudden, the app began producing this error "duplicate class com.google.android.gms.location.places".
And I'm not even joking, I've been searching this whole site to fix this error, even deleting all project and creating a new one. But nothing, no. NOTHING solves it!
I believe I've been reading each single thread on this topic. Ofc, there's a solution there! It just happens to not be the correct solution for me...
This is the error line:
Duplicate class com.google.android.gms.location.places.zza found in modules classes.jar (com.google.android.gms:play-services-places-placereport:16.0.0) and classes.jar (com.google.android.gms:play-services-places:9.6.1)
This is my dependencies and app.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {url 'https://jitpack.io'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.qwisenow"
minSdkVersion 22
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.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0' // FusedLocationProviderClient
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.stripe:stripe-android:8.7.0'
implementation 'com.github.f0ris.sweetalert:library:1.5.6'
implementation 'com.ebanx:swipe-button:0.8.3'
implementation 'me.dm7.barcodescanner:zxing:1.9.13'
implementation 'com.braintreepayments:card-form:3.1.1'
implementation 'com.github.aarsy.googlemapsanimations:googlemapsanimations:1.0.5'
implementation 'com.android.support:cardview-v7:28'
implementation 'com.vipulasri:ticketview:1.0.7'
implementation 'me.philio:pinentryview:1.0.6'
implementation 'com.github.ar-android:DrawRouteMaps:1.0.0'
implementation 'com.codemybrainsout.onboarding:onboarder:1.0.4'
implementation 'com.karumi:dexter:5.0.0'
}
Can anybody see something looks "duplicate" there? I can't, and I've tried probably 30 solutions on this, but Android Studio keeps give me errors...

Categories

Resources