更新了Android Studio之後就出現了以下的問題。。。

Unable to build apk: The number of method references cannot exceed 64K

相同的sources。。。出現了問題就build 不到apk, 整個人orz 了。。。。

找了好幾個論壇,終於找到了原因,更改了Google Services 的lib 換成了只用 Google Services -GCM, 就好了。。。

=========================

以下是最詳細的解釋:

大約就是用得太多methods所以就不能了。。。

Unable to build apk: The number of method references cannot exceed 64K occur when app .dex file have more than 65,536 methods.

Exceed 65K Method that means method count more than 65,536 methods There are different ways to fix it:

1. Reduce dependencies in your project put dependencies in gradle which are required

Most problems that I found from another developers is use Google Play Services in them project like this.

 compile 'com.google.android.gms:play‐services:8.4.0'

So the best way is choosing only some dependencies in Google Play Services that you really want to use it.

compile 'com.google.android.gms:play‐services‐location:8.4.0'
compile 'com.google.android.gms:play‐services‐maps:8.4.0'
compile 'com.google.android.gms:play‐services‐ads:8.4.0'

2. Set minimum SDK version to 21 or higher

Why it worked when change minimum SDK to 21? That's because of Android 5.0 or higher are use ART (Android Runtime) that supported MultiDex instead of Dalvik. So ART can support more than 65,536 methods.

3. Use Proguard to reduce useless method

4. Use MultiDex

But these are the Limitation of MultiDex library

• May occurs ANR while app launching if .dex files too large.

• Should be define minimum SDK to version 14 or higher.

• MulitDex uses more memory and may crash while app running if allocation memory is over limit.

• Take more build time when you build the project

文章標籤
創作者介紹

呆子獅的夢想世界

lionlionchopper 發表在 痞客邦 PIXNET 留言(0) 人氣()