Skip to content

Commit

Permalink
Merge pull request #1558 from dhis2/master-dev
Browse files Browse the repository at this point in the history
fix: [MASTER-DEV] Docs: improve debugging section
  • Loading branch information
vgarciabnz authored May 10, 2021
2 parents 4c22d1a + e07c46d commit 2f00a1d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 68 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Main goals:

## Documentation

Developer-oriented documentation can be found in [Documentation section](https://docs.dhis2.org/master/en/dhis2_android_sdk_developer_guide/about-this-guide.html) in DHIS2 web. It is intended to be used by developers.
Developer-oriented documentation can be found in [Documentation section](https://docs.dhis2.org/en/develop/developing-with-the-android-sdk/about-this-guide.html) in DHIS2 web. It is intended to be used by developers.

## Examples

Expand All @@ -24,4 +24,4 @@ Code examples can be found in the [Android Skeleton app](https://github.com/dhis

Community support can be found in [Android SDK Development](https://community.dhis2.org/c/development/sdk-android-development) category in the community portal. Any feedback on the SDK will be highly appreciated.

To report bugs or request new features, there is project in DHIS2 Jira named [ANDROSDK](https://jira.dhis2.org/projects/ANDROSDK). Please do not hesitate to create an issue with your request.
To report bugs or request new features, there is project in DHIS2 Jira named [ANDROSDK](https://jira.dhis2.org/projects/ANDROSDK/issues). Please do not hesitate to create an issue with your request.
133 changes: 67 additions & 66 deletions docs/content/developer/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,94 +12,95 @@ Specially relevant plugins to debug the SDK:
- Database: see table content and perform custom SQL queries

Steps to install it and configure it:

1. Ensure you have the Android SDK installed (you probably will if you are planning to debug an Android app)
2. Download Flipper from [its website](https://fbflipper.com/)
3. Modify your build.gradle to install Flipper dependencies.

```gradle
dependencies {
...
debugImplementation "com.facebook.flipper:flipper:0.83.0"
debugImplementation "com.facebook.soloader:soloader:0.10.1"
debugImplementation ("com.facebook.flipper:flipper-network-plugin:0.83.0") {
exclude group: 'com.squareup.okhttp3'
}
```gradle
dependencies {
...
debugImplementation "com.facebook.flipper:flipper:0.83.0"
debugImplementation "com.facebook.soloader:soloader:0.10.1"
debugImplementation ("com.facebook.flipper:flipper-network-plugin:0.83.0") {
exclude group: 'com.squareup.okhttp3'
}
releaseImplementation "com.facebook.flipper:flipper-noop:0.83.0"
}
```
releaseImplementation "com.facebook.flipper:flipper-noop:0.83.0"
}
```
4. DHIS2 Android SDK includes a no-op version of Flipper in the release version. It should be excluded to avoid duplicated classes.
```gradle
dependencies {
...
implementation ("org.hisp.dhis:android-core:x.x.x") {
exclude group: 'com.facebook.flipper'
```gradle
dependencies {
...
implementation ("org.hisp.dhis:android-core:x.x.x") {
exclude group: 'com.facebook.flipper'
}
}
}
```
```
5. Add the diagnostic activity to the Android Manifest:
```xml
<activity android:name="com.facebook.flipper.android.diagnostics.FlipperDiagnosticActivity"
android:exported="true"/>
```
```xml
<activity android:name="com.facebook.flipper.android.diagnostics.FlipperDiagnosticActivity"
android:exported="true"/>
```
6. It is recommended to create a helper class to initialize Flipper and create the network interceptor:
```java
import android.content.Context;

import com.example.android.androidskeletonapp.BuildConfig;
import com.facebook.flipper.android.AndroidFlipperClient;
import com.facebook.flipper.android.utils.FlipperUtils;
import com.facebook.flipper.core.FlipperClient;
import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin;
import com.facebook.flipper.plugins.inspector.DescriptorMapping;
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
import com.facebook.soloader.SoLoader;

import okhttp3.Interceptor;

public class FlipperManager {

public static Interceptor setUp(Context appContext) {
if (BuildConfig.DEBUG && FlipperUtils.shouldEnableFlipper(appContext)) {
NetworkFlipperPlugin networkPlugin = new NetworkFlipperPlugin();
SoLoader.init(appContext, false);
FlipperClient client = AndroidFlipperClient.getInstance(appContext);
client.addPlugin(networkPlugin);
client.addPlugin(new DatabasesFlipperPlugin(appContext));
client.addPlugin(new InspectorFlipperPlugin(appContext, DescriptorMapping.withDefaults()));
client.start();
return new FlipperOkhttpInterceptor(networkPlugin);
} else {
return null;
```java
import android.content.Context;
import com.example.android.androidskeletonapp.BuildConfig;
import com.facebook.flipper.android.AndroidFlipperClient;
import com.facebook.flipper.android.utils.FlipperUtils;
import com.facebook.flipper.core.FlipperClient;
import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin;
import com.facebook.flipper.plugins.inspector.DescriptorMapping;
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
import com.facebook.soloader.SoLoader;
import okhttp3.Interceptor;
public class FlipperManager {
public static Interceptor setUp(Context appContext) {
if (BuildConfig.DEBUG && FlipperUtils.shouldEnableFlipper(appContext)) {
NetworkFlipperPlugin networkPlugin = new NetworkFlipperPlugin();
SoLoader.init(appContext, false);
FlipperClient client = AndroidFlipperClient.getInstance(appContext);
client.addPlugin(networkPlugin);
client.addPlugin(new DatabasesFlipperPlugin(appContext));
client.addPlugin(new InspectorFlipperPlugin(appContext, DescriptorMapping.withDefaults()));
client.start();
return new FlipperOkhttpInterceptor(networkPlugin);
} else {
return null;
}
}
}
}
```
```
7. Set up the plugins while configuring the SDK:
```java
// This will be null if not debug mode to make sure your data is safe
Interceptor flipperInterceptor = FlipperManager.setUp(context.getApplicationContext());
```java
// This will be null if not debug mode to make sure your data is safe
Interceptor flipperInterceptor = FlipperManager.setUp(context.getApplicationContext());
List<Interceptor> networkInterceptors = new ArrayList<>();
if (flipperInterceptor != null) {
networkInterceptors.add(flipperInterceptor);
}
List<Interceptor> networkInterceptors = new ArrayList<>();
if (flipperInterceptor != null) {
networkInterceptors.add(flipperInterceptor);
}
return D2Configuration.builder()
...
.networkInterceptors(networkInterceptors)
.build();
```
return D2Configuration.builder()
...
.networkInterceptors(networkInterceptors)
.build();
```
If you want to use any other Flipper plugins to debug other aspects of the app, we recommend you to go through [the documentation](https://fbflipper.com/docs/getting-started/android-native).
Expand Down

0 comments on commit 2f00a1d

Please sign in to comment.