Skip to content

Commit 6f726de

Browse files
kirich1409claude
andauthored
Add :sample:android-app standalone Android application module (#180)
* Add :sample:android-app standalone Android application module (#171) Creates a new :sample:android-app module (com.android.application) that depends on :sample, :featured-debug-ui, and :featured-platform. Wires DataStoreConfigValueProvider via defaultLocalProvider(context) and shows FeatureFlagsDebugScreen on demand. Also populates :sample's androidMain manifest and MainActivity so the existing KMP sample module can run as a self-contained Android activity. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Handle system back to close debug screen in MainActivity * Fix simplify issues in sample/android-app - Delete accidental MainActivity from :sample KMP library module - Revert :sample androidMain manifest to empty (library must not declare launcher Activity) - Remove androidMain deps block from :sample (belonged to deleted MainActivity) - Remove featured-debug-ui from :sample commonMain (only needed in android-app) - android-app: fix import order for BackHandler - android-app: use applicationContext instead of this for defaultLocalProvider - android-app: add shrinkResources = true alongside isMinifyEnabled - android-app: add androidx.appcompat for Theme.AppCompat.Light.NoActionBar - android-app: remove tools:replace (library manifest no longer declares theme) * Use android.targetSdk catalog key instead of compileSdk for targetSdk --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8979f24 commit 6f726de

4 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
plugins {
2+
alias(libs.plugins.androidApplication)
3+
alias(libs.plugins.composeCompiler)
4+
}
5+
6+
android {
7+
namespace = "dev.androidbroadcast.featured.sample.app"
8+
compileSdk =
9+
libs.versions.android.compileSdk
10+
.get()
11+
.toInt()
12+
13+
defaultConfig {
14+
applicationId = "dev.androidbroadcast.featured.sample"
15+
minSdk =
16+
libs.versions.android.minSdk
17+
.get()
18+
.toInt()
19+
targetSdk =
20+
libs.versions.android.targetSdk
21+
.get()
22+
.toInt()
23+
versionCode = 1
24+
versionName = "1.0.0"
25+
}
26+
27+
buildFeatures {
28+
compose = true
29+
}
30+
31+
buildTypes {
32+
release {
33+
isMinifyEnabled = true
34+
isShrinkResources = true
35+
proguardFiles(
36+
getDefaultProguardFile("proguard-android-optimize.txt"),
37+
)
38+
}
39+
}
40+
}
41+
42+
dependencies {
43+
implementation(project(":sample"))
44+
implementation(project(":featured-debug-ui"))
45+
implementation(project(":featured-platform"))
46+
implementation(libs.androidx.activity.compose)
47+
implementation(libs.androidx.appcompat)
48+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<application
4+
android:label="Featured Sample"
5+
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
6+
<activity
7+
android:name="dev.androidbroadcast.featured.sample.MainActivity"
8+
android:exported="true"
9+
android:windowSoftInputMode="adjustResize">
10+
<intent-filter>
11+
<action android:name="android.intent.action.MAIN" />
12+
<category android:name="android.intent.category.LAUNCHER" />
13+
</intent-filter>
14+
</activity>
15+
</application>
16+
</manifest>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package dev.androidbroadcast.featured.sample
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.BackHandler
6+
import androidx.activity.compose.setContent
7+
import androidx.activity.enableEdgeToEdge
8+
import androidx.compose.runtime.getValue
9+
import androidx.compose.runtime.mutableStateOf
10+
import androidx.compose.runtime.saveable.rememberSaveable
11+
import androidx.compose.runtime.setValue
12+
import dev.androidbroadcast.featured.ConfigValues
13+
import dev.androidbroadcast.featured.SampleApp
14+
import dev.androidbroadcast.featured.debugui.FeatureFlagsDebugScreen
15+
import dev.androidbroadcast.featured.platform.defaultLocalProvider
16+
17+
class MainActivity : ComponentActivity() {
18+
// ConfigValues is held at Activity scope for this sample.
19+
// In production, move to Application or a DI singleton to avoid
20+
// recreating (and re-opening) the DataStore file on every rotation.
21+
private val configValues by lazy {
22+
ConfigValues(localProvider = defaultLocalProvider(applicationContext))
23+
}
24+
25+
override fun onCreate(savedInstanceState: Bundle?) {
26+
super.onCreate(savedInstanceState)
27+
enableEdgeToEdge()
28+
setContent {
29+
var showDebug by rememberSaveable { mutableStateOf(false) }
30+
31+
if (showDebug) {
32+
BackHandler { showDebug = false }
33+
FeatureFlagsDebugScreen(configValues = configValues)
34+
} else {
35+
SampleApp(
36+
configValues = configValues,
37+
onOpenDebugUi = { showDebug = true },
38+
)
39+
}
40+
}
41+
}
42+
}

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ plugins {
3838

3939
include(":featured-gradle-plugin")
4040
include(":sample")
41+
include(":sample:android-app")
4142
include(":core")
4243
include(":featured-compose")
4344
include(":featured-registry")

0 commit comments

Comments
 (0)