Running another App class in my application (for debugging)

I want to allow some dependencies in my application only if I am debugging my application, for example, I want to use Stetho only for debugging, and not in the final version, how can I achieve this?

I tried to create another folder called debug and create a DebugApp that extends from my application, but I don’t know how to run this DebugApp , maybe I should add something to Gradle?

 public class DebugApp extends App { @Override protected void init() { super.init(); DebugAppInitializer.initStetho(this); DebugAppInitializer.initCrashczyk(this); } } 

It would be great if I could associate it with my productFlavors

+5
source share
2 answers

You can put your code as follows:

 if(BuildConfig.DEBUG){ ... //debug init } else { ....//release init } 

OR

1) Create a project structure as follows:

enter image description here

2) Gradle flavors:

  productFlavors { driver { applicationId "android.com.driver" versionName "1.0" buildConfigField "Boolean", "DRIVER_SESSION", "true" minSdkVersion 16 targetSdkVersion 23 } passenger { applicationId "android.com.passenger" versionName "1.0" buildConfigField "Boolean", "DRIVER_SESSION", "false" minSdkVersion 16 targetSdkVersion 23 } } sourceSets { passenger { manifest.srcFile 'src/passenger/AndroidManifest.xml' } driver { manifest.srcFile 'src/driver/AndroidManifest.xml' } } 

3) You need to create differents classes and put the application name for each manifest file:

manifest in driver package β†’

  <application android:name=".application.YourFirstAppInDriverPackage" ... > 

appears in the passenger package β†’

  <application android:name=".application.YourSecondAppInPassengerPackage" ... > 

4) Switch the development mode between two projects:

enter image description here

+8
source

I believe you are looking for this: https://www.littlerobots.nl/blog/stetho-for-android-debug-builds-only/

TL DR: To activate DebugApp, you need to redefine the manifest in the debug folder as follows:

  <manifest package="com.mycompany" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <application tools:replace="android:name" android:name=".DebugApp"/> </manifest> 
-1
source

Source: https://habr.com/ru/post/1243940/


All Articles