Gradle 构建成功,但当我尝试运行我的应用程序时,出现此错误:
Error:Your app has more methods references than can fit in a single dex file. See https://developer.android.com/tools/building/multidex.html
我在我的应用中实现了“使用 Google 帐户登录”功能后得到了这个。
为什么我会收到这个?为了解决这个问题,我不明白这个问题。你们有解决方案吗?
编辑
我按照步骤操作,但是它显示另一个错误:
Copying resources from program jar [/Users/Earthling/AndroidStudioProjects/GoogleTestProject/app/build/intermediates/transforms/jarMerging/debug/jars/1/1f/combined.jar] :app:transformClassesWithDexForDebug FAILED Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin/java'' finished with non-zero exit value 3
最佳答案
你必须使用 multidex
因为你的项目超出了一个应用程序中授权的方法的限制(大约 ~56000 或差不多,我不记得了)。请参阅文档中的这句话(您顺便提供的链接):
As the Android platform has continued to grow, so has the size of Android apps. When your application and the libraries it references reach a certain size, you encounter build errors that indicate your app has reached a limit of the Android app build architecture.
为了构建和运行,您有 to configure your build.gradle
如下:
android {
defaultConfig {
...
// enabling multidex
multiDexEnabled true
}
}
// add the dependencie
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
然后,创建您自己的 Application
类,如下所示:
public class MyApplication extends MultiDexApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this); // install multidex
}
}
最后,在Manifest
中添加这个类:
<application
...
android:name=".MyApplication">
或者您可以默认使用 android.multidex.application
而不是像这样创建:
<application
...
android:name="android.support.multidex.MultiDexApplication">
关于java - 安卓错误 : Your app has more methods references than can fit in a single dex file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34749193/