What is ProGuard?

Perhaps you noticed the file proguard-rules.pro in your app directory? Why do we need that? ProGuard ProGuard has three use cases: shrinking obfuscating optimizing Code shrinking Often called “tree shaking”, shrinking optimizes the byte code by removing unused code. Resource shrinking After code shrinking all non-referenced resources will be removed as well Obfuscation This step…

How to use Snackbars

A Snackbar is a replacement for Toasts in Android. Dependency implementation ‘com.google.android.material:material:1.4.0’ Layout A snackbar must be tied to a coordinator layout. If you use fragments the standard layout is FrameLayout which can be directly swapped with: <androidx.coordinatorlayout.widget.CoordinatorLayout Snackbar val snackbar = Snackbar.make( binding.root, “No internet connection! Please enable WiFi or Mobile Data”, Snackbar.LENGTH_INDEFINITE )…

Depdencency Graph with Gradle

Gradle has built-in capabilities to generate a dependency graph of all packages used in the application. Gradle Tools gradle app:dependencies Command line Windows .\gradlew.bat app:dependencies Linux / macOS ./gradlew app:dependencies Further Reading Anatomy of a Gradle file How to add local jar files to your gradle dependencies How to enable R8 in your build process

versionCode vs versionName in Android Apps

versionCode 1versionName “0.1” versionName is a string which is visible to the user in the settings menu under App Info versionCode is an integer. It is used to compare APK updates against each other to make sure apps aren’t downgraded. val packageInfo: PackageInfo = this.packageManager.getPackageInfo(this.packageName, 0)Log.d(packageInfo.versionName)Log.d(packageInfo.versionCode) Further Reading Anatomy of a Gradle file Depdencency Graph…

Logging in Android

Logging brings some light into the darkness of your code. If you are new to logging please have a look at Log4j2 for Kotlin Import import android.util.Log Tag class MainActivity : AppCompatActivity() { companion object { const val TAG = “MainActivity” } Log statement override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Log.d(TAG, “onCreate”) } Logcat Further…

Classes in Kotlin – Part 2

In Part 1 we dealt with the simplest form of initialization with the primary constructor: class Planet( val diameter: Int, val distanceToSun: Double, val mass: Double ) But wait: there is more: Init block The primary constructor cannot contain any code so init block for the rescue: class Planet( val diameter: Int, val distanceToSun: Double,…

Classes in Kotlin – Part 1

Why is there a car in the picture? – Because it has class! Jokes aside, classes are still the building blocks of modern object oriented software design. And of course as the new kid on the block Kotlin has it’s own take on this subject. Declaration Let’s look at the most basic class declaration: class…