Flutter: Request is taking too long to process - json

I am running my application in development (debug) mode on local machine so I'm not sure how much this affects network requests. The target device where the app is running is Android emulator. I have an endpoint which fetches some data, this data can be quite large, it's a large-ish JSON that gets parsed into data structure (class) in my application code.
I am experiencing a problem where sometimes these requests time out (my timeout is set at 30s) even though the actual response is less than 5s. I am attaching a screenshot from dev tools where you can see that the duration of the request is 25 seconds which is just too much. I think time to first byte (TTFB) is the actual time before it starts receiving the data, so the server code is not slow. I don't understand how the "end" time is calculated though.
My internet connection (download) is about 50-70Mbit/s (ADSL).
Screenshot:
What do you think could be the cause for such a long duration of request to be completed? Could it be the size of payload? Or does the framework (Flutter) take a long time to process the response?
I'm using dio² http client to make my requests so not sure if that plays any role. I tried optimising the path where I'm converting JSON response payload into data objects (classes) stored in memory¹ but that doesn't seem to help. I don't think I'm using any weird code pattern³ as all of the other parts of my app are performant.
Unfortunately I can't easily reproduce the situation of what the screenshot is displaying but when I tried doing it, the payload size was over 1MB and in that scenario I believe it could be over 2MB which is pretty large for JSON.
flutter doctor -v output:
[✓] Flutter (Channel stable, 2.8.1, on macOS 11.6.1 20G224 darwin-x64, locale en-CZ)
• Flutter version 2.8.1 at /Users/user/fvm/versions/2.8.1
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 77d935af4d (6 weeks ago), 2021-12-16 08:37:33 -0800
• Engine revision 890a5fca2e
• Dart version 2.15.1
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/user/Library/Android/sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] IntelliJ IDEA Community Edition (version 2020.2.1)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] VS Code (version 1.58.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (2 available)
• SM A505FN (mobile) • XXXXXXX • android-arm64 • Android 11 (API 30)
• Chrome (web) • chrome • web-javascript • Google Chrome 97.0.4692.99
• No issues found!
¹ I receive list of objects in the JSON response. These objects have nested object lists. One of the lists are GPS coordinates that form a path so there can be lot of them. However I need just one list of coordinates from the list of objects so I just dropped the other ones before converting them to my data structures so it basically cuts down 90% of the previous unoptimized size.
² Version 4.0.0
³ It's a regular Flutter app where all widgets come from material.dart module. The network calls are triggered outside of UI by usage of BLoC pattern (via flutter_bloc lib). Each API call has its own event belonging to some BLoC.
The actual API call is performed by a instance of wrapper class that contains an instance of dio client and passes the result to relevant BLoC. The instances of wrapper classes and dio instances are created via dependency injection. Wrapper classes are singletons, dio instances are created once for each of these wrapper classes. The creation of these classes happens before the runApp.

Related

Flutter geolocator package not retrieving location

I've open an issue on the geolocator repository https://github.com/BaseflowIT/flutter-geolocator/issues/199
It entails the geolocator package not retrieving the location. They recently released a new version 3.0.0 and after that the I have had only aftermath.
I am using the correct dependencies:
dependencies:
geolocator: '^3.0.0'
targetSdkVersion 28 and compileSdkVersion 28
Flutter doctor gives me this:
[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14.3 18D109, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.2)
[✓] IntelliJ IDEA Community Edition (version 2018.2.5)
[✓] Connected device (1 available)
• No issues found!
Once I call await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high); the code just doesn't return anything and I have this output in terminal:
I/DynamiteModule( 4233): Considering local module
com.google.android.gms.maps_dynamite:0 and remote module
com.google.android.gms.maps_dynamite:221 I/DynamiteModule( 4233):
Selected remote version of com.google.android.gms.maps_dynamite,
version >= 221 V/DynamiteModule( 4233): Dynamite loader version >= 2,
using loadModule2NoCrashUtils W/System ( 4233): ClassLoader referenced
unknown path: W/System ( 4233): ClassLoader referenced unknown path:
/data/user_de/0/com.google.android.gms/app_chimera/m/00000030/n/armeabi-v7a
W/System ( 4233): ClassLoader referenced unknown path:
/data/user_de/0/com.google.android.gms/app_chimera/m/00000030/n/armeabi
I/Google Maps Android API( 4233): Google Play services client version:
12451000 I/Google Maps Android API( 4233): Google Play services
package version: 15090018 W/DynamiteModule( 4233): Local module
descriptor class for com.google.android.gms.googlecertificates not
found. I/DynamiteModule( 4233): Considering local module
com.google.android.gms.googlecertificates:0 and remote module
com.google.android.gms.googlecertificates:4 I/DynamiteModule( 4233):
Selected remote version of com.google.android.gms.googlecertificates,
version >= 4 W/System ( 4233): ClassLoader referenced unknown path:
/data/user_de/0/com.google.android.gms/app_chimera/m/0000002f/n/armeabi-v7a
W/System ( 4233): ClassLoader referenced unknown path:
/data/user_de/0/com.goo`gle.android.gms/app_chimera/m/0000002f/n/armeabi
I have spent a considerable amount of time on this. I am new to flutter and know that I may be missing a small thing to make it work.
I was facing the same issue. But my app started running after adding this.
[ Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true; ]
Hope it will work.
Future<void> getCurrentLocation() async {
try {
Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
Position position = await Geolocator().getCurrentPosition(
desiredAccuracy: LocationAccuracy.best,
);
return position;
} catch (err) {
print(err.message);
}
}
All the best.
On iOS you'll need to add the following entries to your Info.plist
file (located under ios/Runner) in order to access the device's
location. Simply open your Info.plist file and add the following:
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs access to location when in the background.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app needs access to location when open and in the background.</string>
I was facing the same issue now it works, I've just added forceAndroidLocationManager: true to the Geolocator.getCurrentPosition.
Position position = await
Geolocator.getCurrentPosition(forceAndroidLocationManager: true,
desiredAccuracy: LocationAccuracy.lowest);
Hey #wagnerdelima had same challenge and l solved by the following :
Change the targetSdkVersion 28 and compileSdkVersion 28 to targetSdkVersion 27 and compileSdkVersion 27 and change to geolocator: '^3.0.0' to geolocator: ^2.1.1 as below:
dependencies:
flutter:
sdk: flutter
geolocator: ^2.1.1
permission_handler: "2.1.2"
google_api_availability: "1.0.4"
This was as a result of the caret ^, it is taking the google_api_availability latest, which is migrated to android x.
All the best !!
I was struggling with this problem for about 2 days. After that, I figured out this (Mac):
In Simulator iOS did not work anyway;
Connect an iOS real device After open iOS module in XCode as follow
Right-click on folder project
Choose Flutter->Open iOS module in XCode
On XCode, Select TAGETS -> Runner
In Signing & Capabilities:
Set the Team
Change the Bundle Identifier to a unique one (ex.:co.test.app456)
Run your app in XCode (it will work)
Close XCode and go back to your project in Flutter
Select the real iOS device and run your app
I had the same issue i.e it was not returning anything but keep fecthing location so i just changed from this
forceAndroidLocationManager: true
to this
forceAndroidLocationManager: false
Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.bestForNavigation,
forceAndroidLocationManager: false)
.then((position) {
print(position);
});
Now its working fine. The problem is in new update because in the old package it was working fine
First things first, check the device you are using and your Flutter version.
i had same issue with only one device that is Google's Nexus 6P and Flutter Version 1.9.1+hotfix.6. The problem is with the package "geolocator" because all other devices are working fine.
I recommend new_geolocation. As it resolved the issue for all devices so far.
Secondly, how i used it, the readme file here didnt help, so went through the example project on Github here, used the same methods of this example for exact results.
I hope it will help.
This solution will work, I was facing issue with Android:
Geolocator geoLocator = Geolocator()..forceAndroidLocationManager = true;
Position position = await geoLocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
print(position);
I had the same problem.
I was able to solve it by:
replacing current API key with new one
clearing out all the minor bugs in file, e.g. writing remaining #override functions, adding 'const' and 'final' keywords etc.
Try these,
it might help.
If you are using the iOS Simulator, you need to set the Location different from None in order the getCurrentPosition method returns the position:
I had this problem until I tried to set the accuracy to low. Then it worked. I believe you may need extra permissions for high accuracy location. It's funny only the low accuracy works for me, none of the others. Also, the forceAndroidLocationManager has to be set to false for it to work on my IOS emulator.
This code worked for me:
Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.low,
forceAndroidLocationManager: false)
.then((currloc) {})

Azure IotHub, UWP, DeviceClient.OpenAsync - timeout

I am trying to connect my UWP app to the Azure IotHub with the code below. I have tried a console app with the same code and it works but not on the UWP app.
I have given all the permissions to the UWP app (internet, and all other after that).
Tried a Get with HttpClient and the internet connection works
I have also tried to use the newest target for the UWP app (Win 10, version 1803)
To connect to the IotHub from my UWP app i am using a nuget package: Microsoft.Azure.Devices.Client v 1.17.1
On the UWP the code stops at await device.OpenAsync() and timeouts after some time
Am i missing something?
The code:
string deviceConnectionString = "<CONNECTION STRING>";
var device = DeviceClient.CreateFromConnectionString(deviceConnectionString);
await device.OpenAsync();
Message bla = new Message(Encoding.ASCII.GetBytes("blablabla"));
await device.SendEventAsync(bla);
UPDATE - FIX
The transport type needs to be defined, guess the default transport type does not work with UWP. When creating the client use this:
var device = DeviceClient.CreateFromConnectionString(deviceConnectionString, TransportType.Amqp_WebSocket_Only);
I have just tested on my RPi3B with your setup such as
compiled for Target version: Win 10, version 1803
Microsoft.Azure.Devices.Client v1.17.1
Microsoft.NETCore.UniversalWindowsPlatform v6.1.7
and the runtime failed (Windows IoT Core 10.0.17723.1000
) with the following error:
Could not load file or assembly 'System.Net.Security, Version=4.0.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
so, the workaround is:
use the Microsoft.Azure.Devices.Client version v1.6.0
after this change my test program Blinky on RPi3B is working.
The latest version client SDK does not work on UWP using AMQP.There is a Github issue#421 here. Please trace this issue. As Roman Kiss mentioned, Microsoft.Azure.Devices.Client version v1.6.0 works fine, you can try to use this version.

Houdini arm to x86 translation "Unsupported feature" error when using shared STL in Android NDK app

I created an Android Studio project from this sample NDK project provided by Google and changed a couple things so I could try to leverage Houdini arm to x86 translation:
In app/build.gradle I set abiFilters to armeabi-v7a.
In Application.mk I changed APP_ABI from all to armeabi-v7a so that x86 native libraries won't be created.
Also in Application.mk, I changed APP_STL from stlport_static to gnustl_shared.
You can see the modified code in this repo.
Then I ran the app in the BlueStacks emulator, which supports Houdini. I get the following error:
11-21 00:42:19.742 9947-9947/? D/houdini: [9947] Loading library(version: 4.0.8.45720 RELEASE)... successfully.
11-21 00:42:19.742 9947-9947/? D/houdini: [9947] Unsupported feature (ID:0x10600cae).
11-21 00:42:19.742 9947-9947/? D/houdini: [9947] Open Native Library /data/app-lib/com.sample.teapot-2/libTeapotNativeActivity.so failed.
...
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sample.teapot/com.sample.teapot.TeapotNativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app-lib/com.sample.teapot-2/libTeapotNativeActivity.so
If I make APP_STL any of the supported values with shared I get this error, and with static it works fine. I'd like to get shared working, to solve this issue in React Native. Does shared STL not work with Houdini? Any workarounds?

Installing of package flight always ends with error 0x87E107D6

I am trying to use the feature "Package flight" for testing my windows phone application. I created a new flight package and also a new flight group. The package flight was passed certification and successfully published in app-store. But when I try to install it from app-store I always get an error (error code 0x87E107D6) and installation fails. During installing there is a text "acquiring license" and then I get the error. The application is free and also when I submit the same package as a regular submission everything works without problem( it is installable), therefore I think there is no problem with the package. I also tried this on 2 different devices with windows mobile 10 and without any success. I also contacted windows support with the problem and although I've been communicating with them for one month but I have not got neither any explanation what is the error code means or how to avoid it. Do you know what could be the reason of the error?
having the same issue... just added a flight package and can't install.Even uninstalling ad reinstalling the app doesn't work. But if I remove my account from the group to receive the flight, I can get the non-flight package without errors.
After upgrading my phone from Windows Phone 8.1 (Nokia Lumia 920) to Windows 10 Mobile (Microsoft Lumia 650 Dual SIM) I am facing error installing my OTR-Master app since there is a conflict with a package flight app vs. published app!
It seems that MS can't imagine that a developer is using his own apps and need an app installed twice (one production version) and one test version (package flight).
Conclusion/Solution:
Can't be a BETA tester + user for my own app + at the same time with that new fabulous "package flight" approach.
Removed my email (Live ID) from the BETA tester list and now I am able to install the published app.
Strange: Still able to use the "packaged flighted" app ...
It was caused by my account "email" address that was in 2 flight groups. I removed it from one and the problem was solved.

MonoDroid:INSTALL_FAILED_OLDER_SDK

Using MonoDroid 4.0.6 and MonoDevelop, any attempt to run in an emulator fails with this error listed below:
The minSdkVersion matches the emulator's SDK version. All AVDs were created by the MonoDroid isntaller.
Detecting package list location
Getting package list from device
Installing shared runtime package on device
1849 KB/s (25866362 bytes in 13.657s)
pkg: /data/local/tmp/Mono.Android.DebugRuntime-debug.apk
Success
Installing the platform framework
1565 KB/s (16530851 bytes in 10.310s)
pkg: /data/local/tmp/Mono.Android.Platform.apk
Failure [INSTALL_FAILED_OLDER_SDK]
Failed to install the platform framework
I solved this in 2 ways.
1) In the manifest the minSdkVersion should match or be lower than the emulator
2) (what tripped me up) The Mono DLLs References of the project should be set to the Android version too.
Both are needed. I come from a Java Android background so never thought to change anything but the manifest.