i am trying to add firebase-messaging in my project where i am already using google maps. so when i add firebase dependecy
compile 'com.google.firebase:firebase-messaging:10.0.1'
i got following error.
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
how can i solve this issue
here is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.edesign.astutesol.sallaticustomerapp"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.1.1'
compile 'com.mcxiaoke.volley:library:1.0.15'
compile 'com.github.lecho:hellocharts-library:1.5.8#aar'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.google.android.gms:play-services-auth:10.0.1'
apply plugin: 'com.google.gms.google-services'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.android.support:cardview-v7:25.+'
compile 'org.lucasr.twowayview:twowayview:0.1.4'
}
these are google dependencies
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.google.android.gms:play-services-auth:10.0.1'
apply plugin: 'com.google.gms.google-services'
compile 'com.google.firebase:firebase-messaging:10.0.1'
enable multidex in your default config.
defaultConfig {
applicationId "com.edesign.astutesol.sallaticustomerapp"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
}
If enabling multidex support hasn't worked for you it can be because you might have defined custom application class for your app. What's the application name in your manifest file? If you have defined a custom application class by extending Application (say for example to integrate ACRA, or google analytics) then you will have to override attachBaseContext method.
#Override
protected void attachBaseContext(Context context) {
super.attachBaseContext(context);
MultiDex.install(this);
}
short answer: remove compile 'com.google.android.gms:play-services:10.0.1'
You should not have the following line in your build.gradle
compile 'com.google.android.gms:play-services:10.0.1'
that line will include ALL the google libraries in your applications, which will exceed the method limit (the error you reported) and will make your app big without benefits.
You should include only the sub library that you need.
Example:
compile 'com.google.android.gms:play-services-auth:10.0.1
is ok because you are including only the -auth parth of the library.
Related
i'm having a probleme when creating the APK
When i run the app, it works fine but when i build the apk it says
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/location/places/PlaceReport.class
gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.1'
useLibrary 'org.apache.http.legacy'
configurations {
}
defaultConfig {
applicationId "inc.exemple"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.1.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.baoyz.pullrefreshlayout:library:1.2.0'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
compile 'com.1gravity:android-rteditor:1.6.2'
compile 'com.github.irshulx:laser-native-editor:0.3.5'
compile 'com.github.arturogutierrez:badges:1.0.5#aar'
compile 'com.mikepenz:actionitembadge:3.3.1#aar'
compile 'com.mikepenz:iconics-core:2.8.1#aar'
compile 'com.mikepenz:fontawesome-typeface:4.7.0.0#aar'
compile 'com.synnapps:carouselview:0.0.10'
compile 'com.google.firebase:firebase-messaging:9.8.0'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
}
I believe i should exlude it, but i don't know how, please help, thank you.
So i had to create a new empty project and copy all the libs in it, and try one by one to find which one was containing the problem. the error was coming from the com.github.irshulx:laser-native-editor:0.3.5, it worked after i deleted it, then i modified the whole project and used another work around.
Receving this error on KitKat and lower version running perfectly on Lollipop and above
I have included all the required jars in th gradle and Firebase json file to receive GCM.
my app gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "24.0.0"
defaultConfig {
applicationId ""
minSdkVersion 13
targetSdkVersion 23
versionCode 6
versionName "1.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
defaultConfig {
multiDexEnabled true
}
useLibrary 'org.apache.http.legacy'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':httpmime-4.2.5')
compile project(':universal-image-loader-1.9.3')
compile project(':universal-image-loader-1.9.3')
compile group: 'org.apache.httpcomponents', name: 'httpclient-android', version: '4.3.3'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile 'com.android.support:design:23.4.0'
compile 'com.google.android.gms:play-services:9.0.0'
testCompile 'junit:junit:4.12'
}
This dependency includes the code for all of the Google Play Services APIs:
compile 'com.google.android.gms:play-services:9.0.0'
This is very likely causing your app to exceed the 65K method reference limit, requiring you to use Multidex to run on pre-Lollipop devices.
You have two choices. You can include only the Play Services APIs you actually need. The list is here in the section titled Selectively compiling APIs into your executable. Or you can enable Multidex following the instructions here. Although you have multiDexEnabled true in your build.gradle file, that is only one of the three steps required to configure Multidex. You also need to include the library as a dependency and update your manifest.
If you are using Android Studio 2.2.2, you can see how many method references are in your app using the APK Analyzer. From the menubar, select Build > Analyze APK. The APK is in folder .../app/build/outputs/apk. Select the APK file, and in the resulting window, click on classes.dex to see the number of methods and method references.
Please update the firebase dependencies
dependencies {
...
compile 'com.google.firebase:firebase-messaging:9.6.0'
...
}
apply plugin: 'com.google.gms.google-services'
Hope it helps..
All day I have a challenge with resolve update of some dependencies in my new project.
This is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com...."
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.firebase:firebase-database:9.6.1'
compile 'com.google.firebase:firebase-storage:9.6.1'
compile 'com.firebaseui:firebase-ui:0.4.3'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.android.gms:play-services:9.6.1'
}
apply plugin: 'com.google.gms.google-services'
and error is:
Error:
"Execution failed for task: ':app:transformClassesWithDexForDebug'
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/home/bin/java" finished with non zero-exit value 2
The problem was showing when I tried to upload an image to Firebase storage. There was error with an internet connection etc. I decided to make update of libraries. After this there is an error with jdk 1.8.
Could somebody help me to resolve this challenge?
Regards
Basically you would also want to check and resolve version conflicts in your app's dependencies.
Also check if you have enabled multidex in your app.
I had a similar issue. In my app I am using guava-retrying library, which was fetching google guava library version 21. Guava version 21 requires JDK 1.8 without providing back porting support and this was causing this error in my case.
I was able to solve it by including the guava-retrying library so that it uses version 19.0 of guava library:
compile ("com.github.rholder:guava-retrying:2.0.0") {
exclude group: 'com.google.guava', module: 'guava'
}
compile 'com.google.guava:guava:19.0'
I believe you need to enable Multidex for your application.
add the Multidex library to your dependencies, then enable Multidex in defaultConfig.
Example:
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com...."
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.firebase:firebase-database:9.6.1'
compile 'com.google.firebase:firebase-storage:9.6.1'
compile 'com.firebaseui:firebase-ui:0.4.3'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.android.gms:play-services:9.6.1'
compile 'com.android.support:multidex:1.0.0'
}
Then in `AndroidManifest.xml", enable Multidex installation:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
Source: https://developer.android.com/studio/build/multidex.html#mdex-gradle
My app is working properly. There is no problem. i want to build generated signed apk. The problem is building take too long and completed with errors.
Please check the image. Thanks.
Error:Execution failed for task ':app:transformClassesWithDexForRelease'.> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
here my gradle;
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "umut.com.anyidea"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.firebase:firebase-messaging:9.6.0'
compile 'com.google.firebase:firebase-core:9.6.0'
compile 'com.google.firebase:firebase-crash:9.6.0'
compile 'com.google.android.gms:play-services:9.6.0'
compile 'com.google.android.gms:play-services-auth:9.6.0'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.afollestad.material-dialogs:core:0.9.0.1'
compile 'com.google.firebase:firebase-database:9.6.0'
compile 'com.google.firebase:firebase-auth:9.6.0'
compile 'com.firebaseui:firebase-ui-database:0.6.0'
}
apply plugin: 'com.google.gms.google-services'
In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.
From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs,
Please refer this document:
https://developers.google.com/android/guides/setup
for example if you need Google Account Login then just use :
com.google.android.gms:play-services-auth:9.6.1 not use compile 'com.google.android.gms:play-services:9.6.1'
just add this and try.
its works for me.
defaultConfig {
multiDexEnabled true
}
// multidex issues
compile 'com.android.support:multidex:1.0.0'
or
dexOptions {
javaMaxHeapSize "4g"
}
Have you add this in Application class
MultiDex.install(this);
Put this line in defaultConfig block
multiDexEnabled true
And add the following dependencies
compile 'com.android.support:multidex:1.0.0'
After this rebuild your project. Hopefully this should resolve your error.
Just remove unused libraries (or dependencies) from app's build.gradle file and again try to generate signed apk. It will work. :)
My error:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class
I'm trying to use Stripe and integrate it with retrofit. I have the Stripe lib build.gradle file and the app build.gradle file.
I dont see whats causing this error and I need the dependency in both build.gradle files because both Stripe and Retrofit use it.
app build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.weaverprojects.stripe2"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':stripe')
//compile 'com.android.support:support-v4:18.0.+'
compile 'com.google.code.gson:gson:2.3'
compile 'org.parceler:parceler:0.2.13'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup:otto:1.3.6'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
}
Stripe build.gradle:
apply plugin: 'com.android.library'
dependencies {
// compile 'com.stripe:stripe-java:1.15.1'
// compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/gson-2.2.4.jar')
compile files('libs/stripe-java-1.15.1.jar')
}
android {
compileSdkVersion 21
buildToolsVersion '23.0.1'
defaultConfig {
minSdkVersion 7
targetSdkVersion 21
multiDexEnabled = true
}
}
I do have the Stripe and GSON jar in the libs folder so I tried changing:
compile 'com.google.code.gson:gson:2.3'
to
compile files('../stripe/libs/gson-2.2.4.jar')
in the app's build.gradle.
What am I doing wrong?
Thanks in advance.
The root of the issue is that you're mixing a dependency on a jar via compile files('libs/gson-2.2.4.jar') and a maven artifact via compile 'com.google.code.gson:gson:2.3'.
When you reference the same maven artifact in separate parts of your project, Gradle is able to intelligently figure out that it shouldn't include both. But, Gradle is unable to figure out that the jar you're referencing is the same as the maven artifact you're referencing.
Solution
In Stripes build.gradle, change the lib reference to compile 'com.google.code.gson:gson:2.3', and delete gson-2.2.4.jar from your project entirely.
Either remove the line compile 'com.google.code.gson:gson:2.3'
or
Delete the gson jar from your lib folder. because you have included the library twice once in build file and in libs folder.