-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flutter test breaks when using textRun #354
Comments
Hi @cerealexx , the Rive Font engine won't have initialized at this point. The best way to do this is to manage the loading of the riv binary yourself, and you can also manually call You can see an example in our package tests: https://github.com/rive-app/rive/blob/master/packages/rive_flutter/test/goldens/text/golden_text_test.dart Something like: /// Loads a Rive file from the assets sub-folder
ByteData loadFile(String filename) {
final file = File(
'./${Directory.current.path.endsWith('/test') ? '' : 'test/'}$filename');
return ByteData.sublistView(file.readAsBytesSync());
}
...
final riveBytes = loadFile('assets/electrified_button_simple.riv');
final file = RiveFile.import(riveBytes);
...
RiveAnimation.direct(file); |
Hi @HayesGordon , I was running into the same issue as @cerealexx as I tried to write a simple widget test for a rive widget. I applied the solution you proposed and it actually works. Unfortunately I'm now getting a similar error and still cannot get my test running properly. My simplified code looks like this:
When running this test code I get the following error as soon as the line
Do you have any idea what could be the problem and how to solve it? Thanks ahead! |
@mklemann90 I'm experiencing a similar issue. Have you found a way to solve it? |
@luisredondo so far not, but since it was not top priority in our project, I postponed looking for a solution after I got stuck with this issue. |
Hi all, I'm unable to replicate tests breaking. If someone can share a reproducible example in a repository, I can take a look. But here is an example unit test with files: import 'dart:io';
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:rive/rive.dart';
extension _TextExtension on Artboard {
TextValueRun? textRun(String name) => component<TextValueRun>(name);
}
ByteData _loadFile(String filename) {
final file = File(
'./${Directory.current.path.endsWith('/test') ? '' : 'test/'}$filename');
return ByteData.sublistView(file.readAsBytesSync());
}
void main() {
late RiveFile riveFile;
setUp(() {
return Future(() async {
final riveBytes = _loadFile('assets/text_run.riv');
await RiveFile.initializeText();
riveFile = RiveFile.import(riveBytes);
});
});
test('Text run updating', () {
final artboard = riveFile.mainArtboard.instance();
final run1 = artboard.textRun('run1')!;
final run2 = artboard.textRun('run2')!;
expect(run1.text, "run1-value");
expect(run2.text, "run2-value");
run1.text = "new value 1";
run2.text = "new value 2";
expect(run1.text, "new value 1");
expect(run2.text, "new value 2");
});
} text_run.riv.zip And here is a golden test that updates a text run: https://github.com/rive-app/rive-flutter/blob/master/test/goldens/text/golden_text_test.dart With output files: https://github.com/rive-app/rive-flutter/tree/master/test/goldens/text/images |
Hey @HayesGordon! I created this repository: Invalid argument(s): Failed to lookup symbol 'init': dlsym(RTLD_DEFAULT, init): symbol not found
dart:ffi DynamicLibrary.lookup
package:rive_common/src/rive_text_ffi.dart 527:15 init
package:rive_common/src/rive_text_ffi.dart init
package:rive_common/src/rive_text_ffi.dart 836:3 initFont
package:rive_common/rive_text.dart 471:15 Font.initialize
package:rive/src/rive_file.dart 365:18 RiveFile.initializeText
test/widget_test.dart 23:22 main.<fn>.<fn> I pasted the exact same code you shared, and added the I'm running with: Flutter:
Machine: Please let me know if you are able to reproduce. |
@luisredondo thanks for the repro. This was a mistake on my side, I forgot that Flutter tests need to load in the dylib for macOS. I'm providing a solution, but to give some context, the Rive editor uses the same underlying Here are the steps:
This script will generate a EDIT: I only tested this on the latest version of Rive, at the time of writing v0.13.2
#!/bin/bash
# Default flag for force rebuild set to false
FORCE_REBUILD=false
# Parse command-line options
while getopts "f" opt; do
case $opt in
f)
FORCE_REBUILD=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# Directory where the version file and build outputs will be stored
BUILD_DIR="shared_lib/build/bin/debug/"
# Version file path
VERSION_FILE="rive_common_version.txt"
# Make sure Rive and Rive Common is available
flutter pub get
# Fetch the current rive_common version from pubspec.lock
CURRENT_VERSION=$(dart pub deps -s list | grep rive_common | sed 's/[^0-9.]*//g' | head -n 1)
echo $CURRENT_VERSION
# Check if the version was actually retrieved
if [ -z "$CURRENT_VERSION" ]; then
echo $'\nFailed to retrieve rive_common version. Please check the output of 'dart pub deps -s list'.'
exit 1
fi
# Read the version from disk if the version file exists
if [ -f "$VERSION_FILE" ]; then
SAVED_VERSION=$(cat "$VERSION_FILE")
else
SAVED_VERSION=""
fi
# Check if the build directory is empty
if [ "$(ls -A $BUILD_DIR)" ]; then
BUILD_DIR_EMPTY=false
else
BUILD_DIR_EMPTY=true
fi
# Compare versions and directory status unless force rebuild is triggered
if [ "$FORCE_REBUILD" = false ] && [ "$CURRENT_VERSION" = "$SAVED_VERSION" ] && [ "$BUILD_DIR_EMPTY" = false ]; then
echo $'\nNo rebuild needed. Exiting...\n'
exit 0
fi
# Save the current version to disk
echo $CURRENT_VERSION > $VERSION_FILE
echo ""
echo "Rive Common Version: $CURRENT_VERSION"
echo ""
# Change to the directory where 'rive_common' is located in the local pub cache
pushd ~/.pub-cache/hosted/pub.dev/rive_common-$CURRENT_VERSION
# Run the update_dependencies script with 'force' option
./update_dependencies.sh force
# Change to the directory containing the shared library source
pushd shared_lib
# Build the shared library
./build_shared.sh
# Store the path to the built shared library
RIVE_TEXT_DYLIB=$PWD/build/bin/debug/librive_text.dylib
# Return to the previous directory
popd
# Return to the initial directory
popd
# Create the target directory if it doesn't exist
mkdir -p $BUILD_DIR
# Copy the built shared library to the target directory
cp $RIVE_TEXT_DYLIB $BUILD_DIR
echo $'\nLibrary built and copied successfully.\n' |
Is there any long-term solution for this? |
A Slightly modified version of the script so it can run on ubuntu-latest as well #!/bin/bash
# Default flag for force rebuild set to false
FORCE_REBUILD=false
# Parse command-line options
while getopts "f" opt; do
case $opt in
f)
FORCE_REBUILD=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# Directory where the version file and build outputs will be stored
BUILD_DIR="shared_lib/build/bin/debug/"
# Version file path
VERSION_FILE="rive_common_version.txt"
# Current dir
CURRENT_DIR=$(pwd)
# Make sure Rive and Rive Common is available
flutter pub get
# Fetch the current rive_common version from pubspec.lock
CURRENT_VERSION=$(dart pub deps -s list | grep rive_common | sed 's/[^0-9.]*//g' | head -n 1)
echo $CURRENT_VERSION
# Check if the version was actually retrieved
if [ -z "$CURRENT_VERSION" ]; then
echo $'\nFailed to retrieve rive_common version. Please check the output of 'dart pub deps -s list'.'
exit 1
fi
# Read the version from disk if the version file exists
if [ -f "$VERSION_FILE" ]; then
SAVED_VERSION=$(cat "$VERSION_FILE")
else
SAVED_VERSION=""
fi
# Check if the build directory is empty
if [ "$(ls -A $BUILD_DIR)" ]; then
BUILD_DIR_EMPTY=false
else
BUILD_DIR_EMPTY=true
fi
# Compare versions and directory status unless force rebuild is triggered
if [ "$FORCE_REBUILD" = false ] && [ "$CURRENT_VERSION" = "$SAVED_VERSION" ] && [ "$BUILD_DIR_EMPTY" = false ]; then
echo $'\nNo rebuild needed. Exiting...\n'
exit 0
fi
# Save the current version to disk
echo $CURRENT_VERSION > $VERSION_FILE
echo ""
echo "Rive Common Version: $CURRENT_VERSION"
echo ""
# Change to the directory where 'rive_common' is located in the local pub cache
cd $PUB_CACHE/hosted/pub.dev/rive_common-$CURRENT_VERSION || exit 1
# Run the update_dependencies script with 'force' option
./update_dependencies.sh force
# Change to the directory containing the shared library source
cd shared_lib || exit 1
# Build the shared library
./build_shared.sh
# Store the path to the built shared library
if [ -f "$PWD/build/bin/debug/librive_text.so" ]; then
RIVE_TEXT_DYLIB=$PWD/build/bin/debug/librive_text.so
else
RIVE_TEXT_DYLIB=$PWD/build/bin/debug/librive_text.dylib
fi
# Return to the initial directory
cd $CURRENT_DIR || exit 1
# Create the target directory if it doesn't exist
mkdir -p $BUILD_DIR
# Copy the built shared library to the target directory
cp $RIVE_TEXT_DYLIB $BUILD_DIR
echo $'\nLibrary built and copied successfully.\n' |
Didn't it depend on |
@spydon, it did depend on We're working on a significant underlying change for the Rive Flutter runtime that will directly impact this. For this new version of the Rive Flutter runtime, we're discussing the best way to approach this issue. Most likely, we will build and package the libraries instead of requiring them to be built. So, in that new major release of Rive Flutter, we will address this issue. |
Super, thanks for the update! :) |
Hi @HayesGordon, I wanted to ask if you could provide any information regarding the timeline for the next major release of Rive Flutter. Your insights would be greatly appreciated! Thank you for your help. |
+1 |
Workaround script started generating errors in the pipeline |
Can confirm too the script is not working anymore. Any recommended approach while waiting for the refactor? Thanks |
Releases new `rive_common` and updates `rive_flutter` to use it. Resolves: #354 (comment) Diffs= de19b09fb3 Rive common release 0.4.13 (#8638) 11ff873bf8 support wrapping text in auto width inside a layout (#8624) 28582ea0fd fixed workflow stuff (#8628) b32973afd6 updates to diff.py (#8623) c7fe86a7bf Fix bug in draw key (#8620) 91f9ab8aec fix for incorrect android build option (#8608) 81709286ea Update linear animation advanceAndApply to return if more animation remains (#8610) 37c6987847 Add check to TextModifierGroup to prevent out of bounds access (#8606) 7be5f73b5a editor: update the repeat limit for n-slicing (#8604) 3eefba5039 CoreText fallback shaper ex (#8568) 807f9b20ac image diff hiistogram mode (#8601) 17474d3e2c feat: expose hit test to runtimes (#8598) 36e73f6b4b Fixup android_gms_browserstack (#8599) 88543fa792 Nnnn range data converter (#8585) a2b0cb230a Normalize GM tests (#8586) e10bb4aafd Rename USING_DEPTH_STENCIL to RENDERING_MODE_MSAA (#8584) 869816556f Fix invalid memory access (#8546) 8030dc05eb Fix clip planes on S22/Xclipse/ANGLE (#8582) 01e014f82d Add an android_gms job to browserstack (#8583) 1d23ae5782 editor: be more mindful of sending dirt recursively when n-slicing (#8576) cc15ffa4f6 Fix NestedAnimation skipping export too late (#8573) Co-authored-by: Gordon <pggordonhayes@gmail.com>
Thanks for reporting! This should now be resolved in We're not advertising it yet, and it's not yet ready to be used in Rive Flutter, but the new It should automatically download and verify the libraries and also allow you to build them locally. More information will come after we have all the core features and platforms integrated. But if you'd like to experiment you can see if it's building for you locally. |
@HayesGordon you guys are legends, thanks a lot! |
I still experience this issue after upgrading to rive_common 0.4.13 and rive 0.13.18, am I wrong to understand that it should be resolved? |
No, only the script is fixed, the issue persists for now |
I'm experiencing the same issue. Any ideas when this can be resolved? |
@m1rroxof apply this script before running your pipeline and it will be fixed for now (make sure to use the latest Rive package version)
|
Thanks a lot. I will try it |
The tests in the rive flutter repo currently fail due to the exact build issue mentioned above. This is because the I got it working by adjusting the script slightly to check out ref that worked 3 days ago. else
echo "Cloning rive-cpp."
git clone https://github.com/rive-app/rive-cpp
cd rive-cpp
echo "Changing ref to 76cc558f74408ec883094351a29d803d928f9e2d"
git checkout 76cc558f74408ec883094351a29d803d928f9e2d
cd ..
fi @HayesGordon Another idea to improve this situation would be to have the build binaries for the latest rive_common version be ready for download, so people can just have a few lines of code where they copy the downloaded binary to I did this in a little dart function that I can run before my rive tests which works quite nice. // pseudo code
testWidgets((tester) async {
await loadRiveTextRenderingLib();
}); final _projectRootPath =
"${Directory.current.path}/shared_lib/build/bin/debug/";
Future<void> loadRiveTextRenderingLib() async {
final targetPath = "${_projectRootPath}librive_text.dylib";
if (File(targetPath).existsSync()) return;
final riveLib = File(
"${Directory.current.path}/test/test_util/rive/librive_text.dylib",
);
assert(riveLib.existsSync());
Directory(_projectRootPath).createSync(recursive: true);
riveLib.copySync(targetPath);
} With this solution running tests locally on mac is also supported. |
This should be fixed again in the latest @bjartebore (v0.13.19) |
I tried on Rive version 0.13.20, but got the same issue. It's not clear from this thread whether to expect the issue to be fixed in the new Rive version, or if the new version of Rive fixes the script that is the workaround for the issue. |
The ticket is still open. Only the script is fixed for now. |
Description
flutter test breaks when trying to test a widget that uses dynamic texts:
Any test with that widget returns:
Steps To Reproduce
Steps to reproduce the behavior:
Write a test pumping the mentioned widget.
Expected behavior
Test suite should work
The text was updated successfully, but these errors were encountered: