问题:当我在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'
}
有关如何解决此问题的任何帮助?
答案 0 :(得分:1)
如果您的意图只是添加Gcm。你不需要那些依赖。特别是谷歌播放服务的完整版。
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
在defaultConfig中的模块grandle文件中。
除此之外,它更好的启用程序以保持以下属性以确保你不会膨胀的apk大小
minifyEnabled true
shrinkResources true
请注意,启用proguard有其自身的问题,您将通过仔细查看proguard-rules.pro
来处理这些问题。答案 1 :(得分:0)
如果您无法解决应用程序的依赖关系。 多dex应用程序支持可以解决这个问题。
http://android-developers.blogspot.kr/2014/12/google-play-services-and-dex-method.html http://developer.android.com/tools/building/multidex.html