应用程序在发布时崩溃,但在调试模式下工作正常

问题描述 投票:0回答:2

我已在 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 控制台中显示相同的错误。

这是我的 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(模块:app)

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)


android android-asynctask google-play
2个回答
2
投票
minifyEnable=true

构建发布 apk 时,你的 DAO 找不到东西。尝试检查你的 proguard。


UPD 是的,你有混淆的问题。

'java.lang.String com.biocare.database.n.b'

这个

'n.b'
意味着你在混淆之前有正确的路径,但是在混淆之后路径被更改为值'n'和'b'。您应该在混淆器排除列表中添加此文件(我不知道某些文件,因为我不知道您的代码)。

您可以在 proguard 文档中阅读更多内容。

这个

也很有用


0
投票

© www.soinside.com 2019 - 2024. All rights reserved.