在Null指针异常的情况下,在构建文件崩溃应用中使用启用了Multidex的True

时间:2018-09-23 12:00:25

标签: java android android-multidex

我正在构建一个社交应用程序,由于我有很多依赖性,因此我在构建文件中使用了multidex enable true,并在清单文件中添加了类似的功能。但这给了我空指针异常错误和应用程序崩溃。

但是当我删除multidex时,应用程序运行就没有任何错误..请帮助。

我的整个项目是https://github.com/BlueYeti1881/myfirstapp 这是日志猫错误 enter image description here

构建gradle文件是

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.nepalpolice.hometuitionnepal"
        minSdkVersion 16
        targetSdkVersion 27
        vectorDrawables.useSupportLibrary = true
        versionCode 2
         multiDexEnabled true
        versionName "2.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

         lintOptions {
            checkReleaseBuilds false
            abortOnError false
        }

        packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/project.properties'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/ASL2.0'
            exclude 'allclasses-frame.html'
        }

    }
    dexOptions {
        jumboMode true
    }


    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'


    // Support libraries
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:animated-vector-drawable:27.1.1'
    implementation 'com.android.support:customtabs:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'


    //maps and location





    // Firebase
     implementation 'com.google.firebase:firebase-messaging:11.4.2'
    implementation 'com.google.firebase:firebase-database:11.4.2'
    implementation 'com.google.firebase:firebase-core:11.4.2'
       implementation 'com.google.firebase:firebase-auth:11.4.2'
    implementation 'com.google.firebase:firebase-storage:11.4.2'




    // MVP
    implementation 'com.hannesdorfmann.mosby3:mvp:3.1.0' // Plain MVP

    // Social
    implementation 'com.google.android.gms:play-services-auth:11.4.2'
    implementation 'com.facebook.android:facebook-android-sdk:4.17.0'

    // Images
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'





}


apply plugin: 'com.google.gms.google-services'
预先感谢。

1 个答案:

答案 0 :(得分:1)

  

启用Multidex后

public class Application extends android.app.Application {

    public static final String TAG = Application.class.getSimpleName();

    @Override
    public void onCreate() {
        super.onCreate();

        ApplicationHelper.initDatabaseHelper(this);
        PostInteractor.getInstance(this).subscribeToNewPosts();
    }
}
  

替换为

public class Application extends MultiDexApplication {

    public static final String TAG = Application.class.getSimpleName();

    @Override
    public void onCreate() {
        super.onCreate();

        ApplicationHelper.initDatabaseHelper(this);
        PostInteractor.getInstance(this).subscribeToNewPosts();
    }
}