Android: Multiple dex files define Lcom/google/android/gms/location/places/zza; - android

I can't stop getting this error every time, and I don't know what caused it and how I can solve it:
Multiple dex files define Lcom/google/android/gms/location/places/zza;
I think it may have to do with google-services, but I'm not entirely sure.
app/build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.xxxx.xxxx"
minSdkVersion 14
targetSdkVersion 28
versionCode 10173
versionName "4.3"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// Fixes "Duplicate files copied in APK" build bug
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
dependencies {
// Pushy SDK
implementation 'com.google.firebase:firebase-messaging:17.5.0'
compile 'me.pushy:sdk:1.0.43'
// AppCompat v7 Dependency
compile 'com.android.support:appcompat-v7:28.0.0'
compile 'com.google.android.gms:play-services-maps:16.1.0'
compile 'com.google.android.gms:play-services-places:10.2.0'
// Google Play Services Dependencies
compile 'com.google.android.gms:play-services-location:16.0.0'
compile 'com.google.android.gms:play-services-ads:17.1.1'
// All .jar files in ./libs
compile fileTree(dir: 'libs', include: ['*.jar'])
}
apply plugin: 'com.google.gms.google-services'

If your app has more than 65535 methods, you need to enable the multidex format for your app.
This can be caused by having lots of dependencies in your project.

Related

Error while integrating firebase to android studio

i am trying to integrate firebase to my android project but constantly getting error of
"In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[17.0.
4]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.
Dependency failing: com.google.firebase:firebase-messaging:17.3.4 -> com.google.firebase:firebase-iid#[17.0.4], but fire
base-iid version was 20.0.2."
my code for the app gradle build is-------
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.goldfish"
minSdkVersion 17
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'
}
}
packagingOptions {
// Exclude file to avoid
// Error: Duplicate files during packaging of APK
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
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.google.firebase:firebase-messaging:17.3.4"
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.firebase:firebase-analytics:17.2.2'
}
Upgrade to the latest versions of the Firebase libraries:
implementation 'com.google.firebase:firebase-messaging:20.1.5'
implementation 'com.google.firebase:firebase-analytics:17.3.0'

Gradle Build fails [Android] 'META-INF/kotlinx-coroutines-core.kotlin_module'

Gradle did build my little adroid app fine.
After a while I added some more dependencies, it began to raise this error message and fails building.
Found similar problems, but all stated to exclude. Didnt help.
"
More than one file was found with OS independent path 'META-INF/kotlinx-coroutines-core.kotlin_module'
"
import looks like this
import kotlinx.coroutines.experimental.async
Gradle Build fiel looks like this
"
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
//exclue 'META-INF/kotlinx-coroutines-core.kotlin_module'
}
compileSdkVersion 27
defaultConfig {
applicationId "com.example.a18mas.app_mp3"
minSdkVersion 15
targetSdkVersion 27
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(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.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'
/*_______________________NEW DEPENDENCIES______________________*/
//local
implementation files("/libs/ftp4j-1.7.2.jar", "/libs/kotlinx-coroutines-core-0.22.5.jar")
//public
implementation 'com.beust:klaxon:3.0.1'
implementation 'com.github.kittinunf.fuel:fuel:+' //for JVM
implementation 'com.github.kittinunf.fuel:fuel-android:+' //for Android
implementation 'com.github.kittinunf.fuel:fuel-livedata:+' //for LiveData support
implementation 'com.github.kittinunf.fuel:fuel-rxjava:+' //for RxJava support
implementation 'com.github.kittinunf.fuel:fuel-coroutines:+' //for Kotlin Coroutines support
implementation 'com.github.kittinunf.fuel:fuel-gson:+' //for Gson support
implementation 'com.github.kittinunf.fuel:fuel-jackson:+' //for Jackson support
implementation 'com.github.kittinunf.fuel:fuel-moshi:+' //for Moshi support
implementation 'com.github.kittinunf.fuel:fuel-forge:+' //for Forge support
}
"
You probably did this but ...
clean and build project
rebuild Gradle
restart IDE (this did the trick for me when I had weird gradle issues)
check all the version numbers of the dependencies
I had the same issue with coroutines
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutine_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutine_version"
I updated packagingOptions like this
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/main.kotlin_module'
}
After it everything work correctly.

android studio: duplicating files even when using exclude fix

I am having trouble building my app all of a sudden.
the error:
Error:Execution failed for task
Duplicate files copied in APK lib/x86_64/libogg.so
File1: C:\Users\name\.android\build-cache\72c018be052ae391eef4ab43483d6a04be10a818\output\jni
File2: C:\Users\name\.android\build-cache\425f82e82c18acce2ff0ced2ade670804d31a815\output\jni
I have attempted to fix using packaging options:
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LGPL2.1'
}
entire file
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LGPL2.1'
}
defaultConfig {
applicationId "myappsid"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:support-v4:26'
compile 'com.android.support:support-vector-drawable:26'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'com.google.android.gms:play-services-ads:11.0.4'
compile 'com.ibm.watson.developer_cloud:android-sdk:0.4.2'
compile 'com.ibm.watson.developer_cloud:java-sdk:3.9.1'
testCompile 'junit:junit:4.12'
compile project(':library-release')
}
any help is greatly appreciated. I have tried longer exclude options as well in other posts that I have found but that didn't help either.
You can try using pickFirst in packagingOptions. You need to get the correct package name of libogg.so from File1 or File2:
packagingOptions {
pickFirst 'com/library/name/lib/x86_64/libogg.so'
...
}
UPDATE:
There is a conflicted dependencies:
compile 'com.ibm.watson.developer_cloud:android-sdk:0.4.2'
compile 'com.ibm.watson.developer_cloud:java-sdk:3.9.1'
From the Watson Developer Cloud Java SDK documentation you can find the following:
The Android SDK utilizes the Java SDK while making some
Android-specific additions. This repository can be found here. It
depends on OkHttp and gson.
which is pointing to the first library. So, you should only use:
compile 'com.ibm.watson.developer_cloud:android-sdk:0.4.2'

Android Studio: Duplicate files copied in APK project.properties

After adding the Google Translate API compile 'com.google.cloud:google-cloud-translate:0.18.0-beta' to my project, I have been getting a strange error
Error:Execution failed for task ':ParseStarterProject:transformResourcesWithMergeJavaResForDebug'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK project.properties
File1: .gradle/caches/modules-2/files-2.1/com.google.cloud/google-cloud-translate/0.18.0-beta/9cac04f2bb48f76f352bf65d782506e4aa18406c/google-cloud-translate-0.18.0-beta.jar
File2: /.gradle/caches/modules-2/files-2.1/com.google.cloud/google-cloud-core/1.0.2/ff451b4b785369093bd91d277c22576fc9c1da3a/google-cloud-core-1.0.2.jar
There are other SO posts which mention "Duplicate files copied in APK META_INF", or "Duplicate files copied in APK LICENSE.txt", etc
However, I have not seen anyone else encounter the error "duplicate files copied in APK project.properties"
Adding these to my gradle does not work
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/io.netty.versions.properties'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
Is there something else I can add to my gradle to fix this error? Or is there another way to fix this error by removing "FILE2" as shown in the error logs?
GRADLE
apply plugin: 'com.android.application'
android {
useLibrary 'org.apache.http.legacy'
packagingOptions {
// exclude 'META-INF/LICENSE'
//exclude 'META-INF/io.netty.versions.properties'
//exclude 'META-INF/INDEX.LIST'
}
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
multiDexEnabled true
applicationId "com.package.name"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 41
versionName "2.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
disable 'MissingTranslation'
disable 'ExtraTranslation'
}
dexOptions {
javaMaxHeapSize "4g"
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.firebase:firebase-core:10.2.0'
compile 'com.google.firebase:firebase-messaging:10.2.0'
//noinspection GradleCompatible
compile 'com.google.cloud:google-cloud-translate:0.18.0-beta'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.parse.bolts:bolts-tasks:1.3.0'
compile 'com.parse:parse-android:1.13.0'
compile 'com.android.support:multidex:1.0.1'
//noinspection GradleDynamicVersion
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
//noinspection GradleCompatible
compile 'com.google.android.gms:play-services-ads:10.2.0'
// compile 'com.onesignal:OneSignal:3.4.3#aar'
}
}
apply plugin: 'com.google.gms.google-services'
dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.1'
}
in my case,
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/io.netty.versions.properties'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'project.properties' <------------------------here
}
Remove the google cloud core dependancy
While adding translate dependancy do this
compile ('com.google.cloud:google-cloud-translate:0.5.0') {
exclude group: 'io.grpc', module: 'grpc-all'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'com.google.api-client', module: 'google-api-client-
appengine'
}

Failed to resolve: com.google.android.gms:play-services-gcm:8.7+

I want to use some Google services in my application, so I have added this line to the .gradle file: com.google.android.gms:play-services-gcm:8.7+. But after trying to sync the project I got this error:
Failed to resolve: com.google.android.gms:play-services-gcm:8.7+
I checked all the available answers on Stackoverflow. They suggest installing the sdk for Google repository and Google play services and I did that. Here is a screenshot of the sdks installed on my computer:
Here is the gradle file code:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.project.android.eyedetection"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/localization/LocalizedFormats_fr.properties'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile project(':libraries:opencv')
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services:8.7+'
compile files ('libs/commons-math-2.2.jar')
compile files ('libs/commons-math-2.2-javadoc.jar')
compile files ('libs/commons-math-2.2-sources.jar')
}
I tried to remove the +, but that didn't solve it.
How can I solve the problem?
EDIT: As suggested by Stanojkovic and Gabriele Mariotti using 8.4 solves the problem, this is because I was mistakenly trying to use 8.7 which is not released yet. Thanks all.
Try with
com.google.android.gms:play-services-panorama:8.4.0
Your issue depends by
compile 'com.google.android.gms:play-services:8.7+'
This version is not published yet (the apk is still in rollout, but the library is not public in the IDE)
Use the last stable release:
compile 'com.google.android.gms:play-services:8.4.0'

Categories

Resources