Skip to content

Example Android app that uses the Diode Android library (diode_android_sdk)

License

Notifications You must be signed in to change notification settings

diodechain/diode_android_example

Repository files navigation

Diode Android Example App

This is an example Android application demonstrating how to integrate and use the Diode SDK in your Android projects.

Overview

This example app shows how to:

  • Add the Diode SDK as a dependency to your Android project
  • Initialize the SDK
  • Connect to Diode network peers
  • Send and receive messages through the Diode network

Prerequisites

  • Android Studio with Android SDK
  • The Diode SDK library (AAR file or Maven dependency)

Adding the SDK Dependency

There are several ways to add the Diode SDK to your Android project. Choose the method that best fits your workflow.

Option 1: Using Maven Coordinates (Recommended)

If the SDK is published to a Maven repository (Maven Central, JitPack, or your private repository), add the SDK as a Gradle dependency in your app module's build.gradle:

dependencies {
    implementation 'io.diode:sdk:1.0.0'
}

Add the following dependency to your dependencies block to integrate the library into your Android app:

dependencies {
    // Other dependencies...
    implementation 'io.diode:sdk:1.0.0'
}

Make sure your build.gradle includes the repository where the SDK is hosted:

repositories {
    google()
    mavenCentral()
    // Add your Maven repository here if using a private repo
}

Option 2: Using Local Maven Repository

If you've built the SDK locally and published it to your local Maven repository using ./gradlew publishToMavenLocal, you can use the same Maven coordinates:

repositories {
    mavenLocal() // Include local Maven repository
}

dependencies {
    implementation 'io.diode:sdk:1.0.0'
}

Option 3: Using Local AAR File

Download the AAR, place it in your project's libs directory, and configure your build script to treat it as a library dependency.

  1. Get the AAR file: Build the SDK from the diode_android_sdk project:

    cd ../diode_android_sdk
    ./gradlew :app:assembleRelease

    This creates app/build/outputs/aar/app-release.aar

  2. Copy the AAR to your example app's libs directory:

    cp ../diode_android_sdk/app/build/outputs/aar/app-release.aar app/libs/diode-sdk-release.aar
  3. Add the dependency in app/build.gradle:

    dependencies {
        implementation files('libs/diode-sdk-release.aar')
    }

    Or if you want to reference it by name:

    dependencies {
        implementation(name: 'diode-sdk-release', ext: 'aar')
    }

    If using the named approach, also add:

    repositories {
        flatDir {
            dirs 'libs'
        }
    }

Project Setup

  1. Open the project in Android Studio
  2. Sync Gradle files to download dependencies
  3. Build and run the app on a device or emulator

Usage Example

The example app demonstrates basic SDK usage:

import io.diode.sdk.Bridge

// Initialize the SDK
val bridge = Bridge(applicationContext)

// Set up callbacks
bridge.onMessageReceived = { data ->
    // Handle received messages
    val decoded = String(Base64.decode(data, Base64.DEFAULT))
    // Process decoded message
}

bridge.onConnectionStatusChanged = { connected ->
    // Handle connection status changes
    if (connected) {
        // Connected to peer
    } else {
        // Disconnected from peer
    }
}

// Connect to a Diode peer
bridge.connect("0x389eba94b330140579cdce1feb1a6e905ff876e6", 5000)

// Send a message
bridge.sendMessage("Hello, Diode!")

// Disconnect
bridge.disconnect()

Project Structure

diode_android_example/
├── app/
│   ├── libs/                    # Place AAR files here (Option 3)
│   │   └── diode-sdk-release.aar
│   ├── src/main/
│   │   ├── java/io/diode/example/
│   │   │   └── MainActivity.kt  # Example usage of the SDK
│   │   ├── res/                  # App resources
│   │   └── AndroidManifest.xml
│   └── build.gradle              # App dependencies
├── build.gradle                  # Root build file
└── settings.gradle               # Project settings

Building

  1. Ensure the SDK dependency is properly configured (see above)
  2. Open the project in Android Studio
  3. Sync Gradle files
  4. Build the APK:
    ./gradlew assembleDebug
    Or build a release APK:
    ./gradlew assembleRelease

Running

  1. Connect an Android device or start an emulator
  2. Run the app from Android Studio, or install the APK:
    ./gradlew installDebug

Troubleshooting

SDK Not Found

  • If using Maven coordinates: Ensure the repository is correctly configured and the SDK version exists
  • If using local AAR: Verify the AAR file is in the libs directory and the dependency is correctly specified in build.gradle
  • If using local Maven: Run ./gradlew publishToMavenLocal in the SDK project first

Build Errors

  • Ensure all SDK prerequisites are met (see SDK README)
  • Check that the SDK was built successfully
  • Verify Android SDK and build tools versions match requirements

Runtime Errors

  • Check logcat for detailed error messages
  • Ensure the device/emulator has internet permissions
  • Verify the Diode peer address and port are correct

Working with a SOCKS Connection

If a SOCKS server is running on the remote Diode peer, you can use it as a proxy to connect to other internet locations. This enables you to route your internet traffic through the Diode network, providing privacy and access to services through the peer's network connection.

Overview

A SOCKS (Socket Secure) proxy allows you to:

  • Route TCP connections through the Diode peer
  • Access internet services as if you were on the peer's network
  • Bypass network restrictions or access geo-blocked content
  • Maintain privacy by routing traffic through the Diode network

Getting Started

To implement SOCKS support in your app:

  1. Ensure you're connected to a Diode peer that has a SOCKS server running
  2. Follow the SOCKS Porting Guide for detailed implementation instructions
  3. Use the SOCKS client to route your app's network traffic through the Diode peer

The SOCKS Porting Guide provides:

  • Step-by-step implementation instructions
  • Complete code examples for creating a SOCKS client
  • HTTP request examples through SOCKS
  • Security considerations and best practices
  • Testing guidelines

See the SOCKS Porting Guide for complete documentation on implementing SOCKS proxy functionality in your Android app.

WebView with SOCKS Proxy

If you want to use a WebView that routes all its traffic through a remote SOCKS5 server accessible via the Diode network, see the WebView SOCKS Guide. This guide explains how to:

  • Create a local HTTP proxy server that tunnels through the Diode SDK
  • Route WebView requests through the Diode SDK's SOCKS connection
  • Access internet services through a remote Diode peer's SOCKS server (not on public internet)

Next Steps

  • Explore the SOCKS Porting Guide for advanced proxy functionality
  • Check the SDK README for detailed SDK documentation
  • Customize the example app to fit your use case

License

See the main SDK project for license information.

About

Example Android app that uses the Diode Android library (diode_android_sdk)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages