Dex file exceeded 64k after adding appbrain-sdk:14.30 - android

I was adding Appbrain Sdk for Ads to my app gradle
compile 'com.appbrain:appbrain-sdk:14.30'
Now I'm getting this error:
Error:The number of method references in a .dex file cannot exceed 64K.
I followed the instruction by adding multiDexEnabled true to my code and I get OutOfMemoryException
Here is my code
my app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.webstore.footballscores"
minSdkVersion 17
targetSdkVersion 26
versionCode 8
versionName "1.7"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
jumboMode true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.4.1'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.google.android.gms:play-services-ads:15.0.1'
compile 'com.facebook.android:audience-network-sdk:4.23.0'
compile 'com.google.firebase:firebase-core:16.0.0'
compile 'com.google.firebase:firebase-iid:16.0.0'
compile 'com.google.firebase:firebase-messaging:17.0.0'
compile 'com.google.android.gms:play-services-analytics:16.0.0'
compile 'com.google.android.gms:play-services-tagmanager:16.0.0'
compile 'com.firebase:firebase-jobdispatcher-with-gcm-dep:0.8.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.startapp:inapp-sdk:3.9.3'
compile 'com.appbrain:appbrain-sdk:14.30'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck=true

Add this code block to your build.gradle in android block.
dexOptions {
javaMaxHeapSize "4g"
}
instead of
dexOptions {
jumboMode true
}
This should solve your problem. Good luck.

Related

Error:Conflict with dependency 'com.android.support:support-annotations' in project ':app'

I was trying to solve this gradle error.I imported this project by getting it from a friend of mine.It worked in his system perfectly. Seems like I have a The following issues in my gradle.
Error:Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (27.0.2) and test app (25.4.0) differ.
The following are my gradle
Module app
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
defaultConfig {
applicationId "com.startup.hospital"
minSdkVersion 15
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(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:27.+'
compile 'com.android.support:support-vector-drawable:27.0.2'
compile 'com.android.support:support-v4:27.0.2'
compile 'com.aurelhubert:ahbottomnavigation:2.1.0'
compile 'com.github.arimorty:floatingsearchview:2.1.1'
compile 'com.ss.bottomnavigation:bottomnavigation:1.5.2'
compile 'jp.wasabeef:glide-transformations:2.0.2'
compile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:1.0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Project gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.1"
defaultConfig {
applicationId "com.startup.hospital"
minSdkVersion 15
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(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:27.+'
compile 'com.android.support:support-vector-drawable:27.0.2'
compile 'com.android.support:support-v4:27.0.2'
compile 'com.aurelhubert:ahbottomnavigation:2.1.0'
compile 'com.github.arimorty:floatingsearchview:2.1.1'
compile 'com.ss.bottomnavigation:bottomnavigation:1.5.2'
compile 'jp.wasabeef:glide-transformations:2.0.2'
compile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:1.0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Just add the following in your build.gradle (:app)
configurations.all {
resolutionStrategy {
force 'com.android.support:appcompat-v7:26.+'
force 'com.android.support:support-compat:26.+'
force 'com.android.support:support-core-ui:26.+'
force 'com.android.support:support-annotations:26.+'
force 'com.android.support:recyclerview-v7:26.+'
}
}
Your espresso has already those dependencies same as you have declared above for support library with different version which is causing problem so exclude theme like below from module build.gradle file
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
here is what it should look like
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
defaultConfig {
applicationId "com.startup.hospital"
minSdkVersion 15
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(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:27.+'
compile 'com.android.support:support-vector-drawable:27.0.2'
compile 'com.android.support:support-v4:27.0.2'
compile 'com.aurelhubert:ahbottomnavigation:2.1.0'
compile 'com.github.arimorty:floatingsearchview:2.1.1'
compile 'com.ss.bottomnavigation:bottomnavigation:1.5.2'
compile 'jp.wasabeef:glide-transformations:2.0.2'
compile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:1.0.1'
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
and Your project level build.gradle file should not have those dependencies declared again.
just added this
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:22.1.0'
}

"Method references in a .dex file cannot exceed 64K" after changing build.gradle

I'm getting that error that says I have too many method references:
Error:The number of method references in a .dex file cannot exceed 64K.
It all started when I tried to change my targetSdkVersion to 24 and minSdkVersion to a lower sdk (19) via the gradle app file. That led me to having to change some values throughout the file like
compile 'com.android.support:appcompat-v7:23.0.0'
to
compile 'com.android.support:appcompat-v7:24.1.1'
I've read that people get this error when they have the wrong values in build.gradle. Here was my original build.gradle before the changes:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.delbridge.seth.alarm"
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
debug {
debuggable true
}
}
}
Any thoughts as to what's causing this?
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'org.jsoup:jsoup:1.9.2'
compile 'org.jdeferred:jdeferred-android-aar:1.2.4'
compile 'com.google.android.gms:play-services-appindexing:9.0.2'
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:cardview-v7:23.0.+'
compile 'com.android.support:recyclerview-v7:23.0.+'
compile 'com.google.firebase:firebase-ads:9.0.2'
}
apply plugin: 'com.google.gms.google-services'
And here is my build.gradle currently:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.delbridge.seth.alarm"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'org.jsoup:jsoup:1.9.2'
compile 'org.jdeferred:jdeferred-android-aar:1.2.4'
compile 'com.google.android.gms:play-services-appindexing:9.4.0'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.google.firebase:firebase-ads:9.4.0'
compile 'com.google.android.gms:play-services-ads:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
}
apply plugin: 'com.google.gms.google-services'
You're unnecessarily including all of Google Play Services with this line:
compile 'com.google.android.gms:play-services:9.4.0'
So, remove that line and leave the ones that include the individual components:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'org.jsoup:jsoup:1.9.2'
compile 'org.jdeferred:jdeferred-android-aar:1.2.4'
compile 'com.google.android.gms:play-services-appindexing:9.4.0'
//remove this line:
//compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.google.firebase:firebase-ads:9.4.0'
compile 'com.google.android.gms:play-services-ads:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
}
Note:
If the above solution does not solve your issue, then you will need to enable multidex.
try this in your build.gradle file:
android {
compileSdkVersion 22
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22
// Enabling multidex support.
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
check this page: https://developers.google.com/android/guides/setup
and use needed google play service

Execution failed ':app:transformClassesWithDexForDebug' - GC overhead limit exceeded

have a problem with gradle, my app wont compile and appear this error on "0:Messages" tab, here my code on my build.gradle(app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "app.nucleo.com.doctoc"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental = true;
preDexLibraries = false
javaMaxHeapSize "4g" // 2g should be also OK
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile project(path: ':backend', configuration: 'android-endpoints')
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:appcompat-v7:24.0.0-alpha2'
compile 'com.android.support:support-v4:24.0.0-alpha2'
compile 'com.android.support:design:24.0.0-alpha2'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-auth:8.4.0'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.28'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services-ads:8.4.0'
}
screenshot:
http://i.stack.imgur.com/6BTaw.png
any can help me?
remove from your dependencies:
compile 'com.google.android.gms:play-services:8.4.0'
and look exactly for what else you need from play-services from here.
Fine tune your play-services so you don't include the entire package. Then it won't exceed the 64k function limit and you can remove the multidex thing that I assume you added because it was objecting.
multiDexEnabled false
And the exact play services so it all fits in the same same dex file.

OutOfMemory Error , Too much library files in Android Studio

I am developing a project, which uses a module(library project). Independently both are working fine, but when I am integrating both they starts to throw error in gradle build.
**Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.commom.process.ProcessException: org.gradle.process.internal.ExceException: Process 'command'C:\Program Files\Java\jdk1.8.0_65\bin\java.exe" finished with non-zero exit value 2**
I have almost same import of library set in both the modules, because of security issues I needed to put these modules seperately.
Following are the build.gradle files for both
app : build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "*************************"
multiDexEnabled true
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile files('libs/khandroid-httpclient-4.2.3.jar')
compile project(':library')
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup:otto:1.3.5'
compile 'org.jsoup:jsoup:1.8.3'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'commons-codec:commons-codec:1.6'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
library : build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
multiDexEnabled true
minSdkVersion 14
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 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.squareup:otto:1.3.5'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'commons-codec:commons-codec:1.6'
}
I had already enabled multidexedenabled true .
Any help will be appreciable. Thanks
I solved this issue.Following are the steps I take:
1) In gradle.properties file of project un-comment the line
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
And write : org.gradle.daemon=true
2)In my project module app:build.gradle, I removed all the dependencies that has been there in library's build.gradle file.

No class found exception com.squareup.okhttp.logging.HttpLoggingInterceptor

Even after adding the dependencies and importing the class I am getting java.lang.NoClassDefFoundError: com.squareup.okhttp.logging.HttpLoggingInterceptor.
Can anyone please help?
Gradle Build file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "xyz"
minSdkVersion 15
targetSdkVersion 23
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.google.code.gson:gson:2.4'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'com.squareup.okhttp:logging-interceptor:2.6.0'
}
In my case, I found that the versions of the okhttp3 and okhttp3:logging-interceptor dependencies needed to exactly match. So for example:
...
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
...
Could be a compatibility problem with retrofit.
Try with :
implementation 'com.squareup.okhttp:logging-interceptor:2.5.0'
This post could be help
App crash on HttpLoggingInterceptor
Also it can be connected with multidex true option in your build.gradle (yes, seems like some devices have problems with multidex apps (read, Samsung))
If this is your case, switch this flag off and rebuild your project. Consider using
minifyEnabled true
shrinkResources true
to reduce your apk size. If it is still too large, that's really weird and bad news, but there are some techniques to put your apk on diet.

Categories

Resources