Multidex 和 Singleton Class 在清单应用程序标记中使用 android:name

Multidex And Singleton Class Uses android:name In The Manifest Application Tag

我有一个应用程序,我用过Singleton。我刚刚收到 64k 错误。我通过编译依赖项并在 gradle - multiDexEnabled true

中解决了它
<application
    android:allowBackup="true"
    android:allowClearUserData="true"
    android:fullBackupContent="true"
    android:hardwareAccelerated="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:name="app.project.SingletonController"
    >

<!--android:name="android.support.multidex.MultiDexApplication"-->

然而它在同一个 link 中说 here,那应该包含在 Manifest -> <application android:name = "> 中上面评论了。

如何摆脱这个?

android:name="" 会重复,如果我放置它会产生错误。

您已经为您的应用程序定义了自定义应用程序 class SingletonController

MultiDexApplication 是一个简单的实用程序 class,您可以将其用作您自己的 SingletonController 的超级 class。如果由于某种原因这是不可能的,您必须自己实现该功能

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

Since December 3rd, 2014, build tools 1.0.0-rc1 was released. Now, all you need to do is modify your build.gradle

android {
compileSdkVersion 22
buildToolsVersion "23.0.0"

     defaultConfig {
         minSdkVersion 14 //lower than 14 doesn't support multidex
         targetSdkVersion 22

         // Enabling multidex support.
         multiDexEnabled true
     }

}

依赖项{ 编译 'com.android.support:multidex:1.0.1' }

If you are running unit tests, you will want to include this in your Application class:

public class YouApplication extends Application {

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

}