Declare a variable in Gradle usable in Java using buildConfigField and resValue

Generate Java Constants

android {
    buildTypes {
        debug {
            buildConfigField "int", "FOO", "42"
            buildConfigField "String", "FOO_STRING", "\"foo\""
            buildConfigField "boolean", "LOG", "true"
        }

        release {
            buildConfigField "int", "FOO", "52"
            buildConfigField "String", "FOO_STRING", "\"bar\""
            buildConfigField "boolean", "LOG", "false"
        }
    }
}

You can access them with BuildConfig.FOO

Generate Android resources

android {
    buildTypes {
        debug{
            resValue "string", "app_name", "My App Name Debug"
        }
        release {
            resValue "string", "app_name", "My App Name"
        }
    }
}

You can access them in the usual way with @string/app_name or R.string.app_name

String type build config fields should be declared like this:

buildConfigField "String", "SERVER_URL", "\"http://dev.myserver.com\""

References
https://stackoverflow.com/questions/17197636/is-it-possible-to-declare-a-variable-in-gradle-usable-in-java
https://stackoverflow.com/questions/30796533/how-to-generate-buildconfigfield-with-string-type

Customize Glide Network Timeouts on Android

build.gradle

implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation "com.github.bumptech.glide:okhttp3-integration:4.9.0"
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

create a new GlideModule

@GlideModule
public class CustomTimeOutOkHttpGlideModule extends LibraryGlideModule {

    @Override
    public void registerComponents(Context context, Glide glide, Registry registry) {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();

        // customize connection timeouts here
        // ...

        OkHttpClient okHttpClient = builder.build();

        registry.replace(GlideUrl.class, InputStream.class,
                new OkHttpUrlLoader.Factory(okHttpClient));
    }

}

References
https://futurestud.io/tutorials/glide-4-customize-network-timeouts
https://futurestud.io/tutorials/glide-module-example-accepting-self-signed-https-certificates
https://bumptech.github.io/glide/int/okhttp3.html

Use AndroidX in a project

Use AndroidX in a new project
gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

Migrate an existing project using Android Studio

select Refactor > Migrate to AndroidX from the menu bar

References
https://developer.android.com/topic/libraries/support-library/androidx-overview?utm_source=android-studio&utm_medium=studio-assistant#migration
https://developer.android.com/topic/libraries/support-library/refactor#migrate

Asset font is not loaded in android webView

@font-face { font-family: 'Persian'; src: url('fonts/b_yekan.ttf'); }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<style type="text/css">
    @font-face { font-family: 'B Homa'; src: url('fonts/BHOMA.TTF');}
    @font-face { font-family: 'B Lotus'; src: url('fonts/BLOTUS.TTF');}
    @font-face { font-family: 'B Lotus Bold'; src: url('fonts/BLOTUSBD.TTF');}
</style>
</head>
<body>
    <p style="font-family:'B Homa';font-size:20px;">B Homa: مخصص</p>
    <p style="font-family:'B Lotus';font-size:20px;">B Lotus: مخصص</p>
    <p style="font-family:'B Lotus Bold';font-size:20px;">B Lotus Bold: مخصص</p>
</body>
</html>

References

https://stackoverflow.com/questions/25077094/asset-font-is-not-loaded-in-android-webview