Flutter - Load an asset file into an external Flutter plugin - flutter

I am developing a Flutter plugin with native Platform View. My PlatformView needs a file which is project dependant. I want to pass my file path which is in example project to my library project (Native Android/iOS code). In simple words how can I access my project assets in external library from example/test project.
I was thinking about changing src directory in android gradle but I'm confused how to set scrc directorry to an example project.
flutter_library_project
- android
access file here
- iOS
access file here
- libs
Flutter_library_sample
- assets
file
- android
- iOS
- libs
can access file here

Related

After flutter new project creation I can't locate the main dart file to start programming

I have installed Android Studio and flutter successfully. When I run flutter doctor in command prompt it gives me [all green ticks in these brackets].
The question is that after the creation of a new flutter project on the right-hand side of the screen under the project I am unable to see/locate any dart main file to write code. For further clarification, you can see the attached image below.
Unable to locate the dart file to write code in the project hierarchy:
I have 0 ideas what is still missing in the configuration of Flutter / Android Studio
Well, I figured out why pubspec.yaml and main.dart was not in my project due to the older version of flutter. I downloaded the latest version flutter_windows_2.2.2-stable, created a new flutter project, and included the flutter SDK path of flutter_windows_2.2.2-stable which resolved all my problems. Kindly, make sure whoever wants to start Mobile Application development in Android Studio + Flutter + Dart always download the latest version of everything.
Recent Experiment:
After downloading the latest version of Flutter still, I was unable to get the pubspec.yaml and main.dart files in my Android Studio Project, so the solution is below:
where you have extracted your flutter_windows_2.2.2-stable remember the directory path like E:\src\flutter_windows_2.2.2-stable which is in my scenario.
******************* CMD WORK *******************
Open cmd(Command Prompt) by default you will be in the directory like C:\Users\UserName\
Now go to the path E:\src and to navigate write E: hit enter, now you will be in the E: directory. Write cd E:\src hit enter.
type flutter create project_name ( make sure whenever you withe the name of the project it should be like this my_first_app in this format you name the projects with proper naming convention in flutter [word_word_word_word] ) then hit enter, wait for a while it will create a new flutter project for you including pubspec.yaml and main.dart files + necessary files to be imported.
Reference for naming convention in flutter (https://medium.com/flutter-community/file-and-folder-structure-in-flutter-967b8be3155e#:~:text=Flutter%20doesn't%20have%20a,letters%20and%20underscores%20between%20words.&text=When%20naming%20folders%2C%20you%20want,them%20very%20direct%20and%20clear.)
Right now after the creation of a project(Flutter) in Android Studio you are unable to see/locate the pubspec.yaml and main.dart files use cmd for the project creation which worked in my scenario.

How to use libflutter_linux_glfw.so file and related files from out/host_debug of flutter engine

I followed instructions from Setting up the Engine development to build the flutter engine. Purpose of this was to use the texture support from Texture support for glfw. I could compile the flutter engine.
Next I wanted to use this engine and develop Texture based application. While compiling using the following command, I see that libflutter_linux_glfw.so and other platform files are copied from flutter/bin/cache/artifacts/engine.
flutter build linux
I added the dependency_overrides to pubspec.yaml as follows. But, no luck.
dependency_overrides:
sky_engine:
path: <base folder of engine>/engine/src/out/host_debug_unopt/gen/dart-pkg/sky_engine
sky_services:
path: <base folder of engine>/engine/src/out/host_debug_unopt/gen/dart-pkg/sky_services
Looking forward for the suggestions on the changes required to use files from engine/src/out/host_debug_unopt.
I could use compiled libflutter_linux_glfw.so by using --local-engine-src-path and --local-engine options of flutter given in the following link.
Using a locally-built engine with the flutter tool

Android App Bundle - native code library failed to load

I need to replace the APK to App Bundle feature.
My app using some SDK with native libraries.
The app build.gradle dependencies countains:
     implementation files ('libs / refsi.jar')
     implementation files ('libs / tsi.jar')
The SDK native libraries (two .so files for each architecture) placed under /app/src/main/jniLibs/ (armeabi-v7a | arm64-v8a | x86 | x86_64 | armeabi)
I tried to use googles instructions, and I was looking for help, but after I download the app from google play to my test device, the SDK was not working - the log file shows that the files not found.
"...Native code library failed to load. dalvik.system.PathClassLoader[DexPathList[
[zip file "/data/app/ ....
Please help me understand the correct and simple way to use an app bundle in that case.
This might help you, according to google doc
When building an Android App Bundle, APKs generated from that app bundle that target Android 6.0 (API level 23) or higher now include uncompressed versions of your native libraries by default. This optimization avoids the need for the device to make a copy of the library and thus reduces the on-disk size of your app. If you'd rather disable this optimization, add the following to your gradle.properties file:
android.bundle.enableUncompressedNativeLibs = false

How to import iOS native framework into Flutter?

I want to contribute in this Flutter_blue plugin project adding the functionalities for native iOS using Objective C framework CoreBluetooth. How do I import the framework in to the library so I can start using its APIs?
Update:
CoreBluetooth is not suitable for Flutter project, because it's not a cocoapod dependency. So what I did what, go to cocopods website and look for other bluetooth dependencies from there. You can also find instructions of how to install a dependency there. For me, I made added pod <depdencyname> to <plugin-project>/example/ios/Podfile in the plugin project. Then added dependency: <dependencyname> to the in <plugin-project>/ios/pubspec
I had the same problem for a few time and found a solution by adding this lines to your podspec file at your iOS/ folder in your plugin dir:
s.preserve_paths = 'yourframework.framework'
s.xcconfig = { 'OTHER_LDFLAGS' => '-framework yourframework' }
s.vendored_frameworks = 'yourframework.framework'
Then, on your Flutter project, in the iOS folder, just run pod update on terminal so it can fetch the new dependencies.
You can find the full issue open by me with this problem here.
If you're looking to add a CocoaPod dependency to the iOS "half" of a Flutter plugin, I believe the correct way to do so is to update the podspec file in the /ios folder of the plugin source. I recently did some work on the AdMob plugin, for example, and its podspec lists the SDKs for Firebase and Google Mobile Ads:
https://github.com/flutter/plugins/blob/master/packages/firebase_admob/ios/firebase_admob.podspec
And that's how they get included in the build.

export android project add facebook sdk get error convert to dalvik format failed with error 1

i am doing a small project on android and it using facebook sdk 3.0. everything is ok until i export to upload android market, i got error "error convert to dalvik format failed with error 1" and i try export 2 sample projects in sdk, i got same error. i research on google ,the cause is the projects and facebook sdk have same name file R.java in com.facebook.android. But because it file R.java so i cannot rename it. i try other way, i turn off "build automatically" and delete R.java file in facebook sdk, it can export keystore and apk file but apk file don not work. So what can i do to fix it?
thanks
I was having this problem too with an app that used Facebook SDK. I was trying all sorts of stuff, so I'm not sure what exactly fixed but here's settings that worked for me:
FacebookSDK > Properties > Java Build Path > Order and Export
Android 2.2 - NOT CHECKED
Android Private Libraries - CHECKED
Android Dependencies - CHECKED
MyApp > Properties > Java Build Path > Order and Export
Android 4.2.2 - CHECKED
Android Private Libraries - CHECKED
Android Dependencies - CHECKED
In addition, I had done this before, not sure it mattered. Reverted to Facebook SDK version 3.5 from 3.5.2. Updated to latest ADT 22.2.1. Changed Facebook SDK to use Android 2.2 from 4.2.2.