首先推荐android官方的中文网站,网址为
https://developer.android.google.cn
然后说下我的问题,最近在构建打包APK的过程出现了打包失败的提示:
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
大概意思就是你的方法数已经超过了64K,要解决这个问题就需要访问网站 https://developer.android.com/tools/building/multidex.html
然而这个网站可能需要翻墙才能打开,于是我用本文开头提到的中文网站,然后替换为 https://developer.android.google.cn/studio/build/multidex.html
打开此网站发现其标题为:配置方法数超过 64K 的应用,专门介绍如何解决这个问题。
我引用的方法原文为:
-------------------------------------------------------------官方原文--------------------------------------------------------------------------
修改模块级 build.gradle 文件配置以加入支持库和启用 Dalvik 可执行文件分包输出,如下面这段代码中所找
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
----------------------------------------官方原文-------------------------------------------------------
文中还提出一步:在您的清单中,将 Dalvik 可执行文件分包支持库中的 MultiDexApplication 类添加到 application 元素中。
因为我已引用自定义的Application,我就没有在清单文件里添加这个类,然后我就开始打包.........
还是构建失败,错误信息为: Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
针对这个问题我在stackoverflow找到答案为:
在模块级 build.gradle添加如下代码:
dexOptions {
javaMaxHeapSize "4g"
}
然后打包成功,总结一下,我解决方案全都是在 在模块级 build.gradle里进行的;
然后贴一下build.gradle里的伪代码,如下:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.***.***"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:multidex:1.0.1'
}
然后说下我的问题,最近在构建打包APK的过程出现了打包失败的提示:
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
大概意思就是你的方法数已经超过了64K,要解决这个问题就需要访问网站 https://developer.android.com/tools/building/multidex.html
然而这个网站可能需要翻墙才能打开,于是我用本文开头提到的中文网站,然后替换为 https://developer.android.google.cn/studio/build/multidex.html
打开此网站发现其标题为:配置方法数超过 64K 的应用,专门介绍如何解决这个问题。
我引用的方法原文为:
-------------------------------------------------------------官方原文--------------------------------------------------------------------------
修改模块级 build.gradle 文件配置以加入支持库和启用 Dalvik 可执行文件分包输出,如下面这段代码中所找
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
----------------------------------------官方原文-------------------------------------------------------
文中还提出一步:在您的清单中,将 Dalvik 可执行文件分包支持库中的 MultiDexApplication 类添加到 application 元素中。
因为我已引用自定义的Application,我就没有在清单文件里添加这个类,然后我就开始打包.........
还是构建失败,错误信息为: Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
针对这个问题我在stackoverflow找到答案为:
在模块级 build.gradle添加如下代码:
dexOptions {
javaMaxHeapSize "4g"
}
然后打包成功,总结一下,我解决方案全都是在 在模块级 build.gradle里进行的;
然后贴一下build.gradle里的伪代码,如下:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.***.***"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:multidex:1.0.1'
}