Closed unsuitable001 closed 3 years ago
Is this code to reproduce this available on github?
Is this code to reproduce this available on github?
@mannprerak2 Yes. The main code is the same. But, there are some more work to do to reproduce it properly.
cmake_minimum_required(VERSION 3.16) # for example
project(cronet_flutter)
add_library( wrapper_android
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
"../wrapper.cc"
"../wrapper.h"
"../sample_executor.cc"
"../sample_executor.h"
"/usr/lib/dart/include/dart_api_dl.c"
)
include_directories(/usr/lib/dart/include/)
add_compile_options(-fPIC -ldl -rdynamic -DDART_SHARED_LIB -fpermissive)
Adjust the paths accordingly
Generate ninja build files
cmake -H. -Bgenerated/ninja/project/debug/arm-64-v8a -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-26 -DANDROID_NDK=~/Android/Sdk/ndk/22.1.7171670 -DCMAKE_TOOLCHAIN_FILE=~/Android/Sdk/ndk/22.1.7171670/build/cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN=clang3.6 -G Ninja
Build using ninja
cd generated/ninja/project/debug/arm-64-v8a
ninja
There you will get the libwrapper_android.so
file.
Note: Either change the .so file names to the same as in dart files. Or, change the name in the dart file
android/app/src/main/jniLibs/arm64-v8a
directory from your flutter project's root directory, and paste libcronet
and wrapper
shared libs there. (You may have to create jniLibs and subsequent sub-dirs if they do not exist)Now all set. You can do flutter run
to reproduce the bug
Also attaching my cronet build here. Just in case if you don't want to build yourself.
That quite a lot :p, I think you can wrap all this in a package.
Take a loot at this -> https://github.com/Sunbreak/cronet_flutter. This works out of the box.
Edit: Maybe you can use this as a starting point, put your wrapper code here and see if a similar error occurs?
These https://github.com/Sunbreak/cronet.dart, https://github.com/Sunbreak/native_interop.tour might be helpful.
cc @dcharkes
It is a lot :/ but, most of the work is building the wrapper actually. As I was testing, I haven't put anything extra in gradle file (I'm yet to be familiar with this, that's why :/ ). If we use gradle build file, most of the task will be automated for us though.
Take a loot at this -> https://github.com/Sunbreak/cronet_flutter. This works out of the box.
Okay. I'll check this out.
And, I found this: https://github.com/Sunbreak/cronet_flutter/issues/8 The exact same problem I'm facing. And, as per the patch here, I think my speculations are correct. I'll update you after fixing.
One more question I need to ask. This package is a Dart Package
and not a Flutter Package
, so that we can use it with Dart CLI
and non-flutter scenarios. So, we can't use flutter
as a dependency. Without using it, can we integrate platform specific code to our plugin in a well organized manner? (Like Sunbreak did).
If not, then we can rely upon some shell script , though that don't look good.
So, is there any way that we can add platform specific code and also maintain compatibility with Dart CLI? @mannprerak2 @dcharkes
Context: For testing this package on flutter, I'm just importing this library and adding all the platform specific code on the main (example) project directly. In that process, I guess I'm missing something. That causes this error: The plugin
cronet_flutterdoesn't have a main class defined in <some_long_path_here>/com/example/cronet_flutter/CronetFlutterPlugin.kt
Note: I have MainActivity.kt
file in the same location as CronetFlutterPlugin.kt
and adding CronetFlutterPlugin
as plugin in pubspec
. Ideally, CronetFlutterPlugin.kt
should reside in the package's platform specific code's dir and not in project's. I'm yet to discover how flutter merges them at the build time. I'll let you know after I figure it out.
So, is there any way that we can add platform specific code and also maintain compatibility with Dart CLI?
I suppose we can split the package into 2, maybe something like cronet and flutter_cronet.
So, is there any way that we can add platform specific code and also maintain compatibility with Dart CLI?
I suppose we can split the package into 2, maybe something like cronet and flutter_cronet.
If I'm allowed to do that, then I'll be pushing the changes today (expected). Separating will solve many of the confusions I have now. :p
https://github.com/google/webcrypto.dart is set up as both dart standalone package and flutter plugin.
https://github.com/google/webcrypto.dart is set up as both dart standalone package and flutter plugin.
Wow! I'll surely look into that.
For testing, I created a separate flutter plugin
and used this repo as dependency. I'm getting the version
string properly and also NOT getting the error in this issue.
But, sadly, I'm not getting any data also. I'm still missing something. I'll update as I get some more info.
Package is working now in android. Repo: https://github.com/unsuitable001/flutter_cronet_sample (only arm64 build is provided. for other devices, have to build cronet from scratch)
~But, there are some interesting bugs in the flutter solution. (Though, they aren't impacting the usability. I mean, results produced are error free). You may look into those issues there.~
Edit: Issues have been fixed. One interesting thing I encountered while checking webcrypto
is, it is using flutter
as dependency (and, in environment of course). I can't find any difference between a regular flutter plugin's pubspec
file and webcrypto's. That makes me wonder, how it is a standalone package... I can use it without flutter for sure. But, I still have to install flutter, right?
Closing this issue as it has been fixed (but, the patch is in seperate repo as a seperate package). When I merge that repo to this, I'll refer this issue.
Flutter package with Android support: https://github.com/unsuitable001/flutter_cronet_sample
I get a crash whenever I try to start the cronet engine. I can get the version string without any issues though. The log says: