MultiDex error after updating GCM gradle - android

I was using
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-appinvite:8.4.0'
in my application build.gradle and this in my project build.gradle
classpath 'com.google.gms:google-services:2.0.0-beta2'
From last 10 days i was getting crash because of GCM at the time of InstanceId.
So i found that we need to update GCM to latest gradle so i did the same
classpath 'com.google.gms:google-services:3.0.0'
and
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile 'com.google.android.gms:play-services-appinvite:9.0.2'
but now am getting Multidex error due to this. So i tried to resolve that too by following few steps like extending Application class with MultiDexApplication and all. Still getting the same issue.
My gradle dependencies
compile project(':aws-android-sdk-core-2.2.9')
compile project(':aws-android-sdk-s3-2.2.9')
compile project(':universal-image-loader-1.9.5')
compile project(':FlurryAnalytics-6.2.0')
compile project(':circularImageView')
compile project(':swipeMenuListView')
compile 'com.couchbase.lite:couchbase-lite-android:1.2.0'
compile 'com.instabug.library:instabugsupport:1.+'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-appinvite:8.4.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:multidex:1.0.1'
Any help will be appreciated!

In your build.gradle you may use this
compile 'com.google.android.gms:play-services:8.3.0'
So, remove it and use the needed API only,
Check the VicVu Answer in this link,
gradle - Android Studio build too slow multidex application

Have you tried adding the heap size adjustment to your build.gradle file? For example this will set the max heap size for dexing to 4GB, and it will also enable
multiDexEnabled option.
android {
...
dexOptions {
javaMaxHeapSize "4g"
}
defaultConfig {
multiDexEnabled true
}
}

Related

Application keeps crashing on start when apk is build using mac

I have an android project, When i build the project using mac application crashes on start. When same is done using Windows system it works fine.
Error log is pasted below.
I have tried all the available solutions here Why would I be getting a NoSuchMethodError at super.onCreate() for registerFragmentLifecycleCallbacks in Android?
java.lang.NoSuchMethodError: No virtual method registerFragmentLifecycleCallbacks(Landroid/support/v4/app/FragmentManager$FragmentLifecycleCallbacks;Z)V in class Landroid/support/v4/app/FragmentManager; or its super classes (declaration of 'android.support.v4.app.FragmentManager' appears in /data/app/android.form.avss.prepaidcard-2/base.apk:classes11.dex)
at android.arch.lifecycle.LifecycleDispatcher$DispatcherActivityCallback.onActivityCreated(LifecycleDispatcher.java:75)
at android.app.Application.dispatchActivityCreated(Application.java:219)
at android.app.Activity.onCreate(Activity.java:1039)
at android.support.v4.app.BaseFragmentActivityDonut.onCreate(BaseFragmentActivityDonut.java:39)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:297)
at android.support.v7.app.AppCompatActivity.o nCreate(AppCompatActivity.java:85)
at android.form.avss.prepaidcard.ihmf_form_fill.ui.Activities.FormBaseActivity.onCreate(FormBaseActivity.java:30)
at android.form.avss.prepaidcard.ihmf_form_fill.ui.Activities.FormFillActivity.onCreate(FormFillActivity.java:147)
Below is the app gradle config. and dependencies i am using.
Client restricted the sdk versions to 23, so i can't update it. I have tried updating compiled version but no luck.
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
applicationId "android.form.prepaidcard"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dependencies {
def lifecycle_version = "1.1.1"
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support.constraint:constraint-layout:1.1.3'
compile('com.weiwangcn.betterspinner:library-material:1.1.0') {
exclude group: 'com.android.support', module: 'appcompat-v7'
}
compile 'com.theartofdev.edmodo:android-image-cropper:2.2.5'
compile 'com.journeyapps:zxing-android-embedded:3.4.0'
//network library
compile 'com.squareup.okhttp3:logging-interceptor:3.9.1'
compile 'com.squareup.retrofit2:retrofit:2.5.0'
compile 'com.squareup.retrofit2:converter-gson:2.5.0'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.google.code.gson:gson:2.8.5'
//IHMF dependencies
compile "android.arch.lifecycle:extensions:$lifecycle_version"
compile "android.arch.lifecycle:runtime:$lifecycle_version"
compile 'io.reactivex.rxjava2:rxjava:2.0.0'
compile 'io.reactivex.rxjava2:rxandroid:2.0.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
// compile 'com.github.gcacace:signature-pad:1.2.1'
// compile 'com.journeyapps:zxing-android-embedded:3.6.0'
// compile 'com.squareup.picasso:picasso:2.5.2'
}
Currently i am clueless as apk installed using windows runs smooth.
i can't decide if its code or build level issue. I always have to push the code to Github in order to debug code in window. Which consumes a lot of times.
Any help would be highly appreciated. Thanks
This response isn't a definite answer, but it's too long to put in a comment.
I have the feeling this is a multi-dex issue with a dependency that is shared amongst modules. It seems to be complaining about support v4 libraries.
In the command window you could run ./gradlew :app:dependencies | grep v4 and see which version don't equal 23.4.0 and then exclude that module from those dependencies.
Or you can take a heavy handed approach and resolve it at the top level and try to force the version:
allprojects {
...
configurations {
all {
resolutionStrategy {
force 'com.android.support:support-v4:23.4.0'
}
}
}
}

Getting MultiDex error while adding dependency for gcm and onesignal push notification

Problem: When I add the below dependencies in build.gradle, I am getting a multiDex error. I know this happens if I have unnecessary dependency but I am not able to sort it out. I am doing this for one single push notification in my app.
I added following dependencies to my build.gradle file:
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.google.android.gms:play-services-ads:8.1.0'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-gcm:8.1.0'
compile 'com.onesignal:OneSignal:2.+#aar'
compile 'com.google.android.gms:play-services-analytics:8.1.0'
compile 'com.google.android.gms:play-services-location:8.1.0'
Before this my app was working fine. All of tthe dependecies in my gradle file are listed below (including the above dependencies)
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/android-support-v4.jar')
compile files('libs/Parse-1.3.0.jar')
compile files('libs/signpost-commonshttp4-1.2.1.2.jar')
compile files('libs/signpost-core-1.2.1.2.jar')
compile files('libs/signpost-jetty6-1.2.1.2.jar')
testCompile 'junit:junit:4.12'
compile files('libs/volley.jar')
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.google.android.gms:play-services-ads:8.1.0'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-gcm:8.1.0'
compile 'com.onesignal:OneSignal:2.+#aar'
compile 'com.google.android.gms:play-services-analytics:8.1.0'
compile 'com.google.android.gms:play-services-location:8.1.0'
}
Any help on how to fix this?
If your intention is just to add Gcm. you dont need those many dependencies. Especially google play services full version.
compile 'com.google.android.gms:play-services:8.1.0'
Its always good to add smaller dependencies which fits your usecase such as
compile 'com.google.android.gms:play-services-gcm:8.1.0'
If you still are still exceeding 65k limit and need multidex, you must enable in your module gradle file.
multiDexEnabled true
in your module grandle file in defaultConfig.
Along with this, its better enable proguard to keep following attributes as well to make sure you dont bloat up the apk size
minifyEnabled true
shrinkResources true
Note that enabling proguard has its own problems which you will have deal with by carefully reviewing proguard-rules.pro
if you can't solve your application's dependencies.
multi dex application supporting can be solution for that.
http://android-developers.blogspot.kr/2014/12/google-play-services-and-dex-method.html
http://developer.android.com/tools/building/multidex.html

duplicate entry: com/google/android/gms/common/SupportErrorDialogFragment.class

I am creating project in android studio with multi dex support . I am getting error : java.util.zip.ZipException: duplicate entry: com/google/android/gms/common/SupportErrorDialogFragment.class . I know this issue is for duplicate class. But unable to figure out that which class is getting duplicate and how to fix it. Below are the code of my build.gradle. Please suggest. Thanks.
android {
compileSdkVersion 19
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.rtpl.create.app.v2"
minSdkVersion 14
targetSdkVersion 19
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':pageIndicator')
compile project(':materialDesign')
compile project(':zxingLib')
compile project(':datetimepickerlibrary')
compile project(':facebookSDK')
compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/Android_SDK.jar')
compile files('libs/Android_SDK_component.jar')
compile files('libs/crashlytics.jar')
compile files('libs/google-play-services.jar')
compile files('libs/im.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/linkedin-j-android.jar')
compile files('libs/PayPal_MECL.jar')
compile files('libs/prime-0.6.1.jar')
compile files('libs/signpost-commonshttp4-1.2.1.1.jar')
compile files('libs/signpost-core-1.2.1.1.jar')
compile files('libs/signpost-jetty6-1.2.1.1.jar')
compile files('libs/socialauth-4.2.jar')
compile files('libs/socialauth-android-2.6.jar')
compile files('libs/twitter4j-core-3.0.5.jar')
compile files('libs/universal-image-loader-1.9.1-SNAPSHOT-with-sources.jar')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile files('libs/gcm.jar')
compile 'com.android.support:multidex:1.0.0'
}
You have conflicting dependencies in your build.gradle, meaning multiple dependencies containing the same classes:
compile 'com.google.android.gms:play-services:+'
compile files('libs/google-play-services.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/gcm.jar')
All of these components are provided by Google Play Services (the first one in the list). So you should only declare Google Play Services once, preferably only the components you're using instead of the full package: See "Selectively compiling APIs into your executable" https://developers.google.com/android/guides/setup
Chances are you won't even need multidex after you simplify your project dependencies.
Also (unrelated), I'm wondering what are these dependencies, if it's the Android framework itself you can remove them:
compile files('libs/Android_SDK.jar')
compile files('libs/Android_SDK_component.jar')

Is it mandatory to compile my app with api 22 lollipop?

My project compiles and runs fine with api 21 and when i try to compile it with api 22 i'm facing many errors from gradle (Error:In <declare-styleable> SherlockSpinner, unable to find attribute android:popupPromptView, and many other errors) and i can't fix them.
So the question is what happens if i let api 22 go and just compile it with api 21, and which devices can't run my app?
UPDATE:
Please take a look at my config and tell me which devices can't run my app
this is a part of my build.gradle config file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
lintOptions {
abortOnError false
checkReleaseBuilds false
}
}
dependencies {
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.code.gson:gson:2.3'
compile 'com.google.android.gms:play-services-base:6.5.+'
compile project(':chipsLibrary')
compile project(':slidingMenu')
compile project(':listviewanims')
compile project(':switchCompatLibrary')
compile project(':lib_numberpicker')
compile project(':styleddialogslib')
compile project(':doomDatePickerlibrary')
compile project(':swipelistview')
compile project(':actionbarsherlockPullToRefresh')
compile project(':showcaseLib_Untouched_library')
compile project(':cropper')
compile project(':library_androidanims')
compile project(':library_async_45')
compile files('libs/google-api-services-drive-v2-rev123-1.18.0-rc.jar')
compile files('libs/google-oauth-client-1.18.0-rc.jar')
compile files('libs/acra-4.5.0.jar')
// Required for Dropbox
compile files('libs/dropbox-android-sdk-1.6.1.jar')
compile files('libs/json_simple-1.1.jar')
compile files('libs/systembartint-1.0.3.jar')
compile files('libs/universal-image-loader-1.9.2 (1).jar')
compile files('libs/volley.jar')
compile files('libs/google-api-client-1.18.0-rc.jar')
compile files('libs/google-api-client-android-1.18.0-rc.jar')
compile files('libs/google-http-client-1.18.0-rc.jar')
compile files('libs/google-http-client-android-1.18.0-rc.jar')
compile files('libs/google-http-client-gson-1.18.0-rc.jar')
compile files('libs/joda-time-2.3.jar')
compile files('libs/itext-4.2.1.jar')
}
Compiling your application by defining particular compile SDK version is only required if you would want to use the features provided by that particular SDK version.
You can definitely compile with lower version and make it compatible for the higher version, but as said above you won't be able to use the new functionalities/features defined by higher version.

Can't add both Google Play Services and Appcompat-v7 dependencies

I am trying to clean up and update the libraries on a project. As part of this I moved from using the classic library folder dependency to one through gradle, for Google Play Services. I started getting an dexDebug error when compiling debug (see Android Studio - UNEXPECTED TOP-LEVEL EXCEPTION: ). From what I understand this error shows up if you have a double dependency somehow.
Below is the dependencies part of my gradle file. If I comment out appcompat-v7 completely, everything works fine. Does play-services already depend on appcompatv7 and automatically bringing it in or what's going on?
dependencies {
compile 'com.google.android.gms:play-services:7.0.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.maps.android:android-maps-utils:0.3'
//compile files('libs/commons-codec-1.8-sources.jar')
compile files('libs/engine.io-client-0.2.3.jar')
compile files('libs/ffmpeg.jar')
compile files('libs/Java-WebSocket-1.3.0.jar')
compile files('libs/socket.io-client-0.1.3.jar')
//compile files('libs/javacpp.jar')
compile files('libs/javacv.jar')
compile files('libs/json-simple-1.1.1.jar')
compile files('libs/opencv.jar')
//compile files('libs/twitter4j-async-4.0.2.jar')
compile files('libs/twitter4j-core-4.0.2.jar')
//compile files('libs/twitter4j-media-support-4.0.2.jar')
//compile files('libs/twitter4j-stream-4.0.2.jar')
}
It turns out there was an exact duplicate to this question:
After update of AS to 1.0, getting "method ID not in [0, 0xffff]: 65536" error in project
I fixed it by adding (this alone will fix the original problem):
defaultConfig {
...
multiDexEnabled true
}
and by cutting down on the massive Google Play Services, and using only subsets of it (this alone will also fix the original problem):
dependencies {
//compile 'com.google.android.gms:play-services:7.0.0'
compile 'com.google.android.gms:play-services-maps:7.0.0'
compile 'com.google.android.gms:play-services-location:7.0.0'
compile 'com.google.android.gms:play-services-gcm:7.0.0'
compile 'com.google.android.gms:play-services-plus:7.0.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.maps.android:android-maps-utils:0.3+'
compile files('libs/engine.io-client-0.2.3.jar')
compile files('libs/ffmpeg.jar')
compile files('libs/Java-WebSocket-1.3.0.jar')
compile files('libs/socket.io-client-0.1.3.jar')
compile files('libs/javacv.jar')
compile files('libs/json-simple-1.1.1.jar')
compile files('libs/opencv.jar')
compile files('libs/twitter4j-core-4.0.2.jar')
}

Categories

Resources