Section 2 of android native implementation
All checks were successful
Deploy to production / deploy (push) Successful in 21s

This commit is contained in:
Torsten Schulz (local)
2026-07-09 08:04:11 +02:00
parent 53becb6630
commit 75b52de282
18 changed files with 402 additions and 18 deletions

34
android/native/README.md Normal file
View File

@@ -0,0 +1,34 @@
# YourPart Native Android
Native Android-App fuer YourPart als paralleler Aufbau zur bestehenden Capacitor-App.
## Entscheidungen
- Pfad: `/android/native`
- Sprache: Kotlin
- UI: Jetpack Compose
- App-ID Debug/Local: `de.yourpart.nativeapp.local.debug`
- App-ID Production Release: `de.yourpart.nativeapp`
- minSdk: 26
- compileSdk/targetSdk: 36
- Flavors: `local`, `staging`, `production`
- Build Types: `debug`, `release`
## Kommandos
```bash
cd android/native
../android/gradlew -p . :app:assembleLocalDebug
../android/gradlew -p . :app:installLocalDebug
./scripts/assemble-local-debug.sh
```
## Emulator-Backend
Der Android-Emulator erreicht den Host-Rechner ueber `10.0.2.2`.
Der `local` Flavor nutzt:
- API: `http://10.0.2.2:2020`
- Socket.IO: `http://10.0.2.2:2020`
- Daemon: `ws://10.0.2.2:2021`

View File

@@ -0,0 +1,122 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.compose")
id("com.google.dagger.hilt.android")
kotlin("kapt")
}
val gitShaProvider = providers.exec {
workingDir = rootDir.resolve("../..")
commandLine("git", "rev-parse", "--short=12", "HEAD")
}.standardOutput.asText.map { it.trim().ifBlank { "dev" } }
val gitSha: String = runCatching { gitShaProvider.get() }.getOrDefault("dev")
android {
namespace = "de.yourpart.nativeapp"
compileSdk = 36
defaultConfig {
applicationId = "de.yourpart.nativeapp"
minSdk = 26
targetSdk = 36
versionCode = 1
versionName = "0.1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("String", "GIT_SHA", "\"$gitSha\"")
}
flavorDimensions += "environment"
productFlavors {
create("local") {
dimension = "environment"
applicationIdSuffix = ".local"
versionNameSuffix = "-local"
buildConfigField("String", "API_BASE_URL", "\"http://10.0.2.2:2020\"")
buildConfigField("String", "SOCKET_IO_URL", "\"http://10.0.2.2:2020\"")
buildConfigField("String", "DAEMON_SOCKET_URL", "\"ws://10.0.2.2:2021\"")
}
create("staging") {
dimension = "environment"
applicationIdSuffix = ".staging"
versionNameSuffix = "-staging"
buildConfigField("String", "API_BASE_URL", "\"https://staging.your-part.de\"")
buildConfigField("String", "SOCKET_IO_URL", "\"https://staging.your-part.de\"")
buildConfigField("String", "DAEMON_SOCKET_URL", "\"wss://staging.your-part.de\"")
}
create("production") {
dimension = "environment"
buildConfigField("String", "API_BASE_URL", "\"https://www.your-part.de\"")
buildConfigField("String", "SOCKET_IO_URL", "\"https://www.your-part.de\"")
buildConfigField("String", "DAEMON_SOCKET_URL", "\"wss://www.your-part.de\"")
}
}
buildTypes {
debug {
applicationIdSuffix = ".debug"
versionNameSuffix = "-debug"
}
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
}
}
buildFeatures {
buildConfig = true
compose = true
}
lint {
abortOnError = true
checkReleaseBuilds = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
}
dependencies {
implementation("androidx.core:core-ktx:1.17.0")
implementation("androidx.activity:activity-compose:1.13.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.10.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.10.0")
implementation("androidx.navigation:navigation-compose:2.9.6")
implementation("androidx.compose.material3:material3:1.4.0")
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-tooling-preview")
debugImplementation("androidx.compose.ui:ui-tooling")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0")
implementation("com.squareup.retrofit2:retrofit:3.0.0")
implementation("com.squareup.okhttp3:okhttp:5.3.2")
implementation("com.squareup.okhttp3:logging-interceptor:5.3.2")
implementation("com.google.dagger:hilt-android:2.57.2")
kapt("com.google.dagger:hilt-android-compiler:2.57.2")
implementation("androidx.room:room-runtime:2.6.1")
implementation("androidx.room:room-ktx:2.6.1")
kapt("androidx.room:room-compiler:2.6.1")
implementation("androidx.datastore:datastore-preferences:1.1.7")
implementation("io.coil-kt:coil-compose:2.6.0")
implementation("androidx.work:work-runtime-ktx:2.8.1")
implementation("com.google.firebase:firebase-messaging:24.1.2")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.3.0")
androidTestImplementation("androidx.test.espresso:espresso-core:3.7.0")
}

1
android/native/app/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1 @@
# Keep release rules intentionally empty until native modules require them.

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".YourPartNativeApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher_foreground"
android:label="@string/app_name"
android:roundIcon="@drawable/ic_launcher_foreground"
android:supportsRtl="true"
android:theme="@style/Theme.YourPartNative">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,22 @@
package de.yourpart.nativeapp
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import de.yourpart.nativeapp.ui.YourPartNativeApp
import de.yourpart.nativeapp.ui.theme.YourPartTheme
import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
YourPartTheme {
YourPartNativeApp()
}
}
}
}

View File

@@ -0,0 +1,7 @@
package de.yourpart.nativeapp
import android.app.Application
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class YourPartNativeApplication : Application()

View File

@@ -0,0 +1,68 @@
package de.yourpart.nativeapp.ui
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import de.yourpart.nativeapp.BuildConfig
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun YourPartNativeApp() {
Scaffold(
topBar = {
TopAppBar(
title = { Text("YourPart") },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.surface,
titleContentColor = MaterialTheme.colorScheme.onSurface,
),
)
},
) { innerPadding ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(innerPadding)
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
Text(
text = "Native Android MVP",
style = MaterialTheme.typography.headlineSmall,
)
Text(
text = "Projektbasis fuer Kotlin, Compose, Flavors, Hilt und Netzwerk ist angelegt.",
style = MaterialTheme.typography.bodyLarge,
)
Card(
modifier = Modifier.fillMaxWidth(),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.secondaryContainer,
),
) {
Column(
modifier = Modifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
Text("Environment", style = MaterialTheme.typography.titleMedium)
Text("API: ${BuildConfig.API_BASE_URL}")
Text("Socket.IO: ${BuildConfig.SOCKET_IO_URL}")
Text("Daemon: ${BuildConfig.DAEMON_SOCKET_URL}")
}
}
}
}
}

View File

@@ -0,0 +1,27 @@
package de.yourpart.nativeapp.ui.theme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
private val YourPartLightScheme = lightColorScheme(
primary = Color(0xFFF8A22B),
onPrimary = Color(0xFF2B1F14),
secondary = Color(0xFF78C38A),
onSecondary = Color(0xFF173822),
secondaryContainer = Color(0xFFE5F3E8),
onSecondaryContainer = Color(0xFF1F5131),
surface = Color(0xFFFFF8EE),
onSurface = Color(0xFF2B1F14),
background = Color(0xFFFFFCF7),
onBackground = Color(0xFF2B1F14),
)
@Composable
fun YourPartTheme(content: @Composable () -> Unit) {
MaterialTheme(
colorScheme = YourPartLightScheme,
content = content,
)
}

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#F8A22B"
android:pathData="M20,20h68a8,8 0,0 1,8 8v52a8,8 0,0 1,-8 8H20a8,8 0,0 1,-8 -8V28a8,8 0,0 1,8 -8z" />
<path
android:fillColor="#78C38A"
android:pathData="M31,35h18a13,13 0,0 1,0 26H39v16H31zM39,43v10h10a5,5 0,0 0,0 -10z" />
<path
android:fillColor="#FFFFFF"
android:pathData="M58,35h8v17h16v8H66v17h-8V60H42v-8h16z" />
</vector>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#FFF8EE</color>
</resources>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">YourPart Native</string>
</resources>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.YourPartNative" parent="android:style/Theme.Material.Light.NoActionBar">
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:fontFamily">sans</item>
</style>
</resources>

View File

@@ -0,0 +1,6 @@
plugins {
id("com.android.application") version "8.13.0" apply false
id("org.jetbrains.kotlin.android") version "2.2.20" apply false
id("org.jetbrains.kotlin.plugin.compose") version "2.2.20" apply false
id("com.google.dagger.hilt.android") version "2.57.2" apply false
}

View File

@@ -0,0 +1,4 @@
org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8
android.useAndroidX=true
android.nonTransitiveRClass=true
kotlin.code.style=official

View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
"$PROJECT_DIR/../android/gradlew" -p "$PROJECT_DIR" :app:assembleLocalDebug

View File

@@ -0,0 +1,18 @@
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "YourPartNative"
include(":app")