0
0
Android Kotlinmobile~20 mins

Signing configuration in Android Kotlin - Mini App: Build & Ship

Choose your learning style9 modes available
Build: App Signing Setup
This screen helps you configure signing settings for your Android app to prepare it for release.
Target UI
---------------------------------
|       App Signing Setup        |
|-------------------------------|
| Keystore Path: [_____________] |
| Keystore Password: [_________] |
| Key Alias: [_______________]   |
| Key Password: [_____________]  |
|                               |
| [Save Configuration]           |
---------------------------------
Add input fields for keystore path, keystore password, key alias, and key password.
Add a Save Configuration button that validates inputs and shows a confirmation message.
Use secure input for password fields.
Layout should be scrollable if needed and accessible.
Starter Code
Android Kotlin
package com.example.signingconfig

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp

class SigningConfigActivity : ComponentActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
      SigningConfigScreen()
    }
  }
}

@Composable
fun SigningConfigScreen() {
  // TODO: Add input fields and Save button here
}
Task 1
Task 2
Task 3
Task 4
Solution
Android Kotlin
package com.example.signingconfig

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp

class SigningConfigActivity : ComponentActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
      SigningConfigScreen()
    }
  }
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SigningConfigScreen() {
  var keystorePath by remember { mutableStateOf("") }
  var keystorePassword by remember { mutableStateOf("") }
  var keyAlias by remember { mutableStateOf("") }
  var keyPassword by remember { mutableStateOf("") }
  var savedMessage by remember { mutableStateOf("") }

  Column(
    modifier = Modifier
      .fillMaxSize()
      .padding(16.dp),
    verticalArrangement = Arrangement.spacedBy(12.dp)
  ) {
    Text(text = "App Signing Setup", style = MaterialTheme.typography.headlineMedium)

    OutlinedTextField(
      value = keystorePath,
      onValueChange = { keystorePath = it },
      label = { Text("Keystore Path") },
      singleLine = true,
      modifier = Modifier.fillMaxWidth()
    )

    OutlinedTextField(
      value = keystorePassword,
      onValueChange = { keystorePassword = it },
      label = { Text("Keystore Password") },
      singleLine = true,
      visualTransformation = PasswordVisualTransformation(),
      keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
      modifier = Modifier.fillMaxWidth()
    )

    OutlinedTextField(
      value = keyAlias,
      onValueChange = { keyAlias = it },
      label = { Text("Key Alias") },
      singleLine = true,
      modifier = Modifier.fillMaxWidth()
    )

    OutlinedTextField(
      value = keyPassword,
      onValueChange = { keyPassword = it },
      label = { Text("Key Password") },
      singleLine = true,
      visualTransformation = PasswordVisualTransformation(),
      keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
      modifier = Modifier.fillMaxWidth()
    )

    Button(
      onClick = {
        if (keystorePath.isBlank() || keystorePassword.isBlank() || keyAlias.isBlank() || keyPassword.isBlank()) {
          savedMessage = "Please fill in all fields."
        } else {
          savedMessage = "Signing configuration saved successfully!"
        }
      },
      modifier = Modifier.fillMaxWidth()
    ) {
      Text("Save Configuration")
    }

    if (savedMessage.isNotEmpty()) {
      Text(text = savedMessage, color = MaterialTheme.colorScheme.primary)
    }
  }
}

This solution uses Jetpack Compose to build a simple form for signing configuration.

We use OutlinedTextField for each input. Password fields use PasswordVisualTransformation to hide input characters.

The Save button checks if any field is empty and shows a message accordingly.

The layout uses a vertical Column with spacing and padding for a clean look.

Final Result
Completed Screen
---------------------------------
|       App Signing Setup        |
|-------------------------------|
| Keystore Path: [my/path/keystore.jks] |
| Keystore Password: [••••••••] |
| Key Alias: [mykey]             |
| Key Password: [••••••••]       |
|                               |
| [Save Configuration]           |
|                               |
| Signing configuration saved   |
| successfully!                 |
---------------------------------
User types keystore path and passwords into fields.
Passwords show dots instead of characters.
Tapping Save Configuration validates inputs.
If any field is empty, shows 'Please fill in all fields.' message.
If all fields filled, shows 'Signing configuration saved successfully!' message.
Stretch Goal
Add a file picker button next to the Keystore Path field to select the keystore file from device storage.
💡 Hint
Use Android's Storage Access Framework with an Intent to pick a file and update the keystore path state.