无法构建apk:方法引用的数量不能超过64K [英] Unable to build apk: The number of method references cannot exceed 64K

查看:172
本文介绍了无法构建apk:方法引用的数量不能超过64K的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为我的应用程序构建apk文件,但是,我收到了错误:方法引用的数量不能超过64K。



这里是错误:

错误:.dex文件中方法引用的数量不能超过64K。
了解如何在 https://developer.android.com/上解决此问题
$ b

错误:任务':app:transformClassesWithDexForDebug'的执行失败。


com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:com.android.ide.common .process.ProcessException:org.gradle.process.internal.ExecException:进程'命令'C:\程序文件\Java\jdk1.7.0_15\bin\java.exe''以非零退出结束值2


这是我的gradle文件,

  apply plugin:'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion23.0.3

defaultConfig {
applicationIdnikhilraghavendra.hopper
minSdkVersio n 21
targetSdkVersion 23
versionCode 1
versionName1.0
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
packagingOptions {
排除'META-INF / LICENSE'
排除'META-INF / LICENSE-FIREBASE.txt'
排除'META-INF / NOTICE'
}
}

dependencies {
compile fileTree(dir:'libs',include:['* .jar'])
testCompile'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile'c​​om.android.support:design:23.2.1'
compile'c​​om.google.android.gms:play-services -identity:8.4.0'
compile'c​​om.firebase:firebase-client-android:2.3.1'
compile'c​​om.android.support:cardview-v7:23.2.1'
编译'com.google.andr oid.gms:play-services:8.4.0'
}

我想要构建apk文件和部署它没有任何问题,我该怎么做?



更新



我也试过以下内容:

  apply plugin:'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion23.0.3

dexOptions {
maxProcessCount = 4 //这是默认值
}

dataBinding {
enabled = true
}

defaultConfig {
applicationIdnikhilraghavendra.hopper
minSdkVersion 21
targetSdkVersion 23
resConfigsen,fr
versionCode 1
versionName1.0
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rul es.pro'
}
debug {
minifyEnabled true
useProguard false
}
}
packagingOptions {
exclude'META -INF / LICENSE'
排除'META-INF / LICENSE-FIREBASE.txt'
排除'META-INF / NOTICE'
}
}

依赖关系{
编译fileTree(dir:'libs',include:['* .jar'])
testCompile'junit:junit:4.12'
compile'c​​om.android.support: appcompat-v7:23.2.1'
compile'c​​om.android.support:design:23.2.1'
compile'c​​om.google.android.gms:play-services-identity:8.4.0'
编译'com.firebase:firebase-client-android:2.3.1'
compile'c​​om.android.support:cardview-v7:23.2.1'
compile'c​​om.google。 android.gms:play-services:8.4.0'
}

这是生产消息:
$ b

错误:任务执行失败':app:transformClassesWithNewClassShrinkerForDebug'。



如何处理这个问题并建立一个合适的apk ?请帮助。

解决方案

  android {
compileSdkVersion 26
buildToolsVersion 26.0.0

defaultConfig {
applicationIdcom.try.app
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName 1.0
multiDexEnabled true
}

here multiDexEnabled true 应该为您做游戏



更新:支持最新的Android版本

1.如果您的 minSdkVersion 设置为 21 或更高,那么您需要在模块级构建中将multiDexEnabled设置为true。 gradle文件,如上所示。

2.但是,如果您的 minSdkVersion 设置为 20 或更低,那么您必须使用multidex支持库以及上述更改,如下所示:

 依赖关系{
compile' com.android.support:multidex:1.0.1'
}

除上述除了支持库之外,您还需要修改您的Application类,如本链接< a>。
$ b 最佳实践

1.使用proguard删除任何未使用的代码。

2.避免在项目中添加不必要的依赖项。

3.如果需要有限数量的方法或任何开源库的类,那么建议您只克隆项目中的那些项目,因为它不仅可以让您完全控制它们,但也允许proguard对它们执行操作,并且您的代码中没有任何未使用的方法。

来源: Android开发人员 - 使用64K Method配置应用程序


I have been trying to build the apk file for my app, however, I am getting the error: The number of method references cannot exceed 64K.

Here are the errors,

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

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_15\bin\java.exe'' finished with non-zero exit value 2

This is my gradle file,

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "nikhilraghavendra.hopper"
    minSdkVersion 21
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        shrinkResources true
        minifyEnabled true
        useProguard true
        proguardFiles getDefaultProguardFile('proguard-android.txt'),
                'proguard-rules.pro'
    }
}
packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE-FIREBASE.txt'
    exclude 'META-INF/NOTICE'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.google.android.gms:play-services:8.4.0'
}

I want to build the apk file and deploy it without any issues, how do I do it?

Update

I also tried the following

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

dexOptions {
    maxProcessCount = 4 // this is the default value
}

dataBinding{
    enabled = true
}

defaultConfig {
    applicationId "nikhilraghavendra.hopper"
    minSdkVersion 21
    targetSdkVersion 23
    resConfigs "en", "fr"
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        shrinkResources true
        minifyEnabled true
        useProguard true
        proguardFiles getDefaultProguardFile('proguard-android.txt'),
                'proguard-rules.pro'
    }
    debug {
        minifyEnabled true
        useProguard false
    }
}
packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE-FIREBASE.txt'
    exclude 'META-INF/NOTICE'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.google.android.gms:play-services:8.4.0'
}

This is producing the message:

Error:Execution failed for task ':app:transformClassesWithNewClassShrinkerForDebug'.

Warnings found during shrinking, please use -dontwarn or -ignorewarnings to suppress them.

How do I deal with this and build a proper apk? Please Help.

解决方案

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"

    defaultConfig {
        applicationId "com.try.app"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

here multiDexEnabled true should do the game for you

UPDATE : To support latest Android version
1. If your minSdkVersion is set to 21 or higher, all you need to do is set multiDexEnabled to true in your module-level build.gradle file, as shown above.
2. However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library along with above changes as follows:

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

Apart from the above addition of support library, you need to make changes to your Application class as mentioned in this Link.

BEST PRACTICE:
1. Remove any unused code with proguard.
2. Avoid adding unnecessary dependencies in your project.
3. If limited number methods or classes of any open source library are needed, then its advisable to clone only those in your project as it not only gives you total control on them but also allows proguard to act on them and you don't have any unused methods in your code.

Source : Android Developers - Configure Apps with 64K Method count

这篇关于无法构建apk:方法引用的数量不能超过64K的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆