Skip to content

Instantly share code, notes, and snippets.

@wongk
wongk / Example.kt
Created June 15, 2020 17:33
Blog - Wire mock with HTTPS - example trust manager
with (URL(url).openConnection() as HttpsURLConnection) {
val trustManager = object : X509TrustManager {
override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?) = Unit
override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) {
// TODO validate the chain, and throw an exception if invalid.
}
override fun getAcceptedIssuers() = emptyArray<X509Certificate>()
}
@wongk
wongk / build.gradle
Created June 15, 2020 17:13
Blog - Wire mock with HTTPS - test dependencies
androidTestImplementation 'androidx.test:core:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.multidex:multidex:2.0.1'
// https://handstandsam.com/2016/01/30/running-wiremock-on-android/
androidTestImplementation('com.github.tomakehurst:wiremock:2.26.3') {
// Allows us to use the Android version of Apache httpclient instead
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
@wongk
wongk / AndroidManifest.xml
Created June 15, 2020 17:11
Blog - Wire mock with HTTPS - test manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.acme.example">
<uses-permission android:name="android.permission.INTERNET"/>
<application android:name="androidx.multidex.MultiDexApplication">
<uses-library android:name="org.apache.http.legacy" android:required="false" />
</application>
@wongk
wongk / SomeTest.kt
Last active June 15, 2020 17:10
Blog - Wire mock with HTTPS - init block
class SomeTest {
private val context = getApplicationContext<Context>()
@Rule @JvmField val wireMockRule: WireMockRule
init {
// Copy the keystore from assets into the cache dir so wiremock can access it.
// The key pair entry uses the password "password". Wiremock does not support a
// password on the keystore itself. The cert specifies a SAN of 127.0.0.1.
@wongk
wongk / build.gradle.kts
Last active February 18, 2020 21:33
Blog - KMP publishing - umbrella targets
kotlin {
ios {
compilations["main"].defaultSourceSet {
dependsOn(sourceSets["iosMain"])
}
val targetName = name.toLowerCase()
binaries.framework {
// Currently exported dependencies have to be target-specific, so add in the target
@wongk
wongk / build.gradle.kts
Created February 18, 2020 21:05
Blog - KMP publishing - artifactory config
artifactory {
setContextUrl("https://host.example.com/artifactory/")
publish(delegateClosureOf<PublisherConfig> {
repository(delegateClosureOf<DoubleDelegateWrapper> {
setProperty("repoKey", "example-repo")
setProperty("username", "aUsername")
setProperty("password", "aPassword")
setProperty("maven", true)
})
defaults(delegateClosureOf<groovy.lang.GroovyObject> {
@wongk
wongk / build.gradle.kts
Created February 18, 2020 21:00
Blog - KMP publishing - configure Dokka
tasks.named<DokkaTask>("dokka") {
multiplatform {
create("android") {
targets = listOf("Android")
platform = "jvm"
skipEmptyPackages = true
}
create("ios") {
targets = listOf("iOS")
platform = "native"
@wongk
wongk / build.gradle.kts
Last active February 18, 2020 20:58
Blog - KMP publishing - target configuration
kotlin {
android {
publishAllLibraryVariants()
}
iosX64("ios") {
mavenPublication {
artifactId = "${project.name}-iosx64"
}
}
iosArm64 {
@wongk
wongk / settings.gradle
Created December 3, 2019 19:30
Local flag to control building a module
Properties moduleProperties = new Properties()
File modulePropertiesFile = file(rootDir.absolutePath + '/modules.properties')
def buildMyModule = false
if (modulePropertiesFile.exists()) {
moduleProperties.load(sdkPropertiesFile.newDataInputStream())
buildMyModule = moduleProperties.getProperty('build.myModule', 'false').toBoolean()
}
@wongk
wongk / build.gradle.kts
Created November 19, 2019 16:07
Blog - Umbrella Project - build.gradle.kts
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask
buildscript {
project.extra["iosFrameworkName"] = "iOSAppUmbrella"
repositories {
google()