Fonts in XML not working on emulator API 23

2019-08-06 04:22发布

问题:

I'm trying to use Fonts in XML, but have problems on Emulator.

On the device with the Android 23 API works correctly, but on the emulator with the same version for some reason the fonts are not downloaded and are not applied.

I used default Android Studio 3 Emulator (API 23, System image x86).

It's interesting that on the emulator with the API 27 everything works well and the fonts are applied.

My app.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "by.mastihin.testnewcustomfonts"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "com.android.support:appcompat-v7:27.0.2"
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}

Whole project code on GitHub

This is not a big problem for me, it would just be interesting to find out the reason. Thanks!

回答1:

The "auto-downloaded-fonts" system is managed by Google Play Services.

This is installed on all "real" Android devices, so it'll work there.

But most emulators do NOT have Google Play Services installed, so they won't work there. It's only recently that Google published emulators which actually have Google Play Services installed.

Check if you have them installed on your 2 emulators, and i'm guess that the API 23 one does not have them, while the newer, API 27 one, does.