Instantly share code, notes, and snippets.

View script.sh
#!/usr/bin/env bash
# I've found that the "Migrate to AndroidX" converter in Android Studio doesn't work very
# well, so I wrote my own script to do the simple job of converting package names.
#
# You can download a CSV of package names here: https://developer.android.com/topic/libraries/support-library/downloads/androidx-class-mapping.csv
#
# It'll run faster on a clean build because then there are fewer files to scan over.
#
# Uses `gsed` because I'm on a Mac. Can easily replace with `sed` if you don't have `gsed`.
View CropView.java
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
View CropView.java
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
View dependencies block
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(Libraries.Kotlin.stdlib)
implementation(Libraries.Support.appcompatV7)
testImplementation(Libraries.Tests.junit)
androidTestImplementation(Libraries.AndroidTests.testRunner)
androidTestImplementation(Libraries.AndroidTests.espressoCore)
}
View Libraries.kt
object Libraries {
object Kotlin {
val stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlinVersion}"
}
object Support {
val appcompatV7 = "com.android.support:appcompat-v7:28.0.0-alpha3"
}
object Tests {
View Libraries.kt
object Libraries {
object Kotlin {
val stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlinVersion}"
}
object Support {
val appcompatV7 = "com.android.support:appcompat-v7:28.0.0-alpha3"
}
object Tests {
View buildtype kotlin dsl
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), file("proguard-rules.pro"))
}
}
View plugin kotlin dsl
plugins {
id("com.android.application")
kotlin("android") // or id("kotlin-android")
id("kotlin-android-extensions")
}
View clean task groovy
task clean(type: Delete) {
delete rootProject.buildDir
}