当前位置: 首页 > news >正文

解决找不到字体的问题

PlayerView在创建的时候回生成一个PlayerControlView,PlayerControlView构造方法中会用到字体。这个字体在某些机型上找不到。导致应用崩溃。

报错信息大概是这样的

 Binary XML file line #14: Error inflating class androidx.media3.ui.PlayerView

androidx.media3.ui.PlayerControlView.<init>(MyApplication:83)

androidx.media3.ui.PlayerView.<init>(MyApplication:92)

androidx.media3.ui.PlayerView.<init>(MyApplication:2)

解决方案:

把代码下载到本地,然后以库的module的方式依赖

具体操作就是先打开https://github.com/androidx/media/releases/tag/1.3.1

然后下载zip

然后到项目中找到/libraries/ui

在android studio 中File->new ->import module 选择libraries/ui

然后命名一下module的名字

然后找到PlayerControlView 在 构造方法中关于 Typeface 使用字体的逻辑都删掉

然后修改一下build.gradle

// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
plugins {id 'com.android.library'  // 库模块
}
android {namespace 'androidx.media3.ui'compileSdkVersion 34defaultConfig {minSdkVersion 21targetSdkVersion 33}buildTypes {release {minifyEnabled false}}
}dependencies {implementation 'androidx.media3:media3-common:1.3.1'compileOnly 'androidx.recyclerview:recyclerview:1.3.0'compileOnly 'androidx.media:media:1.7.0'implementation 'androidx.annotation:annotation:1.3.0'compileOnly 'org.checkerframework:checker-qual:3.13.0'compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:1.8.20'}ext {releaseArtifactId = 'media3-ui'releaseName = 'Media3 UI module'
}

 

最后在主工程build.gradle引用一下 

implementation project(":media3_ui")

然后setting.gradle 申明一下

include(':media3_ui')

相关文章:

  • windows搭建xwiki17服务器
  • [Java · 铢积寸累] 数据结构 — 数组类型 - Arrays 工具类详解
  • 稳定PCDN运营效率
  • 【leetcode100】零钱兑换Ⅱ
  • 物联网赋能玻璃制造业:实现设备智能管理与生产协同
  • Ubuntu 上安装 Conda
  • 安装 Conda 环境
  • csv数据的写入
  • SharpMap与TerraLib:C#与C++开源GIS库
  • 蓝桥杯算法实战分享:C/C++ 题型解析与实战技巧
  • 【“星睿O6”AI PC开发套件评测】GPU矩阵指令算力,GPU带宽和NPU算力测试
  • npm i 出现permission denied
  • AtCoder 第402场初级竞赛 A~E题解
  • JavaScript 渲染内容爬取实践:Puppeteer 进阶技巧
  • Socket
  • 【STL】unordered_map
  • 【速写】多LoRA并行衍生的一些思考
  • Nginx:前后端分离配置(静态资源+反向代理)
  • navicat导入sql文件 所有问题解决方法集合
  • ios开发中xxx.debug.dylib not found
  • 上海消保委调查二次元消费:手办与卡牌受欢迎,悦己和社交是动力
  • 翁东华卸任文和友小龙虾公司董事,此前抢镜“甲亢哥”惹争议
  • 大理杨徐邱上诉案开庭:当事人称曾接受过两次测谎测试
  • 关税飓风下的跨境电商人:已度过焦虑期,和中国做生意是美国最优解
  • 执政将满百日,特朗普政府面临国内“三重暴击”
  • 美团回应京东“二选一”指控:没有任何理由对某平台进行任何限制