smaho-engineering / esptouch_flutter

ESP-Touch Dart API for Flutter. Platform-specific implementation for Android (Java) and iOS (Objective-C).
https://pub.dev/packages/esptouch_flutter
MIT License
100 stars 34 forks source link

Java.lang.RuntimeException: An error occurred while executing doInBackground() in Release mode #7

Closed aguilaair closed 4 years ago

aguilaair commented 4 years ago

Hello,

I seem to be having issues when building the app in release mode as when I initiate the task I get the following exception:

E/AndroidRuntime(28329): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(28329): Process: com.wegotech.gategodeploy, PID: 28329
E/AndroidRuntime(28329): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(28329):        at android.os.AsyncTask$4.done(AsyncTask.java:399)
E/AndroidRuntime(28329):        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime(28329):        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime(28329):        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime(28329):        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
E/AndroidRuntime(28329):        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(28329):        at java.lang.Thread.run(Thread.java:919)
E/AndroidRuntime(28329): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.net.DatagramSocket.send(java.net.DatagramPacket)' on a null object reference
E/AndroidRuntime(28329):        at com.espressif.iot.esptouch.udp.UDPSocketClient.sendData(UDPSocketClient.java:100)
E/AndroidRuntime(28329):        at com.espressif.iot.esptouch.udp.UDPSocketClient.sendData(UDPSocketClient.java:71)
E/AndroidRuntime(28329):        at com.espressif.iot.esptouch.task.__EsptouchTask.executeForResults(__EsptouchTask.java:325)
E/AndroidRuntime(28329):        at com.espressif.iot.esptouch.EsptouchTask.executeForResults(EsptouchTask.java:106)
E/AndroidRuntime(28329):        at com.smaho.eng.esptouch.EspTouchTaskUtil$EspTouchAsyncTask.doInBackground(EspTouchTaskUtil.java:75)
E/AndroidRuntime(28329):        at com.smaho.eng.esptouch.EspTouchTaskUtil$EspTouchAsyncTask.doInBackground(EspTouchTaskUtil.java:33)
E/AndroidRuntime(28329):        at android.os.AsyncTask$3.call(AsyncTask.java:378)
E/AndroidRuntime(28329):        at java.util.concurrent.FutureTask.run(FutureTask.java:266)

However when on debug mode the app runs flawlessly. What could be the issue?

aguilaair commented 4 years ago

I've tried different devices and flutter versions, I still have the same issues I'm afraid.

aguilaair commented 4 years ago

Here is the relevant code:

  void handleSuccess(ip, bssid) {
    completed = true;
    Get.to(SuccessPage(ip, bssid));
  }

  void handleFail(sub) async {
    sub.cancel();
    print("cancelled!!!!");
    if (!completed) {
      Get.off(FailPage());
    }
  }

  void espSetup() async {
    print("WiFi: " + wifiName);
    print("BSSID: " + wifiBSSID);
    print("PSK: " + wifiPSK);

    final task = ESPTouchTask(
      ssid: wifiName,
      bssid: wifiBSSID,
      password: wifiPSK,
    );
    stream = task.execute();
    final sub = stream.listen((r) {
      handleSuccess(r.ip, r.bssid);
    });
    Future.delayed(Duration(minutes: 1), () {
      handleFail(sub);
    });
  }

  Stream<ESPTouchResult> stream;
vincevargadev commented 4 years ago

Could you provide us a minimal reproducible example with code and instructions on how to reproduce the issue?

aguilaair commented 4 years ago

I managed to fix the issue at the end, I belive I had to tweak the API version