Skip to content

Commit

Permalink
Feature : Android support
Browse files Browse the repository at this point in the history
  • Loading branch information
prem-p-simform committed Jun 10, 2024
1 parent 763aadb commit cddbc07
Show file tree
Hide file tree
Showing 67 changed files with 2,206 additions and 5 deletions.
75 changes: 70 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
<img src="https://img.shields.io/github/release/yagiz/Bagel.svg" /></a>
</p>

Bagel is a little native iOS network debugger. It's not a proxy debugger so you don't have to mess around with certificates, proxy settings etc. As long as your iOS devices and your Mac are in the same network, you can view the network traffic of your apps seperated by the devices or simulators.
Bagel is a little native iOS/Android network debugger. It's not a proxy debugger so you don't have to mess around with certificates, proxy settings etc. As long as your iOS/Android devices and your Mac are in the same network, you can view the network traffic of your apps seperated by the devices or simulators.

## Preview
![Bagel](https://github.com/yagiz/Bagel/blob/develop/assets/screenshot.png?raw=true)
## Installation
#### Install Mac App
## Install Mac App
- Clone the repo.
- Install pods.
- Build and archive the project.
#### Install iOS Client

## Install iOS Client
#### CocoaPods
```shhttps://img.shields.io/badge/version-1.3.1-blue.svg?style=flat
pod 'Bagel', '~> 1.4.0'
Expand Down Expand Up @@ -71,7 +71,72 @@ bagelConfig.netserviceName = ""

Bagel.start(bagelConfig)
```
If you change Netservice parameters in your app, you should also change them on desktop client.

## Install Android client
#### Dependency
* Add the below dependency in your preferred build system
```groovy
implementation 'com.simform:bagel:1.0.0'
```
### Usage
In order to start Bagel we need to start the client and add a interceptor to intercept [OkHttp](https://square.github.io/okhttp/) API calls.
* You can start client in any one of the way you like from below
1. Start client when `Application` class starts
```kotlin
class App : Application() {
override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) { // Only expose in debug
Bagel.start(context)
}
}
}
```
2. Start client using [AppStartup](https://developer.android.com/topic/libraries/app-startup)
```kotlin
class BagelInitializer : Initializer<Unit> {
override fun create(context: Context) {
if (BuildConfig.DEBUG) { // Only expose in debug
Bagel.start(context)
}
}
override fun dependencies(): MutableList<Class<out Initializer<*>>> =
mutableListOf()
}
```
* Add [OkHttp](https://square.github.io/okhttp/) interceptor (**This is required to route API call details**)
* While building your `OkHttp` client create interceptor instance as below
```kotlin
OkHttpClient.Builder()
.apply {
if (BuildConfig.DEBUG) { // Only expose in debug
val bagelInterceptor = BagelInterceptor.getInstance()
addInterceptor(bagelInterceptor)
}
}
. // Add all other interceptor and configurations
.build()
```
### Configuring Bagel
By default, Bagel gets your project name and device information. Desktop client uses these informations to separate projects and devices. You can configure `projectName` and `netServiceType` if you wish:
```kotlin
val bagelConfiguration = BagelConfiguration
.getDefault(context)
.copy(projectName = "Bagel")
Bagel.start(
context,
bagelConfiguration
)
```

#### Note : If you change `netServiceType` parameter in your app, you should also change them on desktop client.

License
----
Expand Down
57 changes: 57 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
/.idea
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# Intellij
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/dictionaries
.idea/libraries
app/.idea/

# Mac
*.DS_Store

# Keystore files
*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Temporary API docs
docs/api

artifacts
55 changes: 55 additions & 0 deletions android/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
/.idea
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# Intellij
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/dictionaries
.idea/libraries
app/.idea/

# Mac
*.DS_Store

# Keystore files
*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Temporary API docs
docs/api
79 changes: 79 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.hilt)
alias(libs.plugins.ksp)
}

android {
namespace = "com.simformsolutions.bagelandroid"
compileSdk = libs.versions.compileSdk.get().toInt()

defaultConfig {
applicationId = "com.simformsolutions.bagelandroid"
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
}

dependencies {
// Uncomment this line to check locally published version
// implementation("com.simform:bagel:1.0.0")
// Comment this line to check locally published version
implementation(project(":bagel"))
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.timber)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.kotlinx.serialization.json)
implementation(libs.androidx.startup.runtime)
implementation(platform(libs.retrofit.bom))
implementation(libs.retrofit)
implementation(libs.hilt.android)
implementation(libs.logging.interceptor)
implementation(libs.retrofit2.kotlinx.serialization.converter)
implementation(libs.androidx.hilt.navigation.compose)
ksp(libs.hilt.android.compiler)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}
21 changes: 21 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.simformsolutions.bagelandroid

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.simformsolutions.bagelandroid", appContext.packageName)
}
}
46 changes: 46 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".BagelApp"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.BagelAndroid"
tools:targetApi="31">
<activity
android:name=".ui.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.BagelAndroid">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">

<meta-data
android:name="com.simformsolutions.bagelandroid.initializer.TimberInitializer"
android:value="androidx.startup" />

<meta-data
android:name="com.simformsolutions.bagelandroid.initializer.BagelInitializer"
android:value="androidx.startup" />
</provider>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.simformsolutions.bagelandroid

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class BagelApp : Application()
Loading

0 comments on commit cddbc07

Please sign in to comment.