Skip to content

Commit

Permalink
android player & demo setup for consuming hermes
Browse files Browse the repository at this point in the history
  • Loading branch information
sugarmanz committed Jul 2, 2024
1 parent 0912bbe commit a934661
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 30 deletions.
20 changes: 14 additions & 6 deletions android/demo/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load("@rules_android//android:rules.bzl", "android_binary", "android_library")
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_import")
load("@rules_kotlin//kotlin:android.bzl", "kt_android_library")
load(":defs.bzl", "main_deps", "test_deps")
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_import")
load("@rules_player//kotlin:defs.bzl", "lint")
load(":defs.bzl", "main_deps", "test_deps")

kt_android_library(
name = "demo_lib",
Expand All @@ -15,20 +15,28 @@ kt_android_library(

android_binary(
name = "demo",
custom_package = "com.intuit.playerui.android.reference.demo",
assets = glob(["src/main/assets/mocks/**"]),
assets_dir = "src/main/assets",
custom_package = "com.intuit.playerui.android.reference.demo",
dex_shards = 3,
enable_data_binding = True,
manifest = ":src/main/AndroidManifest.xml",
multidex = "native",
deps = [
":demo_lib",
"//jvm/j2v8:j2v8-android",
"@maven//:com_eclipsesource_j2v8_j2v8",
# "//jvm/j2v8:j2v8-android",
"@maven//:androidx_databinding_databinding_common",
"@maven//:androidx_databinding_databinding_runtime",
"@maven//:org_jetbrains_kotlin_kotlin_reflect",
# "@maven//:com_eclipsesource_j2v8_j2v8",
# "@maven//:com_facebook_react_hermes_android",
# "//jvm/hermes/libs:hermes-android",
# "//jvm/hermes/libs:jsi-android",
# "@maven//:org_jetbrains_kotlin_kotlin_reflect",
# "//jvm/hermes/libs:arm64-v8a-jsi",
# "//jvm/hermes/src/main/jni:hermes_jni",
# "//jvm/hermes/libs:armeabi-v7a-jsi",
# "//jvm/hermes/libs:x86_64_jsi",
# "//jvm/hermes/libs:x86_jsi",
],
)

Expand Down
14 changes: 10 additions & 4 deletions android/demo/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ maven_main = [
"@maven//:androidx_navigation_navigation_runtime",
"@maven//:androidx_navigation_navigation_ui_ktx",
"@maven//:androidx_navigation_navigation_fragment_ktx",

"@maven//:com_afollestad_material_dialogs_core",
"@maven//:com_google_android_material_material",
#"@maven//:com_squareup_leakcanary_leakcanary_android",

# TODO: Pull these from j2v8-android-debug
"@maven//:com_github_AlexTrotsenko_j2v8_debugger",
"@maven//:com_facebook_stetho_stetho"
"@maven//:com_facebook_stetho_stetho",

# TODO: Pull these from hermes-android
# "@maven//:com_facebook_fbjni_fbjni",
# "@maven//:com_facebook_react_hermes_android",
"@maven//:com_facebook_fbjni_fbjni",
]

maven_test = [
"@maven//:androidx_test_espresso_espresso_intents",
"@maven//:androidx_test_ext_junit_ktx"
"@maven//:androidx_test_ext_junit_ktx",
]

maven = maven_main + maven_test
Expand All @@ -26,5 +32,5 @@ main_deps = maven_main + [
]

test_deps = maven_test + [
"//jvm/utils"
"//jvm/utils",
]
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class BasePlayerFragment : PlayerFragment() {
private val currentPlayerCanvas get() = binding.playerCanvas.getChildAt(0)

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
StethoHelper.initializeDebugger(requireContext(), playerViewModel.player)
// StethoHelper.initializeDebugger(requireContext(), playerViewModel.player)
return super.onCreateView(inflater, container, savedInstanceState)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.onNavDestinationSelected
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.facebook.soloader.SoLoader
import com.google.android.material.navigation.NavigationView
import com.intuit.playerui.android.reference.demo.R
import com.intuit.playerui.android.reference.demo.model.AssetMock
Expand Down Expand Up @@ -58,6 +59,8 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

SoLoader.init(this, false)

setContentView(R.layout.activity_main)

val storybookNav = findViewById<NavigationView>(R.id.storybook_nav)
Expand Down
6 changes: 4 additions & 2 deletions android/player/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
main_exports = [
"//jvm/j2v8:j2v8-android",
# TODO: These should absolutely not be exported via android player
# "//jvm/j2v8:j2v8-android",
"//jvm/hermes:hermes-android",
]

main_deps = main_exports + [
Expand All @@ -25,4 +27,4 @@ test_deps = [
"//jvm/testutils",
"@maven//:org_robolectric_robolectric",
"@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_test",
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package com.intuit.playerui.android

import android.content.Context
import android.view.View
import com.alexii.j2v8debugger.ScriptSourceProvider
//import com.alexii.j2v8debugger.ScriptSourceProvider
import com.intuit.hooks.BailResult
import com.intuit.hooks.HookContext
import com.intuit.hooks.SyncBailHook
import com.intuit.hooks.SyncHook
import com.intuit.hooks.SyncWaterfallHook
import com.intuit.playerui.android.asset.RenderableAsset
import com.intuit.playerui.android.debug.UnsupportedScriptProvider
//import com.intuit.playerui.android.debug.UnsupportedScriptProvider
import com.intuit.playerui.android.extensions.Styles
import com.intuit.playerui.android.extensions.overlayStyles
import com.intuit.playerui.android.extensions.removeSelf
Expand Down Expand Up @@ -47,7 +47,7 @@ public typealias AndroidPlayerConfig = AndroidPlayer.Config
public class AndroidPlayer private constructor(
private val player: HeadlessPlayer,
override val plugins: List<Plugin> = player.plugins,
) : Player(), ScriptSourceProvider by player.runtime as? ScriptSourceProvider ?: UnsupportedScriptProvider(player.runtime) {
) : Player() {

/** Convenience constructor to provide vararg style [plugins] parameter */
public constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.intuit.playerui.android.debug

import com.alexii.j2v8debugger.ScriptSourceProvider
import com.intuit.playerui.core.bridge.runtime.Runtime
import com.intuit.playerui.core.player.PlayerException

internal class UnsupportedScriptProvider(private val runtime: Runtime<*>) : ScriptSourceProvider {
override val allScriptIds: Collection<String>
get() = throw PlayerException("Unsupported exception, $runtime runtime does not support JS debugging")

override fun getSource(scriptId: String): String {
throw PlayerException("Unsupported exception, $runtime runtime does not support JS debugging")
}
}
//package com.intuit.playerui.android.debug
//
//import com.alexii.j2v8debugger.ScriptSourceProvider
//import com.intuit.playerui.core.bridge.runtime.Runtime
//import com.intuit.playerui.core.player.PlayerException
//
//internal class UnsupportedScriptProvider(private val runtime: Runtime<*>) : ScriptSourceProvider {
// override val allScriptIds: Collection<String>
// get() = throw PlayerException("Unsupported exception, $runtime runtime does not support JS debugging")
//
// override fun getSource(scriptId: String): String {
// throw PlayerException("Unsupported exception, $runtime runtime does not support JS debugging")
// }
//}

0 comments on commit a934661

Please sign in to comment.