I want to resolve some dependencies in my application only if I debug my app, for example I want to use Stetho
only for debug, not in final release, how can I achieve that?
I tried creating another folder called debug and creating DebugApp
that extends from my App but I don't know how to run this DebugApp
, maybe I should add something in Gradle?
public class DebugApp extends App {
@Override
protected void init() {
super.init();
DebugAppInitializer.initStetho(this);
DebugAppInitializer.initCrashczyk(this);
}
}
It would be awesome if I can link it to my productFlavors
To start debugging an APK, click Profile or debug APK from the Android Studio Welcome screen. Or, if you already have a project open, click File > Profile or Debug APK from the menu bar. In the next dialog window, select the APK you want to import into Android Studio and click OK.
Set the project as the main project and choose Debug > Debug Main Project (Ctrl+F5) from the main menu or right-click the project in the Projects window and choose Debug.
Android allows the attribute android:debuggable to be set to true in the manifest, so that the app can be debugged. By default this attribute is disabled, i.e., it is set to false , but it may be set to true to help with debugging during development of the app.
You can put your code like this:
if(BuildConfig.DEBUG){
... //debug init
} else {
....//release init
}
OR
1) Create project structure like this:
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) Need to create differents classes and put application name for each manifest files:
manifest in driver package ->
<application
android:name=".application.YourFirstAppInDriverPackage"
...
>
manifest in passenger package->
<application
android:name=".application.YourSecondAppInPassengerPackage"
...
>
4) Switch development mode between two projects:
I believe you're looking for this: https://www.littlerobots.nl/blog/stetho-for-android-debug-builds-only/
TL;DR: In order to activate your DebugApp you'd need to override the manifest in your 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With