You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter编译release.apk时better_player组件无法正常工作

BetterPlayer Debug正常播放但Release版本失效问题排查

问题描述

使用better_player 0.0.83库时,Debug版本APK可正常播放视频,但编译Release版本后播放器无法工作。已按官方文档配置Multidex,相关配置如下:

build.gradle 配置

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.br.sistematutor.tutor"
    minSdkVersion 21
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    multiDexEnabled = true
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation "androidx.multidex:multidex:2.0.1"
    // compile "commons-io:commons-io:+"
}

AndroidManifest.xml 配置

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.br.sistematutor.tutor">
    
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
   <application
        android:label="@string/app_name"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

排查方向

1. 代码混淆规则缺失

Release版本默认开启代码混淆,BetterPlayer及其依赖的ExoPlayer类可能被混淆导致功能失效。需在proguard-rules.pro中添加以下规则:

-keep class com.jhomlala.better_player.** { *; }
-keep class com.google.android.exoplayer2.** { *; }

2. 资源压缩导致依赖资源丢失

若开启了资源压缩(shrinkResources true),可能误删BetterPlayer所需的资源文件。可先尝试关闭资源压缩排查:

android {
    buildTypes {
        release {
            shrinkResources false
        }
    }
}

确认问题后,再添加精准的资源保留规则,避免不必要的资源被删除。

3. ExoPlayer版本冲突

BetterPlayer 0.0.83依赖特定版本的ExoPlayer,若项目中其他依赖引入了不同版本的ExoPlayer,可能引发兼容性问题。可强制统一ExoPlayer版本:

configurations.all {
    resolutionStrategy.force 'com.google.android.exoplayer:exoplayer-core:2.18.1'
}

注:版本号需与BetterPlayer 0.0.83适配,可查看BetterPlayer的依赖清单确认具体版本。

4. Release模式调试日志捕获

开启Release版本的调试模式,通过日志定位具体错误:

android {
    buildTypes {
        release {
            debuggable true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

使用adb logcat命令过滤播放相关日志,查看是否有明确的异常信息(如类找不到、权限缺失等)。

5. 存储权限适配(针对本地视频)

若播放本地视频,Android 10及以上版本需适配Scoped Storage。若未正确适配,Release版本可能无法读取本地文件。可考虑使用MediaStore API访问视频文件,或针对Android 10+申请MANAGE_EXTERNAL_STORAGE权限(需注意该权限的审核要求)。

内容的提问来源于stack exchange,提问作者Lucas Barreto Luz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 09:55:23