java - 在构建文件崩溃应用程序中使用 Multidex 启用 True 并出现空指针异常

标签 java android android-multidex

我正在构建一个社交应用程序,因为我有很多依赖项,所以我在构建文件中使用了 multidex enable true ,并在 list 文件中添加了类似的内容。但它给了我空指针异常错误和应用程序崩溃。

但是当我删除 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'
提前致谢。

最佳答案

After Enabling 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();
    }
}

Replace With

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();
    }
}

关于java - 在构建文件崩溃应用程序中使用 Multidex 启用 True 并出现空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52465889/

相关文章:

java - Netbeans Spring Boot Initializr 项目 : Unable to see jsp content in web browser

java - 播放音频文件并通过 SIP 播放

Android Inbuild(ActionImageCapture) Intent 返回空 Intent 。无法传递结果 {who= null}

安卓聊天服务器

android-studio - 无法即时运行 : legacy multi-dex on Dalvik runtime

java - 从 CLI 创建应用程序时设置 AWS IAM key

java - 从Java中传递的字符串中获取最长的子字符串

java - 如何在 Android 中的两个 Intent 之间传递 arrayList

android - 我该如何解决这个错误?方法 ID 不在 [0, 0xffff] : 65536

Android 构建错误 : Program type already present: android. support.v7.app.**