Closed ch3ckmat3 closed 8 months ago
Can you give me more information about the stacktrace?
What version of flutter are you using?
Are you trying it on an emulator or on a physical device?
I will try to get the stacktrace.
I have tried on a Samsung (v7) and an MI Phone (v8) with same result that it was not detecting network state and was showing offline all the time.
My Flutter version Info: Flutter (Channel master, v1.8.1-pre.22 Dart version 2.5.0 (build 2.5.0-dev.0.0 b5aeaa6796)
Could you try it on stable channel @ch3ckmat3 ?
And did you get the logs?
I will, just switched back to stable for 1.7, will update you as I try the example
My App Is Keep Freezing after I turn On or Off the internet for flutter 1.7 stable release
Going back to a prior Flutter/Dart version is not a practical solution for production apps that must use the more stable and current Flutter/Dart versions. This build issue is still occurring today even on Flutter stable version v1.9.1+hotfix.2 and Dart stable version v2.5.0.
Has there been any progress on resolving the use of the deprecated API? Since the rollout of AndroidX, there have been a lot of issues like this. You may simply need to refer the package to the "Legacy" imports noted in the following link...without having to convert the package to AndroidX:
AndroidX Class Mappings https://developer.android.com/jetpack/androidx/migrate/class-mappings
Sorry for the late answer, I will check on this issue in the following days
The note
from the lint is from the connectivity
package from Google.
This package does not contain any native code for iOS or Android, only its dependencies.
I have updated the example and removed the dependency from Dio.
If you can, please try with version 0.1.2
Thank you
Thanks Vanethos, but the build issue is still occurring even with your new ver. I do apologize for not figuring this out earlier, but the deprecated API issue really is a Google issue in the "Flutter connectivity v0.4.4" package. The Google team has this issue identified as: "https://github.com/flutter/flutter/issues/39842" and they have it scheduled to be part of their December 2019 milestone :(.
No need to apologize @kabnfever ! you got me to look into my app so I thank you for that! :D
Now, let's dive a little deeper.
What is the build issue that you are having, could you paste the log?
Also, can you paste the output of flutter doctor
?
And, finally, what paltform are you trying to build? iOS or Android?
We're receiving the same error as originally reported by ch3ckmat3. We are building for Android devices. We've tried building off of the Flutter stable, master, and dev branches with the same results.
Here's the info you requested:
Build Issue text: Note: C:\flutter.pub-cache\hosted\pub.dartlang.org\connectivity-0.4.4\android\src\main\java\io\flutter\plugins\connectivity\ConnectivityPlugin.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.
Flutter Doctor Results: Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel dev, v1.10.14, on Microsoft Windows [Version 10.0.18362.388], locale en-US) [√] Android toolchain - develop for Android devices (Android SDK version 29.0.0) [√] Android Studio (version 3.5) [√] VS Code, 64-bit edition (version 1.38.1) [√] Connected device (2 available) • No issues found!
Hey @kabnfever
As far as I can see that is a warning and not an error, is there anything else on the logs?
It is a warning when building a debug version of an app. It is an error when building a release version of your app for two reasons:
1) Automated "Release build" scripts will fail on this warning unless you specifically ignore them. 2) When ignoring the warning on Release builds, the Release build of our app which uses the connectivity functionality completely fails and reports our devices as Offline 100% of the time regardless of whether or not you are connected to Wifi, mobile, or both.
We (State of California Dept of Corrections & Rehabilitation) cannot ship a debug version of our app to production pipelines by ISO regulations nor should any business anyway. In addition it is bad practice to use deprecated APIs when current APIs are available which are backwards compatible to legacy code.
As I stated above, Google has already acknowledged this issue as a "real" problem that needs to be corrected in "flutter/flutter#39842" and Google has scheduled the fix to be part of their December 2019 milestone.
As I said before, if I can have your help solving the issue it would be great :)
About the deprecated issue if you cannot wait until December I can try to fork connectivity and fix it. I can't promise anything. Is that okay with you?
Also, do you have more information about the release builds always being offline?
I am using this package in our production app and I do not have this problem. are you using a custom server to ping?
If you are, can you try a release build with logs enabled to see if there is any error being thrown in that case?
And @kabnfever I am sorry for any inconveniences, I will try my best to fix this :)
Im having the same issue
Note: /Users/irperera/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity-0.4.4/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityPlugin.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.
I've been searching in the source code of connectivity
and found out that it's going to be hard to replace the current code.
Basically, the code that they use to monitor the network:
Network network = manager.getActiveNetwork();
NetworkCapabilities capabilities = manager.getNetworkCapabilities(network);
if (capabilities == null) {
return "none";
}
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
|| capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) {
return "wifi";
}
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
return "mobile";
}
can only be used for SDK versions higher than 23
So, they have to use the following for SDK versions lower than it:
private String getNetworkTypeLegacy(ConnectivityManager manager) {
// handle type for Android versions less than Android 9
NetworkInfo info = manager.getActiveNetworkInfo();
if (info == null || !info.isConnected()) {
return "none";
}
int type = info.getType();
switch (type) {
case ConnectivityManager.TYPE_ETHERNET:
case ConnectivityManager.TYPE_WIFI:
case ConnectivityManager.TYPE_WIMAX:
return "wifi";
case ConnectivityManager.TYPE_MOBILE:
case ConnectivityManager.TYPE_MOBILE_DUN:
case ConnectivityManager.TYPE_MOBILE_HIPRI:
return "mobile";
default:
return "none";
}
}
However, this has deprecated methods.
I even tried to bump the version even further but the problem still persists.
So, I'm going to try to see what I can do, but for the time being, either I lock this package for apps higher than SDK 23 or we have the deprecation warning.
Great research @Vanethos...really! I vote for locking the flutter_connectivity_widget package for apps higher than SDK 23 in a new rev (0.1.3) and I'll be your first guinea pig :). Those who require an SDK of 23 or less can use rev (0.1.2 or prior).
Hey @kabnfever ! thanks for the comment :D
What if we do the following:
Is it possible for you to use a package from git in your pubspec?
Something like:
speech_bubble:
git:
url: https://github.com/Vanethos/PHSpeechBubble.git
ref: PHSB-2-4-5
If it is, then I can create a version just for you and others on a separate branch.
Why insisting on creating another branch? Well, me and others that use the library really need to target it to users on 21 to 23.
But, we can reach a consensus! Give me your thoughts on the subject
Hmmm...if it were up to me I'd probably target the current and future SDKs to use the master & feature branches and target the older SDKs to have their own specific branch since they will eventually migrate forward or go away. I guess ultimately it depends on what your consumer base wants, but I'd usually use my master & feature branches for current & future tech...of course they'd be stable branches :).
I'm good whichever way you want to go @Vanethos.
@kabnfever as soon as I can I'll fork the connectivity package and create a version for API > 23!
Sorry for taking so much time!
No apologizes necessary @Vanethos, you have been very responsive and helpful.
So, even more digging into the matter
It seems that there was ANOTHER method deprecated and oh boy will this cause many issues
@Override
public void onListen(Object arguments, EventSink events) {
receiver = createReceiver(events);
registrar
.context()
.registerReceiver(receiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
Basically, as seen here: https://medium.com/ki-labs-engineering/monitoring-wifi-connectivity-status-part-1-c5f4287dd57 in Android N the ability to monitor network connectivity was greatly impaired, so we can do two things:
Either way it's going to be waaay more complicated than I first predicted, so I won't be able to fix this today (and this is why Google has postponed this, for sure)
@kabnfever I have created a branch for you to test and use:
To use it you can:
connectivity_widget:
git:
url: https://github.com/Vanethos/flutter_connectivity_widget.git
ref: feature/custom_connectivity
If you are also using the connectivity
package, you must use this one instead:
connectivity:
git:
url: https://github.com/Vanethos/connectivity_api_23
ref: master
What I had to do:
I created a custom package - connectivity_api_23
that uses a library to check the internet status, instead of the deprecated APIs.
Then, I had to change a bit of the connectivity code and use that custom package into connectivity (fortunately without any code change).
There's a chance that you'll have an android error for not compiling.
If that's the case, then please do the following:
cd android
./gradlew clean
This will clean your gradle folder
Hi @Vanethos, looks like there is still a Dio dependency on the connectivity_widget package whcih is getting in the way of me testing this new branch:
[cdcr_connector_tester] flutter packages get
Running "flutter pub get" in cdcr_connector_tester...
Because cdcr_connector_tester depends on connectivity_widget from git which depends on dio ^2.1.0, dio ^2.1.0 is required.
So, because cdcr_connector_tester depends on dio ^3.0.3, version solving failed.
pub get failed (1)
exit code 1
I forgot to mention to you earlier that I've been getting this "packages get" error when using both the feature/custom_connectivity branch and the public package when simply using the "connectivity_widget: ^0.1.2" reference in the pubspec.yaml file.
@kabnfever updated the branch with the correct changes, I didn't correctly merge things into master
I am getting this error:
the app built successfully, but couldn't render any widgets wrapped by this widget and was getting this error:
Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.