我正在尝试为我的项目创建一个 发行版 。生成release-apk之后,在我安装并启动它时,会出现以下错误
06-20 17:45:47.629 800 861 I WindowManager: B2026652 WAR. Hide the surface com.google.android.tvlauncher/com.google.android.tvlauncher.MainActivity
06-20 17:45:47.637 14162 14162 D AndroidRuntime: Shutting down VM
06-20 17:45:47.639 14162 14162 E AndroidRuntime: FATAL EXCEPTION: main
06-20 17:45:47.639 14162 14162 E AndroidRuntime: Process: com.tv.app, PID: 14162
06-20 17:45:47.639 14162 14162 E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate application com.tv.app.exoui.DemoApplication: java.lang.ClassCastException: com.tv.app.exoui.DemoApplication cannot be cast to android.app.Application
06-20 17:45:47.639 14162 14162 E AndroidRuntime: at android.app.LoadedApk.makeApplication(LoadedApk.java:971)
06-20 17:45:47.639 14162 14162 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5816)
06-20 17:45:47.639 14162 14162 E AndroidRuntime: at android.app.ActivityThread.-wrap1(Unknown Source:0)
06-20 17:45:47.639 14162 14162 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1662)
06-20 17:45:47.639 14162 14162 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:105)
06-20 17:45:47.639 14162 14162 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
06-20 17:45:47.639 14162 14162 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6592)
06-20 17:45:47.639 14162 14162 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
06-20 17:45:47.639 14162 14162 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
06-20 17:45:47.639 14162 14162 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
06-20 17:45:47.639 14162 14162 E AndroidRuntime: Caused by: java.lang.ClassCastException: com.tv.app.exoui.DemoApplication cannot be cast to android.app.Application
06-20 17:45:47.639 14162 14162 E AndroidRuntime: at android.app.Instrumentation.newApplication(Instrumentation.java:1101)
06-20 17:45:47.639 14162 14162 E AndroidRuntime: at android.app.Instrumentation.newApplication(Instrumentation.java:1086)
06-20 17:45:47.639 14162 14162 E AndroidRuntime: at android.app.LoadedApk.makeApplication(LoadedApk.java:965)
06-20 17:45:47.639 14162 14162 E AndroidRuntime: ... 9 more
06-20 17:45:47.644 800 861 I WindowManager: B2026652 WAR. Hide the surface com.google.android.tvlauncher/com.google.android.tvlauncher.MainActivity
但是当我在 调试版本 中运行相同的代码时,我没有收到此错误
在构建发行版时,proguard会显示一些警告,因为该应用程序在调试版本中运行良好,所以我在proguard-rules.pro中给出了〜ignorewarnings ,这可能是个问题吗?
代码:
public class DemoApplication extends Application {
...
}
AndroidManifest.xml
<application
android:allowBackup="false"
android:largeHeap="true"
android:name=".exoui.DemoApplication"
android:testOnly="false">