2016-03-15 56 views
2

今天,我有这样的一个错误:MultiDex应用程序的Android

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 

我在写的build.gradle:

multiDexEnabled true

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

在我的清单:

android:name="android.support.multidex.MultiDexApplication" 

而且在我的主要梅索德:

public class myMethode extends AppCompatActivity{ 
@Override 
protected void attachBaseContext(Context base) { 
super.attachBaseContext(base); 
MultiDex.install(this); 
} 
} 

但我还是收到这些错误:

03-15 12:15:37.066 19676-19676/de.example E/AndroidRuntime: FATAL EXCEPTION: main 
03-15 12:15:37.066 19676-19676/de.example E/AndroidRuntime: Process: de.imatics.mediplan, PID: 19676 
03-15 12:15:37.066 19676-19676/de.example E/AndroidRuntime: java.lang.RuntimeException: Unable to resume activity {de.imatics.mediplan/de.example.MedicationScheduleActivity}: java.lang.NullPointerException 
+2

你的'MedicationScheduleActivity'有一个'NullPointerException' –

+0

显示你的'MedicationScheduleActivity' –

回答

2

build.gradle下机器人排除像

packagingOptions { 
     exclude 'META-INF/DEPENDENCIES.txt' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE.txt' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/DEPENDENCIES' 
     exclude 'META-INF/notice.txt' 
     exclude 'META-INF/license.txt' 
     exclude 'META-INF/dependencies.txt' 
     exclude 'META-INF/LGPL2.1' 
    } 

和元信息也应该是MultiDex.install(this);应该b Ë写的应用程序类与像

public class MyApp extends Application { 

    @Override 
    protected void attachBaseContext(Context base) { 
     super.attachBaseContext(base); 
     MultiDex.install(this); 
    } 
} 
0
apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.2" 

    defaultConfig { 
     applicationId "de.imatics.mediplan" 
     minSdkVersion 19 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
     multiDexEnabled true 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

    lintOptions { 
     abortOnError false 
    } 
    packagingOptions { 
     exclude 'META-INF/DEPENDENCIES.txt' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE.txt' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/DEPENDENCIES' 
     exclude 'META-INF/notice.txt' 
     exclude 'META-INF/license.txt' 
     exclude 'META-INF/dependencies.txt' 
     exclude 'META-INF/LGPL2.1' 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    wearApp project(':wear') 
    testCompile 'junit:junit:4.12' 
    compile files('libs/Android-DDP.jar') 
    compile 'com.android.support:appcompat-v7:23.1.1' 
    compile 'com.google.android.gms:play-services:8.4.0' 
    compile 'com.android.support:design:23.1.1' 
    compile 'com.android.support:multidex:1.0.1' 
} 
0

你需要你的应用程序类添加到AndroidManifest而不是MultiDexApplication类

<application 
      android:name="com.app.YourAppClass" 
      android:icon="@drawable/icon" 
      android:theme="@style/Theme" 
      android:label="@string/app_name"> 
0

我解决问题的应用程序类扩展,我impl。自动设置活动,但这些从我的build.gradle删除一些支持流星的代码..感谢上帝的github