From 1b9f5989efff651c3a99eacfacab2015cc75a5a4 Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 28 Jul 2020 10:45:48 +0200 Subject: [PATCH 1/3] Fix empty stacktrace in bug report ACRA has to be initialized after MultiDex https://github.com/ACRA/acra/issues/619 https://github.com/ACRA/acra/wiki/Troubleshooting-Guide#legacy-multidex --- app/src/debug/java/org/schabi/newpipe/DebugApp.kt | 12 ++++++------ app/src/main/java/org/schabi/newpipe/App.java | 7 +++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/debug/java/org/schabi/newpipe/DebugApp.kt b/app/src/debug/java/org/schabi/newpipe/DebugApp.kt index 5cfde80b8..9ea3bdabe 100644 --- a/app/src/debug/java/org/schabi/newpipe/DebugApp.kt +++ b/app/src/debug/java/org/schabi/newpipe/DebugApp.kt @@ -1,6 +1,5 @@ package org.schabi.newpipe -import android.content.Context import androidx.multidex.MultiDex import androidx.preference.PreferenceManager import com.facebook.stetho.Stetho @@ -11,11 +10,6 @@ import okhttp3.OkHttpClient import org.schabi.newpipe.extractor.downloader.Downloader class DebugApp : App() { - override fun attachBaseContext(base: Context) { - super.attachBaseContext(base) - MultiDex.install(this) - } - override fun onCreate() { super.onCreate() initStetho() @@ -34,6 +28,12 @@ class DebugApp : App() { return downloader } + override fun initACRA() { + // install MultiDex before initializing ACRA + MultiDex.install(this) + super.initACRA() + } + private fun initStetho() { // Create an InitializerBuilder val initializerBuilder = Stetho.newInitializerBuilder(this) diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index 33d77ea47..64c1fdb1c 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -77,7 +77,6 @@ public class App extends Application { @Override protected void attachBaseContext(final Context base) { super.attachBaseContext(base); - initACRA(); } @@ -200,7 +199,11 @@ public class App extends Application { .build(); } - private void initACRA() { + /** + * Called in {@link #attachBaseContext(Context)} after calling the {@code super} method. + * Should be overridden if MultiDex is enabled, since it has to be initialized before ACRA. + */ + protected void initACRA() { try { final CoreConfiguration acraConfig = new CoreConfigurationBuilder(this) .setReportSenderFactoryClasses(REPORT_SENDER_FACTORY_CLASSES) From 21d1f69d6d7697c1eae6b4b0d5f0a441ec857de7 Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 28 Jul 2020 10:48:54 +0200 Subject: [PATCH 2/3] Do not init ACRA if inside its own process https://github.com/ACRA/acra/wiki/Troubleshooting-Guide#applicationoncreate --- app/src/main/java/org/schabi/newpipe/App.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index 64c1fdb1c..75228cefe 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -204,6 +204,10 @@ public class App extends Application { * Should be overridden if MultiDex is enabled, since it has to be initialized before ACRA. */ protected void initACRA() { + if (ACRA.isACRASenderServiceProcess()) { + return; + } + try { final CoreConfiguration acraConfig = new CoreConfigurationBuilder(this) .setReportSenderFactoryClasses(REPORT_SENDER_FACTORY_CLASSES) From 04e7d13043fc53473f0e8218ce2c7d0fc0cd6058 Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 28 Jul 2020 11:02:01 +0200 Subject: [PATCH 3/3] Remove deprecated calls to set Sender class to ACRA setReportSenderFactoryClasses() is deprecated, now extensions (ReportSenderFactory is an extension) should be registered using AutoService: https://github.com/ACRA/acra/wiki/Custom-Extensions#by-annotation --- app/build.gradle | 4 ++++ app/src/main/java/org/schabi/newpipe/App.java | 6 ------ .../org/schabi/newpipe/report/AcraReportSenderFactory.java | 7 +++++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index afca85646..5d5affb8b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -89,6 +89,7 @@ ext { androidxRoomVersion = '2.2.5' groupieVersion = '2.8.0' markwonVersion = '4.3.1' + googleAutoServiceVersion = '1.0-rc7' } configurations { @@ -175,6 +176,9 @@ dependencies { implementation "com.google.android.material:material:1.1.0" + compileOnly "com.google.auto.service:auto-service-annotations:${googleAutoServiceVersion}" + kapt "com.google.auto.service:auto-service:${googleAutoServiceVersion}" + implementation "androidx.appcompat:appcompat:1.1.0" implementation "androidx.preference:preference:1.1.1" implementation "androidx.recyclerview:recyclerview:1.1.0" diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index 75228cefe..0071d2efe 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -20,10 +20,8 @@ import org.acra.ACRA; import org.acra.config.ACRAConfigurationException; import org.acra.config.CoreConfiguration; import org.acra.config.CoreConfigurationBuilder; -import org.acra.sender.ReportSenderFactory; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.downloader.Downloader; -import org.schabi.newpipe.report.AcraReportSenderFactory; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.settings.SettingsActivity; @@ -65,9 +63,6 @@ import io.reactivex.plugins.RxJavaPlugins; public class App extends Application { protected static final String TAG = App.class.toString(); - @SuppressWarnings("unchecked") - private static final Class[] - REPORT_SENDER_FACTORY_CLASSES = new Class[]{AcraReportSenderFactory.class}; private static App app; public static App getApp() { @@ -210,7 +205,6 @@ public class App extends Application { try { final CoreConfiguration acraConfig = new CoreConfigurationBuilder(this) - .setReportSenderFactoryClasses(REPORT_SENDER_FACTORY_CLASSES) .setBuildConfigClass(BuildConfig.class) .build(); ACRA.init(this, acraConfig); diff --git a/app/src/main/java/org/schabi/newpipe/report/AcraReportSenderFactory.java b/app/src/main/java/org/schabi/newpipe/report/AcraReportSenderFactory.java index f4c1c4ac8..2655ea672 100644 --- a/app/src/main/java/org/schabi/newpipe/report/AcraReportSenderFactory.java +++ b/app/src/main/java/org/schabi/newpipe/report/AcraReportSenderFactory.java @@ -4,9 +4,12 @@ import android.content.Context; import androidx.annotation.NonNull; +import com.google.auto.service.AutoService; + import org.acra.config.CoreConfiguration; import org.acra.sender.ReportSender; import org.acra.sender.ReportSenderFactory; +import org.schabi.newpipe.App; /* * Created by Christian Schabesberger on 13.09.16. @@ -28,6 +31,10 @@ import org.acra.sender.ReportSenderFactory; * along with NewPipe. If not, see . */ +/** + * Used by ACRA in {@link App}.initAcra() as the factory for report senders. + */ +@AutoService(ReportSenderFactory.class) public class AcraReportSenderFactory implements ReportSenderFactory { @NonNull public ReportSender create(@NonNull final Context context,