package com.example.proguardr8
import android.os.Bundle
import android.widget.Button
import android.widget.Switch
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
class ProGuardR8OptimizationScreen : AppCompatActivity() {
private lateinit var minifySwitch: Switch
private lateinit var checkStatusButton: Button
private var isMinifyEnabled = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_proguard_r8_optimization)
minifySwitch = findViewById(R.id.switch_minify)
checkStatusButton = findViewById(R.id.button_check_status)
minifySwitch.setOnCheckedChangeListener { _, isChecked ->
isMinifyEnabled = isChecked
Toast.makeText(this, if (isChecked) "Minify Enabled" else "Minify Disabled", Toast.LENGTH_SHORT).show()
}
checkStatusButton.setOnClickListener {
val status = if (isMinifyEnabled) "Minification is ON" else "Minification is OFF"
Toast.makeText(this, status, Toast.LENGTH_SHORT).show()
}
}
}
/*
In your module-level build.gradle file, add or update the following inside the android block:
android {
buildTypes {
release {
minifyEnabled true // or false to disable
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
This enables R8/ProGuard minification and optimization for release builds.
*/This screen uses a Switch to simulate enabling or disabling code minification, which is controlled in the build.gradle file for real projects. The Button shows the current minify status using a Toast message.
The key part of enabling ProGuard and R8 optimization is in the build.gradle file where minifyEnabled true turns on code shrinking and obfuscation. The app UI here helps beginners understand the concept interactively.