写点什么

如何修复 org/jacoco/agent/rt/internal_773e439/Offline 异常?

作者:Changing Lin
  • 2021 年 11 月 24 日
  • 本文字数:5666 字

    阅读完需:约 19 分钟

1.异常现象

在实现 播放在线 TS 文件 的功能的时候,按照之前的思路是,集成 ExoPlayer 来实现播放功能。一开始是以源码的方式依赖到主工程,但考虑到项目的可维护性,决定编译 ExoPlayer 相关组件,得到对应的 aar 依赖包,拷贝到主工程中,避免对 ExoPlayer 的依赖。移植完毕后,启动播放器,发现报错了,异常如下:

-6694/com.mycompany.myproject D/AndroidRuntime: Shutting down VM05-10 18:47:55.986 6694-6694/com.mycompany.myproject E/AndroidRuntime: FATAL EXCEPTION: main                                                                        Process: com.mycompany.myproject, PID: 6694                                                                        java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_773e439/Offline;                                                                            at com.mycompany.ui.components.ListArrayAdapter.$jacocoInit(ListArrayAdapter.java)                                                                            at com.mycompany.ui.components.ListArrayAdapter.<init>(ListArrayAdapter.java)                                                                            at com.mycompany.myproject.NationalityFragment.onCreateView(NationalityFragment.java:47)                                                                            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)                                                                            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)                                                                            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)                                                                            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)                                                                            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)                                                                            at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339)                                                                            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:602)                                                                            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)                                                                            at android.app.Activity.performStart(Activity.java:5953)                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)                                                                            at android.app.ActivityThread.access$800(ActivityThread.java:144)                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)                                                                            at android.os.Looper.loop(Looper.java:135)                                                                            at android.app.ActivityThread.main(ActivityThread.java:5221)                                                                            at java.lang.reflect.Method.invoke(Native Method)                                                                            at java.lang.reflect.Method.invoke(Method.java:372)                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
复制代码


2.分析

  • 关键信息:

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_773e439/Offlineat com.mycompany.ui.components.ListArrayAdapter.$jacocoInit(ListArrayAdapter.java)
复制代码
  • 猜测与 org.jacoco.agent 包有关,并且很大可能由于 ExoPlayer 的资源包导致的;但搜索 ExoPlayer 源码,无找到对该包的引用信息

  • 经过查询资料,发现 jacocoInit 与 Gradle 的代码覆盖率有关,怀疑 ExoPlayer 工程打开了 testCoverageEnabled,导致打包生成的 aar 包嵌入了 jacoco 埋点;而主工程中是未开启的,导致出现异常。因此,解决思路是关闭 ExoPlayer 工程的 testCoverageEnabled。

3.解决方法

  • 修改 ExoPlayer 源码的 build.gradle 配置文件,全局关闭 android.buildTypes.debug.testCoverageEnabled

Index: demos/main/src/main/assets/media.exolist.jsonIDEA additional info:Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP<+>UTF-8===================================================================diff --git a/demos/main/src/main/assets/media.exolist.json b/demos/main/src/main/assets/media.exolist.json--- a/demos/main/src/main/assets/media.exolist.json	(revision 0ba317b1337eaa789f05dd6c5241246478a3d1e5)+++ b/demos/main/src/main/assets/media.exolist.json	(date 1637652481861)@@ -238,6 +238,10 @@       {         "name": "Apple media playlist (AAC)",         "uri": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_4x3/gear0/prog_index.m3u8"+      },+      {+        "name": "录像文件",+        "uri": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_4x3/gear0/prog_index.m3u8"       }     ]   },Index: library/hls/build.gradleIDEA additional info:Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP<+>UTF-8===================================================================diff --git a/library/hls/build.gradle b/library/hls/build.gradle--- a/library/hls/build.gradle	(revision 0ba317b1337eaa789f05dd6c5241246478a3d1e5)+++ b/library/hls/build.gradle	(date 1637720366971)@@ -16,7 +16,7 @@ android {     buildTypes {         debug {-            testCoverageEnabled = true+            testCoverageEnabled = gradle.ext.testCoverageEnabled         }     } Index: library/dash/build.gradleIDEA additional info:Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP<+>UTF-8===================================================================diff --git a/library/dash/build.gradle b/library/dash/build.gradle--- a/library/dash/build.gradle	(revision 0ba317b1337eaa789f05dd6c5241246478a3d1e5)+++ b/library/dash/build.gradle	(date 1637720366723)@@ -16,7 +16,7 @@ android {     buildTypes {         debug {-            testCoverageEnabled = true+            testCoverageEnabled = gradle.ext.testCoverageEnabled         }     } Index: library/transformer/build.gradleIDEA additional info:Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP<+>UTF-8===================================================================diff --git a/library/transformer/build.gradle b/library/transformer/build.gradle--- a/library/transformer/build.gradle	(revision 0ba317b1337eaa789f05dd6c5241246478a3d1e5)+++ b/library/transformer/build.gradle	(date 1637720366743)@@ -16,7 +16,7 @@ android {     buildTypes {         debug {-            testCoverageEnabled = true+            testCoverageEnabled = gradle.ext.testCoverageEnabled         }     } Index: library/extractor/build.gradleIDEA additional info:Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP<+>UTF-8===================================================================diff --git a/library/extractor/build.gradle b/library/extractor/build.gradle--- a/library/extractor/build.gradle	(revision 0ba317b1337eaa789f05dd6c5241246478a3d1e5)+++ b/library/extractor/build.gradle	(date 1637720366930)@@ -16,7 +16,7 @@ android {     buildTypes {         debug {-            testCoverageEnabled = true+            testCoverageEnabled = gradle.ext.testCoverageEnabled         }     } Index: library/core/build.gradleIDEA additional info:Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP<+>UTF-8===================================================================diff --git a/library/core/build.gradle b/library/core/build.gradle--- a/library/core/build.gradle	(revision 0ba317b1337eaa789f05dd6c5241246478a3d1e5)+++ b/library/core/build.gradle	(date 1637720366923)@@ -23,7 +23,7 @@      buildTypes {         debug {-            testCoverageEnabled = true+            testCoverageEnabled = gradle.ext.testCoverageEnabled         }     } Index: settings.gradleIDEA additional info:Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP<+>UTF-8===================================================================diff --git a/settings.gradle b/settings.gradle--- a/settings.gradle	(revision 0ba317b1337eaa789f05dd6c5241246478a3d1e5)+++ b/settings.gradle	(date 1637720366937)@@ -29,4 +29,5 @@ project(modulePrefix + 'demo-surface').projectDir = new File(rootDir, 'demos/surface') project(modulePrefix + 'playbacktests').projectDir = new File(rootDir, 'playbacktests') +gradle.ext.testCoverageEnabled = false apply from: 'core_settings.gradle'Index: library/common/build.gradleIDEA additional info:Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP<+>UTF-8===================================================================diff --git a/library/common/build.gradle b/library/common/build.gradle--- a/library/common/build.gradle	(revision 0ba317b1337eaa789f05dd6c5241246478a3d1e5)+++ b/library/common/build.gradle	(date 1637720366777)@@ -13,7 +13,7 @@ // limitations under the License. apply from: "$gradle.ext.exoplayerSettingsDir/common_library_config.gradle" -android.buildTypes.debug.testCoverageEnabled true+android.buildTypes.debug.testCoverageEnabled gradle.ext.testCoverageEnabled  dependencies {     api ('com.google.guava:guava:' + guavaVersion) {Index: library/smoothstreaming/build.gradleIDEA additional info:Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP<+>UTF-8===================================================================diff --git a/library/smoothstreaming/build.gradle b/library/smoothstreaming/build.gradle--- a/library/smoothstreaming/build.gradle	(revision 0ba317b1337eaa789f05dd6c5241246478a3d1e5)+++ b/library/smoothstreaming/build.gradle	(date 1637720366730)@@ -16,7 +16,7 @@ android {     buildTypes {         debug {-            testCoverageEnabled = true+            testCoverageEnabled = gradle.ext.testCoverageEnabled         }     } Index: library/ui/build.gradleIDEA additional info:Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP<+>UTF-8===================================================================diff --git a/library/ui/build.gradle b/library/ui/build.gradle--- a/library/ui/build.gradle	(revision 0ba317b1337eaa789f05dd6c5241246478a3d1e5)+++ b/library/ui/build.gradle	(date 1637720366736)@@ -13,7 +13,7 @@ // limitations under the License. apply from: "$gradle.ext.exoplayerSettingsDir/common_library_config.gradle" -android.buildTypes.debug.testCoverageEnabled true+android.buildTypes.debug.testCoverageEnabled gradle.ext.testCoverageEnabled  dependencies {     implementation project(modulePrefix + 'library-core')
复制代码


发布于: 3 小时前阅读数: 9
用户头像

Changing Lin

关注

获得机遇的手段远超于固有常规之上~ 2020.04.29 加入

我能做的,就是调整好自己的精神状态,以最佳的面貌去面对那些未曾经历过得事情,对生活充满热情和希望。

评论

发布
暂无评论
如何修复org/jacoco/agent/rt/internal_773e439/Offline异常?