[Android] Fix unresolved reference release on release builds

Nicolas Pomepuy git at videolan.org
Thu Dec 15 12:37:23 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Dec 15 11:49:00 2022 +0100| [483c0a3d4e6b0f47e6859e476ee3d3029dbf66e4] | committer: Nicolas Pomepuy

Fix unresolved reference release on release builds

> https://code.videolan.org/videolan/vlc-android/commit/483c0a3d4e6b0f47e6859e476ee3d3029dbf66e4
---

 .../src/org/videolan/vlc/MediaParsingService.kt    |  5 +---
 .../vlc-android/src/org/videolan/vlc/util/Util.kt  | 32 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 0e50cef840..50db4734de 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -298,10 +298,7 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
     private fun startScan(shouldInit: Boolean, upgrade: Boolean) {
         scanActivated = true
         if (MLServiceLocator.getLocatorMode() == MLServiceLocator.LocatorMode.TESTS) {
-            val jsonData = AppContextProvider.appResources.openRawResource(R.raw.basic_stub).bufferedReader().use {
-                it.readText()
-            }
-            (medialibrary as StubMedialibrary).loadJsonData(jsonData)
+            (medialibrary as StubMedialibrary).loadJsonData(Util.readAsset("basic_stub.json", ""))
         }
         when {
             shouldInit -> {
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Util.kt b/application/vlc-android/src/org/videolan/vlc/util/Util.kt
index 8537c42248..8a67ff4603 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Util.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Util.kt
@@ -23,14 +23,46 @@ package org.videolan.vlc.util
 import android.app.Activity
 import android.app.Service
 import android.content.Context
+import org.videolan.resources.AppContextProvider
 import org.videolan.resources.VLCInstance
+import org.videolan.tools.CloseableUtils
 import org.videolan.tools.runBackground
 import org.videolan.tools.runOnMainThread
 import org.videolan.vlc.gui.video.VideoPlayerActivity
+import java.io.BufferedReader
+import java.io.IOException
+import java.io.InputStream
+import java.io.InputStreamReader
 
 object Util {
     const val TAG = "VLC/Util"
 
+    fun readAsset(assetName: String, defaultS: String): String {
+        var inputStream: InputStream? = null
+        var r: BufferedReader? = null
+        try {
+            inputStream = AppContextProvider.appResources.assets.open(assetName)
+            r = BufferedReader(InputStreamReader(inputStream, "UTF8"))
+            val sb = StringBuilder()
+            var line: String? = r.readLine()
+            if (line != null) {
+                sb.append(line)
+                line = r.readLine()
+                while (line != null) {
+                    sb.append('\n')
+                    sb.append(line)
+                    line = r.readLine()
+                }
+            }
+            return sb.toString()
+        } catch (e: IOException) {
+            return defaultS
+        } finally {
+            CloseableUtils.close(inputStream)
+            CloseableUtils.close(r)
+        }
+    }
+
     fun checkCpuCompatibility(ctx: Context) {
         runBackground(Runnable {
             if (!VLCInstance.testCompatibleCPU(ctx))



More information about the Android mailing list