Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter stuck at 'waiting for observatory port to be available' if Android background services is used

I been trying to get write platform code for Flutter to get a background service started. In here, I used a minimal example with no actual work done to show that the application simply won't run. The actual flutter code is not modified at all.

MainActivity.java

public class MainActivity extends FlutterActivity {

  Intent i = new Intent(this, MainService.class);

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GeneratedPluginRegistrant.registerWith(this);
  }
}

MainService.java

public class MainService extends IntentService {
  public MainService() {
    super("MainService");
  }

  @Override
  protected void onHandleIntent(Intent Intent) {
  }
}

AndroidManifest.xml

 <service android:enabled="true"
android:name=".MainService"></service>

The buildVersion is >27 and Manifest file has the service tag added accordingly.

Compiling and running with flutter run -v will show the following message:

..
[ +121 ms] Starting: Intent { act=android.intent.action.RUN flg=0x20000000 cmp=com.example.hello/.MainActivity (has extras)}
[   +1 ms] Waiting for observatory port to be available...

And the installation is stuck.

Is there a workaround about this? If this is an actual bug in Flutter's implementation, does it also mean there is no way to run a Flutter application in the background?

like image 751
Carrein Avatar asked Dec 18 '18 10:12

Carrein


2 Answers

First, check if the two names are the same:

  • the package name in android/app/src/mainAndroidManifest.xml
  • the package name in android/app/main/kotlin/MainActivity.kt

Then, check that the iOS bundle name is similar to the package name. For example:

  • iOS bundle name: com.example.myAppName
  • Package name: com.example.my_app_name

Finally, check that the name of the Firebase iOS application bundle ID is the same as the iOS bundle name.

In Firebase:

In Xcode:

like image 87
이수미 Avatar answered Sep 18 '22 13:09

이수미


Another potential cause for this issue is the package specified in your MainActivity.kt is in the wrong format, it should also use the same valid Dart package name, e.g.

package com.test.my_app_name

instead of

package com.test.MyAppName

like image 29
David Conlisk Avatar answered Sep 17 '22 13:09

David Conlisk