Skip to content

Instantly share code, notes, and snippets.

dependencies {
testImplementation 'com.github.IvanShafran:shared-preferences-mock:1.0'
}
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
@IvanShafran
IvanShafran / shared-preferences-mock-sample.java
Last active June 29, 2019 20:19
Shared preferences mock sample
public class CounterPreferences {
// ...
private final SharedPreferences sharedPreferences;
public CounterPreferences(@NonNull final Context context) {
sharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
}
public int getCounter() {
return sharedPreferences.getInt(KEY, 0);
}
...
apply from: 'signing.gradle'
...
android {
...
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
def propertiesFilename = "production.properties"
if (!project.file(propertiesFilename).exists()) {
propertiesFilename = "contributors.properties"
}
def signingProperties = new Properties()
signingProperties.load(new FileInputStream(file(propertiesFilename)))
android {
signingConfigs {
# Sign key alias for contributors.jks
releaseSignKeyAlias=key
# Sign key password for contributors.jks
releaseSignKeyPassword=password
# Path to contributors.jks
releaseStoreFilePath=./contributors.jks
# Keystore password for contributors.jks
releaseStorePassword=password
class Sample {
companion object {
init {
DependencyChecker.check()
}
}
}
public class DependencyChecker {
public static void check() throws ClassNotFoundException {
try {
// Intrinsics exists in all std-lib versions
Class.forName("kotlin.jvm.internal.Intrinsics");
} catch (ClassNotFoundException e) {
throw new ClassNotFoundException("Library depends on Kotlin std-lib.\n" +
"Add to dependencies: org.jetbrains.kotlin:kotlin-stdlib:1.3.31"
);
}
class Sample {
companion object {
@JvmField
val INSTANCE = Sample()
}
}
@IvanShafran
IvanShafran / kotlin-compiler-apiVersion-and-languageVersion.gradle
Last active May 10, 2019 18:06
Kotlin compiler flags: apiVersion and languageVersion
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
apiVersion = "1.2"
languageVersion = "1.2"
}
}