[英]Getting MultiDex error while adding dependency for gcm and onesignal push notification
問題:當我在build.gradle中添加以下依賴項時,出現了multiDex錯誤。 我知道如果我有不必要的依賴關系會發生這種情況,但是我無法解決它。 我正在為我的應用程序中的一個推送通知執行此操作。
我在build.gradle文件中添加了以下依賴項:
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'
在此之前,我的應用程序運行良好。 下面列出了我的gradle文件中的所有依賴項(包括上述依賴項)
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'
}
任何有關如何解決此問題的幫助?
如果您的意圖只是添加Gcm。 您不需要那么多的依賴關系。 尤其是Google Play服務完整版。
compile 'com.google.android.gms:play-services:8.1.0'
添加較小的依賴項(通常適合您的用例)通常是一件好事,例如
compile 'com.google.android.gms:play-services-gcm:8.1.0'
如果仍然超過65k,並且需要multidex,則必須在模塊gradle文件中啟用。
multiDexEnabled true
在您的模塊Grandle文件中的defaultConfig中。
除此之外,它還使Proguard能夠更好地保持以下屬性,以確保您不會誇大apk大小
minifyEnabled true
shrinkResources true
請注意,啟用proguard會有其自身的問題,您將通過仔細查看proguard-rules.pro來解決這些問題。
如果您無法解決應用程序的依賴性。 多dex應用程序支持可以解決此問題。
http://android-developers.blogspot.kr/2014/12/google-play-services-and-dex-method.html http://developer.android.com/tools/building/multidex.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.