Skip to content

Instantly share code, notes, and snippets.

interface UserService {
@GET("http://10.0.2.2/users")
fun getUsers(): Single<List<User>>
...
interface UserService {
@GET("/users")
fun getUsers(): Single<List<User>>
...
class BaseUrlInterceptor(baseUrl: String) : Interceptor {
private val baseUrl: HttpUrl = baseUrl.toHttpUrl()
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val url = request.url
// Skip URL reconstruction if we're hitting a local endpoint
if (url.host == "10.0.2.2") return chain.proceed(request)
class BaseUrlInterceptor(baseUrl: String) : Interceptor {
private val baseUrl: HttpUrl = baseUrl.toHttpUrl()
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val url = request.url
// Reconstruct the URL with the new base URL
return chain.proceed(
request
// Existing code
Retrofit
.Builder()
.baseUrl("https://example.com")
...
// New test code
Retrofit
.Builder()
.baseUrl("http://10.0.2.2")
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.livefront.example">
<application android:networkSecurityConfig="@xml/network_security_config">
...
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
</domain-config>
</network-security-config>
supportedResConfigs=en,notnight,port
// ...
android {
// ...
defaultConfig {
resConfigs "en"
// ...
}
// ...
}
@weisers
weisers / resconfigs-final-build.gradle
Last active December 3, 2020 14:56
Setup build.gradle to pull in any defined resource configuration settings
// ...
apply from: "$rootDir/gradle/buildTasks.gradle"
android {
// ...
defaultConfig {
if (project.supportedResConfigs != null) {
resConfigs project.supportedResConfigs
}
// ...
}