应用程序在发行时崩溃,但在调试模式下可以正常运行

时间:2019-07-27 19:29:25

标签: android android-asynctask google-play

我在Play商店上载了应用。它可以在调试模式下正常运行,但是当我从Play商店下载相同的APK(发布模式)时,它崩溃了。我无法弄清楚,堆栈跟踪没有给出确切的错误位置。

  

java.lang.RuntimeException:     在android.os.AsyncTask $ 3.done(AsyncTask.java:318)     在java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)     在java.util.concurrent.FutureTask.setException(FutureTask.java:223)     在java.util.concurrent.FutureTask.run(FutureTask.java:242)     在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:243)     在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)     在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:607)     在java.lang.Thread.run(Thread.java:761)   造成原因:java.lang.NullPointerException:     在com.biocare.fots.HomeActivity $ GetEmpDetailsTask.doInBackground(HomeActivity.java)     或.onPostExecute(HomeActivity.java)     在com.biocare.fots.HomeActivity $ GetEmpDetailsTask.doInBackground(HomeActivity.java)     在android.os.AsyncTask $ 2.call(AsyncTask.java:304)     在java.util.concurrent.FutureTask.run(FutureTask.java:237)     在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:243)     在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)     在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:607)     在java.lang.Thread.run(Thread.java:761)

以上堆栈跟踪信息是从Play商店开发者控制台复制的。 Firebase控制台中显示相同的错误。

enter image description here

这是我的AsyncTask代码:

 private static class GetEmpDetailsTask extends AsyncTask<Void, Void, Void> {

    WeakReference<HomeActivity> mContext;

    GetEmpDetailsTask(HomeActivity context) {
        mContext = new WeakReference<>(context);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected Void doInBackground(Void... voids) {
        if(android.os.Debug.isDebuggerConnected())
            android.os.Debug.waitForDebugger();
        AppDatabase appDatabase = AppDatabase.getAppDatabaseInstance(
                mContext.get());
        Employee employee = appDatabase.employeeDAO().get();
        FotApplication.Employee.Id = employee.employeeId;
        FotApplication.Employee.Name = employee.firstName + " "
                + employee.lastName;
        FotApplication.Employee.Designation = employee.empDesignationName;
        FotApplication.Employee.DesignationDesc = employee.empDesignationName;
        FotApplication.Employee.Email = employee.email;
        return null;
    }


    @Override
    protected void onPostExecute(Void aVoid) {
        mContext.get().mTvEmpName.setText(FotApplication.Employee.Name);
        mContext.get().mTvEmpEmail.setText(FotApplication.Employee.Email);
    }
}

这是我的 build.gradle(模块:应用)

apply plugin: 'com.android.application'


android {
    signingConfigs {
        config {
            keyAlias 'abc'
            keyPassword 'test'
            storeFile file('path/to/keystore.jks')
            storePassword 'testpass'
        }
    }
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.myapp.fats"
        minSdkVersion 22
        targetSdkVersion 29
        versionCode 38
        versionName "2.1.9"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.gms:play-services-places:17.0.0'
    implementation 'com.jakewharton:butterknife:8.6.0'
    implementation 'com.google.firebase:firebase-messaging:19.0.1'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
    implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
    annotationProcessor 'com.jakewharton:butterknife:8.6.0'
    annotationProcessor 'androidx.room:room-compiler:2.1.0'
    implementation 'androidx.room:room-runtime:2.1.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'com.afollestad.material-dialogs:commons:0.9.6.0'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel:2.0.0'
    implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    implementation 'com.wang.avi:library:2.1.3'
    implementation 'androidx.gridlayout:gridlayout:1.0.0'
    implementation ('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') {
        transitive = true
    }
}
repositories {
    mavenCentral()
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'

编辑1:

Android Studio中的Logcat:

 Process: com.biocare.fots, PID: 15978
java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:353)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
    at java.util.concurrent.FutureTask.run(FutureTask.java:271)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at java.lang.Thread.run(Thread.java:764)
 Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String com.biocare.database.n.b' on a null object reference
    at com.biocare.fots.HomeActivity$a.a(Unknown Source:20)
    at com.biocare.fots.HomeActivity$a.doInBackground(Unknown Source:2)
    at android.os.AsyncTask$2.call(AsyncTask.java:333)

1 个答案:

答案 0 :(得分:2)

我猜想,如果您的DAO(例如Room)使用反射,则当您使用minifyEnable=true构建发行版APK时,您的DAO找不到任何东西。尝试检查您的监护人。

UPD 是的,您对混淆有疑问。 'java.lang.String com.biocare.database.n.b'这个'n.b'表示您在混淆之前具有正确的路径,但是在混淆路径更改为值'n'和'b'之后。您应该将此文件(我不知道某些文件,因为我不知道您的代码)添加到proguard排除列表中。

您可以在Proguard文档中阅读更多内容。 This也可能有用