【问题标题】:The number of method references in a .dex file cannot exceed 64K, multidexenabled is not working and failed for task ':app:clean'.dex 文件中的方法引用数不能超过 64K,multidexenabled 不起作用并且任务 ':app:clean' 失败
【发布时间】:2017-01-11 09:56:30
【问题描述】:

谁能帮我解决这个问题!它昨天工作,但今天早上我再次运行我的应用程序时,它没有工作。

这是我的 build.gladle...

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    repositories {
        mavenCentral()
    }
    defaultConfig {
        applicationId "com.brandtechnosolutions.petbaazar"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}



dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.google.android.gms:play-services:9.8.0'
    compile 'com.google.android.gms:play-services-appindexing:9.8.0'
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    compile 'com.android.support:support-v4:25.1.0'
    compile `enter code here`'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    testCompile 'junit:junit:4.12'
}

我试过用这个...

defaultConfig {
    ...
    minSdkVersion 15
    targetSdkVersion 23
    ...

    // Enabling multidex support.
    multiDexEnabled true
}

还有这个……

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

但随后又出现了一个新错误...

在视图类上定义的 android:onClick 属性的父或祖先上下文中找不到方法 logIn(View)

这是我的 MainActivity 中的 logIn() 方法...

void logIn(View view) {                        //called when log in button pressed
    Intent intent = new Intent(MainActivity.this, LoginActivity.class);
    startActivity(intent);                 // start web activity
}

另外 Instant Run 无法在 android studio 中运行...显示错误:

任务“:app:clean”执行失败。无法删除文件

当我启用即时运行时。请帮忙!

【问题讨论】:

  • 你需要完整的'com.google.android.gms:play-services:9.8.0'吗?您可以只包含您需要的部分播放服务。
  • @Kevinrob 你真的没有读到最后,是吗?从最新的错误中可以看出,它与 multiDex 无关。他修复了 multiDex 问题。

标签: android android-studio build.gradle


【解决方案1】:

问题是您的 onClick 方法不是public。我认为该错误不再与 multiDex 相关。将签名更改为:

public void logIn(View view)...

【讨论】:

  • SO 的人怎么了?这肯定是问题的答案,我得到一个减号?为什么 ?那我还想干什么?
  • 昨天用的是非公开的onClick方法,今天不行了!
  • @SayanMukherjee 试试改成这个,如果解决了请告诉我。
【解决方案2】:

尝试添加

android{
...
    dexOptions {
        javaMaxHeapSize "4g"
   }
}

【讨论】:

    【解决方案3】:

    我最近遇到了同样的问题。如果应用程序包含过多的方法调用,则必须将其设为 Multidex 应用程序。不过,我认为你真的不需要这样做。

    在您的 app.gradle 中有 compile 'com.google.android.gms:play-services:9.8.0' 行,它基本上采用了整个播放服务模块,这是巨大的。我猜你的应用也需要很长时间才能构建。

    因此,删除一般播放服务依赖项(但如果需要,请保留 compile 'com.google.android.gms:play-services-appindexing:9.8.0')并添加可能需要在依赖项列表末尾添加以下行 apply plugin: 'com.google.gms.google-services'

    然后你就可以删除所有的 multidex 废话了 :)

    【讨论】:

    • 完成了您刚才提到的操作,但出现错误:错误:(40, 0) 未找到 ID 为 'com.google.gms.google-services' 的插件。
    【解决方案4】:

    问题解决了,这就是我所做的……

    将其添加到 build.gradle

     dexOptions {
            javaMaxHeapSize "1g"
        }
    

    还有……

    multiDexEnabled true
    

    并将 onClick 方法更改为 public...

    void logIn(View view) {                        //called when log in button pressed
        Intent intent = new Intent(MainActivity.this, LoginActivity.class);
        startActivity(intent);                 // start web activity
    }
    

    我实际上不知道其中哪些真正有效,我认为是一起!

    感谢你们的时间和帮助,非常感谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-15
      • 2016-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      • 1970-01-01
      相关资源
      最近更新 更多