.dex 文件中的方法引用数不能超过 64K,multidexenabled 不起作用,任务':app:clean'失败



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

这是我的构建...

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'
}

但随后一个新的错误来了...

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

这是我的主活动中的logIn()方法...

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

此外,即时运行在安卓工作室中不起作用......显示错误:

任务":应用:清理"的执行失败。无法删除文件

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

问题是您的onClick方法不public。我认为该错误不再与多德克斯有关。将签名更改为:

public void logIn(View view)...

尝试添加

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

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

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

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

然后,您可以删除所有多dex废话:)

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

将其添加到 build.gradle

 dexOptions {
        javaMaxHeapSize "1g"
    }

和。。。

multiDexEnabled true

并将单击方法更改为公共...

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

我不知道实际上哪些真正有效,我想一起!

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

最新更新