Backendless application was not initialized

Sometimes the app build failed and this error occurs.(This error doesn’t occur every time)

java.lang.ExceptionInInitializerError
E/AndroidRuntime( 1311): 	at com.backendless.HeadersManager.getInstance(HeadersManager.java:38)
E/AndroidRuntime( 1311): 	at com.backendless.Invoker.invokeSync(Invoker.java:95)
E/AndroidRuntime( 1311): 	at com.backendless.Invoker$1.run(Invoker.java:71)
E/AndroidRuntime( 1311): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime( 1311): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime( 1311): 	at java.lang.Thread.run(Thread.java:923)
E/AndroidRuntime( 1311): Caused by: java.lang.IllegalStateException: Backendless application was not initialized
E/AndroidRuntime( 1311): 	at com.backendless.AndroidBackendlessPrefs.getAuthKeys(AndroidBackendlessPrefs.java:119)
E/AndroidRuntime( 1311): 	at com.backendless.AndroidBackendlessPrefs.getApplicationId(AndroidBackendlessPrefs.java:50)
E/AndroidRuntime( 1311): 	at com.backendless.Backendless.getApplicationId(Backendless.java:277)
E/AndroidRuntime( 1311): 	at com.backendless.AndroidHeadersManager.<init>(AndroidHeadersManager.java:34)
E/AndroidRuntime( 1311): 	at com.backendless.AndroidHeadersManager.getInstance(AndroidHeadersManager.java:22)
E/AndroidRuntime( 1311): 	at com.backendless.HeadersManager.<clinit>(HeadersManager.java:28)
E/AndroidRuntime( 1311): 	... 6 more

Initialize backendless:

static Future<void> initBackendless() async {
String APPLICATION_ID = "<APPLICATION_ID>";
String ANDROID_API_KEY = "<ANDROID_API_KEY>";
String IOS_API_KEY = "<IOS_API_KEY>";

await Backendless.initApp(APPLICATION_ID, ANDROID_API_KEY, IOS_API_KEY);
host = "https://api.backendless.com/" +
    await Backendless.getApplicationId() +
    "/" +
    await Backendless.getApiKey() +
    "/services";
print(host);

}
in main:

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

await Request.initBackendless();
runApp(MyApp());
}

Hi @adel_kasno

I would recommend you to move the Backendless initialization code after runApp() call. Otherwise it can sometimes produce unexpected behaviour.
For example, you can init Backendless inside your Home Page State.

I’ve also created internal ticket BKNDLSS-24155 to improve the initialization logic and avoid the error you have faced.

Best Regards,
Maksym

Hi @adel_kasno

The issue has been resolved. Please check new Flutter SDK release v.6.3.0.

Best Regards,
Maksym