objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
927 stars 115 forks source link

Invalid Plugin Specification (flutter v1.20+) #112

Closed rmtmckenzie closed 3 years ago

rmtmckenzie commented 3 years ago

When trying to build my app on Flutter (Channel master, 1.21.0-6.0.pre.42), build fails with this error: """dart Invalid plugin specification objectbox. Cannot find the flutter.plugin.platforms key in the pubspec.yaml file. """

I'm assuming due to the missing specification for android & iOS plugin files.

vaind commented 3 years ago

Looks like a new requirement for the upcoming flutter version... A pull request would be very welcome if you've stumbled upon a solution in the meantime.

I guess we'll have to address this for the future version support.

On Tue, Jul 28, 2020, 9:01 PM Morgan notifications@github.com wrote:

When trying to build my app on Flutter (Channel master, 1.21.0-6.0.pre.42), build fails with this error: """dart Invalid plugin specification objectbox. Cannot find the flutter.plugin.platforms key in the pubspec.yaml file. """

I'm assuming due to the missing specification for android & iOS plugin files.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/objectbox/objectbox-dart/issues/112, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQOG4RSCY3O2HAOLERWAILR54N6ZANCNFSM4PK2I3JA .

rmtmckenzie commented 3 years ago

Yeah I'm just working it now tbh, I have android working and just testing out iOS

rmtmckenzie commented 3 years ago

Well I gave it a start, but it's crashing on run on iOS (not finding the objectbox symbols I'm thinking).

I've run out of time to work on it, but here's what I had started on:

https://github.com/rmtmckenzie/objectbox-dart/tree/updated-pubspec-platforms

I'll do a PR if I can get it to work properly.

vaind commented 3 years ago

I've been able to reproduce the "missing symbols" on iOS part of this issue but not find the cause yet, The upstream issue: https://github.com/flutter/flutter/issues/62853

vaind commented 3 years ago

Also WRT to other changes in your branch (updated-pubspec-platforms), those seem good on a first look but we'll have to wait until the flutter FFI plugin handling is sorted before merging.

vaind commented 3 years ago

Can't get xcode to load the library properly - the problem is objectbox-swift sourced native framework is called ObjectBox.framework which is the same name as flutter uses when it compiles our (dart) objectbox-dart/ios/objectbox.podspec. It would have been a problem before (with an older version of flutter), if we already had some source codes in ios/ - now we need them for the new flutter to recognize objectbox as a flutter plugin with custom implementation.

And because we're trying to include both the objectbox-swift sourced ObjectBox.framework and newly flutter-generated objectbox.framework this creates a conflict, resulting in xcode/cocoapods ignoring the ObjectBox.framework and taking only the one from flutter:

ls -alh build/ios/iphoneos/Runner.app/Frameworks/
total 286960
drwxr-xr-x  13 objectbox  staff   416B Aug  7 17:36 .
drwxr-xr-x  27 objectbox  staff   864B Aug  7 17:36 ..
drwxr-xr-x   5 objectbox  staff   160B Aug  7 17:36 App.framework
drwxr-xr-x   6 objectbox  staff   192B Aug  7 17:36 Flutter.framework
drwxr-xr-x   4 objectbox  staff   128B Aug  7 17:36 ObjectBox.framework
-rw-r--r--   1 objectbox  staff    91M Aug  7 17:36 libswiftCore.dylib
-rw-r--r--   1 objectbox  staff   440K Aug  7 17:36 libswiftCoreFoundation.dylib
-rw-r--r--   1 objectbox  staff   1.9M Aug  7 17:36 libswiftCoreGraphics.dylib
-rw-r--r--   1 objectbox  staff   1.0M Aug  7 17:36 libswiftDarwin.dylib
-rw-r--r--   1 objectbox  staff   3.9M Aug  7 17:36 libswiftDispatch.dylib
-rw-r--r--   1 objectbox  staff    41M Aug  7 17:36 libswiftFoundation.dylib
-rw-r--r--   1 objectbox  staff   664K Aug  7 17:36 libswiftObjectiveC.dylib
drwxr-xr-x   4 objectbox  staff   128B Aug  7 17:36 path_provider.framework
graybox:objectbox_demo objectbox$ ls -alh build/ios/iphoneos/Runner.app/Frameworks/ObjectBox.framework/
Info.plist  objectbox   
graybox:objectbox_demo objectbox$ ls -alh build/ios/iphoneos/Runner.app/Frameworks/ObjectBox.framework/
total 456
drwxr-xr-x   4 objectbox  staff   128B Aug  7 17:36 .
drwxr-xr-x  13 objectbox  staff   416B Aug  7 17:36 ..
-rw-r--r--   1 objectbox  staff   743B Aug  7 17:36 Info.plist
-rw-r--r--   1 objectbox  staff   222K Aug  7 17:36 objectbox

I've tried renaming ObjectBox.framework to ObjectBoxC.framework but it crashed during startup. The binary of the lib seems to have hardcoded ObjectBox as a framework name so it's not a simple file rename and a google search on how to rename the framework doesn't yield any actual results to me (except for changing the source project itself, which is a no-go as it means changing objectbox-swift).

Therefore, I'm falling back to the only other option I can currently think (maybe except from ignoring objectbox-swift and building and distributing objectbox-c for iOS separately, which doesn't look appealing): I'm extracting objectbox_flutter_libs as a separate dart package, this would result in flutter using a different framework name objectbox_flutter_libs.framework, avoiding the conflict with ObjectBox.framework. Unfortunately, that also means we have to have yet another package on pub.dev. I hope I'll be able to depend on it from the objectbox package so there's no extra step for end users to take.

vaind commented 3 years ago

So... extracting flutter libs to a separate package works for iOS

but breaks Android now... I'll have to see about that: E/flutter ( 6747): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library (dlopen failed: library "libobjectbox-jni.so" not found)

rmtmckenzie commented 3 years ago

I found a way to get this to almost work without having to bother with that. Unfortunately almost isn't the same as just working 😞 . But what I did was set the module_name in the podspec to objectboxdart. Unfortunately this breaks the flutter build, but actually only in once place - the GeneratedPluginRegistrant.m file. For now I'm probably going to just live with that and modify it by hand after each pub get/update.

What I have done is opened a bug against flutter to have them look into this, as I don't think you'll be the only native library that has collisions with the relevant flutter packages. It's here: https://github.com/flutter/flutter/issues/63240, and what it proposes is a keyword in the plugin's pubspec.yaml which would change the module that the package is symlinked etc to, or at least changes the name of the framework. I could do a PR against flutter for just the module part of it pretty easy, but I'm not 100% sure whether they'd be happy about leaving the name in the search path the same as it is now or whether they'd want to have that set from the moduleName key as well... and in that case I'm not as confident about figuring out how the flutter tool does that in the rather limited amount of time I have to work on this.

Anyways, not immediately helpful but hopefully that's going in the right direction at least... Oh and if you think that what I've proposed in the flutter issue would be a good idea, maybe +1 it there as that's how they determine the order they look at issues.

vaind commented 3 years ago

Went with a separate objectbox_flutter_libs package flutter users have to depend on in addition to objectbox when used in flutter. Dart-only user still only depend on objectbox.

Followup to further improve this (if/when possible): #114

vaind commented 3 years ago

Should be resolved with the upcoming v0.7.0 so closing. Feel free to follow up in case of further issues.