Generate Signed Apk Error Multidex - android

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. :)

Related

google gms:play service conflict with firebase

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.

com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException:com.google.firebase.provider.FirebaseInitProvider

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..

While adding any new dependencies in android build.gradle file. it always show an error

Error:(42, 13) Failed to resolve: com.android.volley:volley:1.0.0
When add any dependencies in android build.gradle file it always shows the above error. But same project is running on a different machine same dependencies can add successful. I search lot for solving this problem but can't find any solution. Kindly Please help me to fix the problem Thank you.
I face the same error while adding any dependencies now, but few weeks before i can add any dependencies on my project
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "myappid"
minSdkVersion 17
targetSdkVersion 24
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter({url "http://jcenter.bintray.com/"})
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.android.support:cardview-v7:24.0.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.android.support:support-vector-drawable:24.0.0'
// VectorDrawableCompat
compile 'com.android.support:animated-vector-drawable:24.0.0'
compile 'com.android.support:support-annotations:24.0.0'
compile 'com.satsuware.lib:usefulviews:2.3.6'
compile 'com.github.ganfra:material-spinner:1.1.1'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile 'com.ramotion.foldingcell:folding-cell:1.0.1'
compile 'com.android.volley:volley:1.0.0'
}
I try many way to solve the problem i have faced but no one can rectify the problem. I ask the help of may experience developer, they told me that they never face such a problem in there life. So only solution i found is to reinstall android studio. Now it work perfectly. Any way thanks for your support.

Gradle Build Run error (DebugUtils.class) in Android Studio 1.5

I'm getting the following error
Error:Execution failed for task
:app:transformClassesWithJarMergingForDebug.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/util/DebugUtils.class
I searched the entire day but couldn't found a proper answer which will solve my problem.
My app bulid gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.project.test"
multiDexEnabled true
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
dexOptions {
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
// depend files
dependencies
{
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services-ads:+'
compile 'com.google.android.gms:play-services-identity:+'
compile 'com.google.android.gms:play-services-gcm:+'
compile files('libs/android-support-v4.jar')
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
}
I tried Clean and Rebuild, but that also not working.
Please help on this. Thanks in advance.
This issue happens when you add the same class twice.
In your project you are adding many times the support-v4 library.
remove android-support-v4.jar from libs folder
remove this line compile files('libs/android-support-v4.jar')
change the dependency of the library 'com.github.JakeWharton:ViewPagerIndicator:2.4.1' because it uses an old support-v4.jar
Use:
compile ('com.github.JakeWharton:ViewPagerIndicator:2.4.1') {
exclude module: 'support-v4'
}
After doing some research it seams that com.github.JakeWharton:ViewPagerIndicator:2.4.1 is already importing the android-support-v4.jar, from here your duplicate error. In order to fix it I recommend you to do the following changes:
remove android-support-v4.jar from libs folder
remove from gradle file the line compile files('libs/android-support-v4.jar').
Hope it fixes your problem.

Build Gradle Android studio Build Slow

I use Android Studio to build my android application. But my laptop take 5 mins to build app. I don't know why. It's always load to build gradle too slow. Here is my code Build Gradle :
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
repositories { mavenCentral() }
defaultConfig {
applicationId "thsoft.com.sosme"
minSdkVersion 15
targetSdkVersion 23
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:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.wang.avi:library:1.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.jakewharton:disklrucache:2.0.2'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.crittercism:crittercism-android-agent:5.5.0-rc-1'
}
Could you help me to solved it? Thank you!
There is nothing wrong with the gradle code, but way too many dependencies. It depends on your processor's speed and memory. Try getting 8gb of memory and you'll be just fine. According to official site, minimum requirement is 4gb!!
Try enable offline mode to ignore up-to-date checks:
http://tools.android.com/recent/androidstudio040released
Or change build type to Debug :
Build Variants - > Debug ( Bottom Left corner AS)
Gluck!
Install the latest Android Studio 2.0 preview release. Its just awesome and it will reduce the gradle build time for sure. Let's try
to increase your build time you just need to increase your RAM
and in your gradle file remove those dependencies which are not required.
You have used play services which is huge. If you are using Google Cloud Messaging use com.google.android.gms:play-services-gcm:8.3.0. definitely it will reduce your build time. Don't put whole play services. Be specific which play service you are using.
this Link may help you https://developers.google.com/android/guides/setup
Good Luck

Categories

Resources