Skip to content

Commit 75cca1e

Browse files
ErikUggeldahlErikUggeldahl
andcommitted
feat(Android): Scripting support (#11438) 9112280455
Adds the build flags required to enable scripting. Adds two samples, one for legacy, one for Compose, using the Blinko example. Also patches the command server to accept script assets and not crash for unrecognized assets. Co-authored-by: Erik <erik@rive.app>
1 parent 98f6e39 commit 75cca1e

File tree

9 files changed

+102
-4
lines changed

9 files changed

+102
-4
lines changed

.rive_head

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e7142dcfedf6710265bd49fe031c26e663b37f99
1+
9112280455e25db4649d446601f443c763151649

app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
<activity
6060
android:name=".ComposeListActivity"
6161
android:exported="true" />
62+
<activity
63+
android:name=".ScriptingActivity"
64+
android:exported="true" />
65+
<activity
66+
android:name=".LegacyScriptingActivity"
67+
android:exported="true" />
6268
<activity
6369
android:name=".RiveViewActivity"
6470
android:exported="true" />
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package app.rive.runtime.example
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.SystemBarStyle
6+
import androidx.activity.enableEdgeToEdge
7+
import app.rive.runtime.kotlin.RiveAnimationView
8+
import android.graphics.Color as AndroidColor
9+
10+
class LegacyScriptingActivity : ComponentActivity() {
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
super.onCreate(savedInstanceState)
13+
enableEdgeToEdge(
14+
statusBarStyle = SystemBarStyle.dark(AndroidColor.BLACK),
15+
navigationBarStyle = SystemBarStyle.dark(AndroidColor.BLACK)
16+
)
17+
val riveView = RiveAnimationView.Builder(this)
18+
.setResource(R.raw.blinko)
19+
.setAutoBind(true)
20+
.build()
21+
setContentView(riveView)
22+
}
23+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package app.rive.runtime.example
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.SystemBarStyle
6+
import androidx.activity.compose.setContent
7+
import androidx.activity.enableEdgeToEdge
8+
import androidx.compose.foundation.layout.padding
9+
import androidx.compose.material3.Scaffold
10+
import androidx.compose.ui.Modifier
11+
import androidx.compose.ui.graphics.Color
12+
import app.rive.Result
13+
import app.rive.Rive
14+
import app.rive.RiveFileSource
15+
import app.rive.RiveLog
16+
import app.rive.rememberRiveFile
17+
import app.rive.rememberRiveWorker
18+
import app.rive.rememberViewModelInstance
19+
import android.graphics.Color as AndroidColor
20+
21+
class ScriptingActivity : ComponentActivity() {
22+
override fun onCreate(savedInstanceState: Bundle?) {
23+
super.onCreate(savedInstanceState)
24+
enableEdgeToEdge(
25+
statusBarStyle = SystemBarStyle.dark(AndroidColor.BLACK),
26+
navigationBarStyle = SystemBarStyle.dark(AndroidColor.BLACK)
27+
)
28+
RiveLog.logger = RiveLog.LogcatLogger()
29+
30+
setContent {
31+
val riveWorker = rememberRiveWorker()
32+
val riveFile = rememberRiveFile(
33+
RiveFileSource.RawRes.from(R.raw.blinko),
34+
riveWorker
35+
)
36+
37+
Scaffold(containerColor = Color(0xFF0C1935)) { innerPadding ->
38+
when (riveFile) {
39+
is Result.Loading -> LoadingIndicator()
40+
is Result.Error -> ErrorMessage(riveFile.throwable)
41+
is Result.Success -> {
42+
val file = riveFile.value
43+
val vmi = rememberViewModelInstance(file)
44+
Rive(
45+
riveFile.value,
46+
Modifier.padding(innerPadding),
47+
viewModelInstance = vmi
48+
)
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}

app/src/main/res/raw/blinko.riv

2.56 MB
Binary file not shown.

kotlin/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ android {
3737

3838
// Enable removing miniaudio to reduce binary size
3939
def audioEnabled = !project.hasProperty("noAudio")
40+
// Enable removing scripting to reduce binary size
41+
def scriptingEnabled = !project.hasProperty("noScripting")
4042
// Enable ASAN support when debugging
4143
def asanEnabled = project.hasProperty("asan")
4244

@@ -68,6 +70,8 @@ android {
6870
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
6971
// Toggle miniaudio
7072
"-DWITH_RIVE_AUDIO=${audioEnabled ? 'ON' : 'OFF'}",
73+
// Toggle scripting
74+
"-DWITH_SCRIPTING=${scriptingEnabled ? 'ON' : 'OFF'}",
7175
// Needed for ASAN support (if enabled)
7276
// See https://developer.android.com/ndk/guides/asan#building
7377
// and https://developer.android.com/ndk/guides/cmake#android_arm_mode

kotlin/src/main/cpp/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ else ()
6767
set(RIVE_AUDIO_ARG "disabled")
6868
endif ()
6969

70+
# Add an option to remove scripting
71+
# Passed from Gradle with -DWITH_SCRIPTING=ON|OFF
72+
option(WITH_SCRIPTING "Enable Rive scripting support" ON)
73+
if (WITH_SCRIPTING)
74+
# Flag for Premake
75+
set(RIVE_SCRIPTING_ARG "--with_rive_scripting")
76+
# Add to the list of static libraries
77+
list(APPEND static_libs luau_vm)
78+
endif ()
79+
7080
# Add an option to enable ASAN
7181
# Passed from Gradle with -DENABLE_ASAN=ON|OFF
7282
option(ENABLE_ASAN "Enable Address Sanitizer" OFF)
@@ -113,12 +123,12 @@ else ()
113123
message(FATAL_ERROR "Unsupported ABI: ${CMAKE_ANDROID_ARCH_ABI}")
114124
endif ()
115125

116-
# Promote our ${ANDROID_NDK} to an environment var so premake uses the same one.
126+
# Promote our ${ANDROID_NDK} to an environment var so Premake uses the same one.
117127
set(ENV{ANDROID_NDK} "${ANDROID_NDK}")
118128

119129
# Build the Rive C++ runtime and its dependencies as static .a libs
120130
execute_process(
121-
COMMAND bash ${RIVE_RUNTIME_DIR}/build/build_rive.sh --file=premake5_cpp_runtime.lua android ninja ${CONFIG} ${RIVE_ARCH} --no-rive-decoders --with_rive_audio=${RIVE_AUDIO_ARG} ${RIVE_ASAN_FLAG} -- rive_cpp_runtime
131+
COMMAND bash ${RIVE_RUNTIME_DIR}/build/build_rive.sh --file=premake5_cpp_runtime.lua android ninja ${CONFIG} ${RIVE_ARCH} --no-rive-decoders --with_rive_audio=${RIVE_AUDIO_ARG} ${RIVE_SCRIPTING_ARG} ${RIVE_ASAN_FLAG} -- rive_cpp_runtime
122132
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
123133
RESULT_VARIABLE SCRIPT_RESULT
124134
OUTPUT_VARIABLE SCRIPT_OUTPUT

kotlin/src/main/cpp/premake5_cpp_runtime.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ do
2323
'rive_sheenbidi',
2424
'rive_yoga',
2525
'miniaudio',
26+
'luau_vm',
2627
})
2728
end

0 commit comments

Comments
 (0)