-
Notifications
You must be signed in to change notification settings - Fork 87
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
Adding intent causes the app in release builds to throw realmexception #1355
Comments
Hi @milindgoel15! |
No, I have not tried it yet. Will do Do you happen to know or any idea why the realm is getting locked after adding android intent plugin to the project? |
Setting a different path is much more difficult with Android 13. Because google doesn't let apps to access external storage. Is there any other workaround to this issue? Edit 1: Plus all the existing data of users won't be there in the new directory location. Edit 2: Is there any option to export the realm db file and import it later for restoring data? |
@milindgoel15, unfortunately i couldn't reproduce this error. It works for me. Maybe what I do is different from your code. It will be good if you can share some parts of your code. What do you launch with If I understand correctly, you have already the realm file on your device and it is locked by some reason.
You can use this as an workaround, but it will be good to know why the files are locked. |
Yes, sure. This is my realm service and i am using it with riverpod provider to watch/read changes. class RealmServices {
late Realm realm;
RealmServices() {
realm = getRealm();
}
Realm getRealm() {
final Configuration config = Configuration.local(
[
TodoModel.schema,
NoteModel.schema,
FutureModel.schema,
],
schemaVersion: 8,
);
return Realm(config);
}
} final realmProvider = Provider((ref) => RealmServices());
It gets locked if the release build is made with the intent/add_2_calendar package. Otherwise works.
About this, by default, the file is stored in data/data location which cant be accessed by a normal user. So copying is not possible. I checked the path and its in data/data/packagename/files/default.realm.
Just tested this and it gives However, i also tried running the production debug variant and it gave this exception: Also, just to note, I tried changing the default path to So maybe the above code could help figure out why it's locking the realm in the default path? |
Some updates to the previous comment: For stack trace, i tried: and after that, it gave this error logs: The following PathNotFoundException was thrown building Home(dirty, dependencies: [UncontrolledProviderScope], state: _HomeState#9a51d):
ealm\', path = '/data/data/packagename/files/default.realm\default.realm' (OS Error: No such file or directory, errno = 2) This is after i copied the code you provided. But again hot restarting the app works. |
So I was trying out copying the old data into the new location. I modified the code you provided for copying data as i tested using the android studio to look into the system partition. I found that the realm doesn't use this path: but it only works in certain conditions. more explained below: String appDir = "/storage/emulated/0/Android/data/com.mgprojects.todoify.dev/files/database.realm"; this is my new dir created using storage permission final String storagePath = Configuration.defaultStoragePath; // old path
if (Directory(storagePath).existsSync()) { // this has to run to successfully copy the old data into new location
Directory(storagePath).createSync();
File("$storagePath/default.realm").copySync(appDir);
Configuration.defaultRealmPath = appDir;
print('old data copied');
} when data is copied, when we try to add new todo or anything, it creates an error: Exception has occurred.
RealmException (RealmException: Error opening realm at path /storage/emulated/0/Android/data/com.mgprojects.todoify.dev/files/database.realm. Error code: 1021 . Message: Failed to memory buffer:Invalid top array size (ref: 2704, array size: 0) file size: 0, read lock size: some(4096), read lock version: some(4)) To prevent error, we have to reverse the check condition to: if (!Directory(storagePath).existsSync()) { // now it wont run, making the app work to store new data
Directory(storagePath).createSync();
File("$storagePath/default.realm").copySync(appDir);
Configuration.defaultRealmPath = appDir;
print('old data copied');
} we can use the new directory to store new data by providing it in path final Configuration config = Configuration.local(
[
TodoModel.schema,
NoteModel.schema,
FutureModel.schema,
],
schemaVersion: 8,
path: appDir,
);
return Realm(config);
} Do you know how to modify this so as to make the if condition only run once when it has to copy old data? also, i am getting weird log in console after moving data to new location: W/1.ui (17856): type=1400 audit(0.0:48425): avc: denied { create } for name="access_control.new_commit.cv" scontext=u:r:untrusted_app:s0:c86,c257,c512,c768 tcontext=u:object_r:media_rw_data_file:s0:c86,c257,c512,c768 tclass=fifo_file permissive=0 app=com.mgprojects.todoify.dev
W/1.ui (17856): type=1400 audit(0.0:48426): avc: denied { create } for name="access_control.pick_writer.cv" scontext=u:r:untrusted_app:s0:c86,c257,c512,c768 tcontext=u:object_r:media_rw_data_file:s0:c86,c257,c512,c768 tclass=fifo_file permissive=0 app=com.mgprojects.todoify.dev
W/1.ui (17856): type=1400 audit(0.0:48427): avc: denied { create } for name="database.realm.note" scontext=u:r:untrusted_app:s0:c86,c257,c512,c768 tcontext=u:object_r:media_rw_data_file:s0:c86,c257,c512,c768 tclass=fifo_file permissive=0 app=com.mgprojects.todoify.dev Some updates to this: I was able to add a conditional check for the copy db condition. While it worked fine in the debug variant. The release build was still not able to open the realm even if the new location is in android/data when the intent plugins are added to pubspec. |
Some new tests: I had them combined since the first build until i added this calendar/intent plugins which starts breaking the build. To test this in your end, go to the same file and combine the 2 blocks: From: subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
} to subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
} and the app will stop working in the release build. You will also notice the build generated won't be in the usual location, i.e, android/build/outputs and build/app/outputs/flutter-apk. Because normally, they are generated in build folders only, not in android. |
Hi @milindgoel15! |
Yes, we don't need to copy the realm file now. Although I was wondering if it is possible to implement a backup and restore function? Will the same method of copying the db file be used for such a purpose? Realm doesn't have any built-in function ig. |
You can use realm-dart/test/realm_test.dart Line 1690 in eb81b95
|
➤ desistefanova commented: I'm closing this issue, because the user had found the reason why it happens and it is not something that should be fixed in the realm package. |
Alright thanks. |
Hii. I faced the similar issue few weeks back, and the above solution , separating the subprojects did fixed the issue. And all of sudden, today same thing is happening, the app is working fine on debug mode, but on release mode it is throwing same Exception. Flutter Doctor output :
|
Your current error in the screenshot seems to be different from what this issue was for. Try to use the path provider and usage of storage permission. Android doesn't let you write to many folders/directory because of scoped storage so you have to choose your folder path accordingly. |
@milindgoel15 But I am not trying to write in multiple folders/directory, . I have not setup my app to write in specific directory, so it should use the default location. And it was working till yesterday. |
According to your error, it's trying to create a directory named |
@milindgoel15 I have not written any code to manually create directory or to create files at any specific directory. I even have to specified the base file path. |
check your realm config. |
@Shreedhar73 What platform are you running the app on? (OS & version)? Could you tell me the content of How does your realm import statement look? Also, in the future, please open new issues pointing to old ones, if you believe you experience a similar issue, instead of continuing on an already closed issue. This works better for our workflow. |
Android 13, |
@Shreedhar73 And the content of |
The app doesnt even reach to the point, where I have called Configuration.FlexibleSync |
But if I close the app and restart the app it works fine and the config path here is : /data/data/com.yipl.onlyever/files/mongodb-realm/appID/64af9051276e5ab5f17044b9/default.realm .. |
@Shreedhar73 What is |
If closing the app, and restarting fixed it, can you then reproduce the issue anymore? |
@nielsenko yes next time I do clean installation of the app, same issue occurs. |
Does not compute? 😕 Do you have a minimal reproduction, you can send me? |
@nielsenko I have not provided the baseFilePath in the appConfiguration but when I print the 'Configuration.defaultRealmPath' FileSystemException: Creation failed, path = 'default.realm' (OS Error: Read-only file system, errno = 30) |
@Shreedhar73 Yes, something goes wrong when determining the default. Are you running on an emulator, or a real device? |
@nielsenko Its on real device. Redmi note 10 pro ( Android 13) |
Thx, as a work-around you could try taking a dependency on path_provider and specify a suitable |
@nielsenko That worked, although I am not sure if it is the correct way. |
@Shreedhar73 I'm trying to reproduce on my end. I don't have a Redmi note 10 pro at hand, and I cannot make it fail on my end. Can I ask you to run this project on your end? Basically just: Hmm, not sure why the code-link preview is not working, anyway it is basically just trying to open a sync'ed realm: import 'package:flutter/material.dart';
import 'package:realm/realm.dart';
part 'main.g.dart';
@RealmModel()
class _Stuff {
@PrimaryKey()
@MapTo('_id')
late ObjectId id;
}
final app = App(AppConfiguration('evil-app-mggjg'));
final userProvider = () async {
return app.currentUser ?? await app.logIn(Credentials.anonymous());
}();
final realmProvider = () async {
return Realm(Configuration.flexibleSync(
await userProvider,
[Stuff.schema],
));
}();
Future<void> main() async {
final realm = await realmProvider;
runApp(MyApp(realm: realm));
}
class MyApp extends StatelessWidget {
final Realm realm;
const MyApp({super.key, required this.realm});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Material(
child: Center(
child: Text(
'successfully opened realm at:\n${realm.config.path}}',
),
),
),
);
}
} |
@nielsenko Sure just give me few minutes |
@nielsenko It is working fine. Seems like dependency in my projects are creating the issue. |
@Shreedhar73 Could you show your pubspec.yaml? |
bloc: ^8.1.1
realm: ^1.0.3
flutter:
sdk: flutter
flutter_bloc: ^8.1.2
flutter_localizations:
sdk: flutter
intl: ^0.18.0
dio: ^5.0.3
get_it: ^7.2.0
google_fonts: ^4.0.4
flutter_html: ^3.0.0-beta.2
url_launcher: ^6.1.10
just_audio: ^0.9.32
auto_route: ^5.0.0
equatable: ^2.0.5
dartz: ^0.10.1
shared_preferences: ^2.0.20
fluttertoast: ^8.2.1
very_good_infinite_list: ^0.7.0
youtube_explode_dart: ^2.0.1
flutter_inappwebview: ^5.7.2+3
cached_network_image: ^3.2.3
google_sign_in: ^6.1.2
flutter_svg: ^2.0.0+1
firebase_auth: ^4.6.2
firebase_core: ^2.13.1
firebase_crashlytics: ^3.3.1
scroll_to_index: ^3.0.1
modal_bottom_sheet: ^3.0.0-pre
visibility_detector: ^0.4.0+2
image_picker: ^1.0.2
expandable:
collection:
video_player:
replay_bloc: ^0.2.4
json_serializable: ^6.6.2
workmanager: ^0.5.1
percent_indicator: ^4.2.3
rounded_background_text: ^0.3.0
amplify_storage_s3: ^1.0.1
amplify_flutter: ^1.0.1
amplify_auth_cognito: ^1.0.1
flutter_screenutil: ^5.7.0
google_sign_in_macos:
path: google_sign_in_macos
google_sign_in_platform_interface: ^2.2.0
http:
flutter_markdown: ^0.6.17+1
markdown_widget: ^2.2.0
flutter_math_fork: ^0.7.1
file_selector: ^1.0.0
path_provider: ^2.1.1
desktop_drop: ^0.4.3
fvp: ^0.4.0
wakelock_plus: ^1.1.1
file_picker: ^5.5.0 |
I added all of those packages on the newer project with your code and then the issue is reproducing. |
Hmm.. I had to update minSdkVersion to 24 on Android to build, but I still don't have any issue on my end (Running on Pixel 7 Pro - Android 14) |
With all those packages ? Removing fvp works on my side . |
Yes, I added them all. But maybe my I also tried on a Pixel 6 Pro with Android 13, still I see no issue. What version of |
fvp : 0.4.0 |
@Shreedhar73 What version of flutter are you running currently? |
@nielsenko 3.10.5 |
@nielsenko Yes so, I think the issue is solved (atleast for my usecase) Since the OG 'VideoPlayer' doesnt support mac os platform we are using the 'FVP' , Currently, the registerWith method was being called after the realmAppConfiguration. (on main) Calling "registerWith" before setting up app configuration fixes my issue. ( but that doesnt gives anything why the issue occured on first place and I have to test it on mac application too, I will let you know tommorow how it goes.) Thanks Again |
Still cannot make it fail on my end. Tried calling I have pushed a commit with my latest additions to the default_path_issue repo. Can you make it fail like this on your |
@nielsenko with only realm and fvp on pubsec, your code is working fine on my end. |
I can replicate the issue (8/10 times) when desktop_drop: ^0.4.3 is on pubspec with fvp and realm. |
Still no success (or rather failure) on my end. I have added the Right now I have to move on with other work. Happy we got it working for you, but annoyed that I don't understand why it fails in the first place. Good luck with your project |
What happened?
I am using a local configuration-based realm and i want to create a scheduled task and add it to my calendar app. For this, i am using android_intent_plus to create an intent. But whenever i add this plugin to a project and build a release apk. The app throws a realm exception.
If I remove the plugin from the project, do flutter clean and build a release apk. The app works fine. is it a plugin issue?
I tried adding the plugin package name to Proguard and tested without any proguard or obfuscation.
Repro steps
Version
3.10.5
What Atlas Services are you using?
Local Database only
What type of application is this?
Flutter Application
Client OS and version
Android 13
Code snippets
No response
Stacktrace of the exception/crash you're getting
Relevant log output
No response
The text was updated successfully, but these errors were encountered: