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 {
            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", "\"\""


Customize Glide Network Timeouts on Android


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

public class CustomTimeOutOkHttpGlideModule extends LibraryGlideModule {

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

        // customize connection timeouts here
        // ...

        OkHttpClient okHttpClient =;

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



Use AndroidX in a project

Use AndroidX in a new project file:


Migrate an existing project using Android Studio

select Refactor > Migrate to AndroidX from the menu bar


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"
<html xmlns="">
<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');}
    <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>