Blocks until initialization of the native system has completed.
Calling this method multiple times has no effect.
246 {
247 if (initialized) {
248 return;
249 }
250 if (Looper.myLooper() != Looper.getMainLooper()) {
251 throw new IllegalStateException(
252 "ensureInitializationComplete must be called on the main thread");
253 }
254 if (settings == null) {
255 throw new IllegalStateException(
256 "ensureInitializationComplete must be called after startInitialization");
257 }
258
259 try (TraceSection
e = TraceSection.scoped(
"FlutterLoader#ensureInitializationComplete")) {
261
263 shellArgs.
add(
"--icu-symbol-prefix=_binary_icudtl_dat");
264
266 "--icu-native-lib-path="
268 + File.separator
269 + DEFAULT_LIBRARY);
271 Collections.addAll(shellArgs,
args);
272 }
273
274 String kernelPath = null;
275 if (BuildConfig.DEBUG || BuildConfig.JIT_RELEASE) {
276 String snapshotAssetPath =
277 result.dataDirPath + File.separator + flutterApplicationInfo.
flutterAssetsDir;
278 kernelPath = snapshotAssetPath + File.separator + DEFAULT_KERNEL_BLOB;
283 } else {
286
287
288
289
291 "--"
293 + "="
295 + File.separator
297
298
299
300 if (BuildConfig.PROFILE) {
303 }
304 }
305
306 shellArgs.
add(
"--cache-dir-path=" +
result.engineCachesPath);
309 }
312 }
313
314 ApplicationInfo applicationInfo =
315 applicationContext
316 .getPackageManager()
317 .getApplicationInfo(
318 applicationContext.getPackageName(), PackageManager.GET_META_DATA);
319 Bundle metaData = applicationInfo.metaData;
320 int oldGenHeapSizeMegaBytes =
321 metaData != null ? metaData.getInt(OLD_GEN_HEAP_SIZE_META_DATA_KEY) : 0;
322 if (oldGenHeapSizeMegaBytes == 0) {
323
324 ActivityManager activityManager =
325 (ActivityManager) applicationContext.getSystemService(Context.ACTIVITY_SERVICE);
326 ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
327 activityManager.getMemoryInfo(memInfo);
328 oldGenHeapSizeMegaBytes = (
int) (memInfo.totalMem / 1e6 / 2);
329 }
330 shellArgs.
add(
"--old-gen-heap-size=" + oldGenHeapSizeMegaBytes);
331
332 DisplayMetrics displayMetrics = applicationContext.getResources().getDisplayMetrics();
333 int screenWidth = displayMetrics.widthPixels;
334 int screenHeight = displayMetrics.heightPixels;
335
336
337 int resourceCacheMaxBytesThreshold = screenWidth * screenHeight * 12 * 4;
338 shellArgs.
add(
"--resource-cache-max-bytes-threshold=" + resourceCacheMaxBytesThreshold);
339
340 shellArgs.
add(
"--prefetched-default-font-manager");
341
342 if (metaData != null) {
343 if (metaData.getBoolean(ENABLE_IMPELLER_META_DATA_KEY, false)) {
344 shellArgs.
add(
"--enable-impeller");
345 }
346 if (metaData.getBoolean(ENABLE_VULKAN_VALIDATION_META_DATA_KEY, false)) {
347 shellArgs.
add(
"--enable-vulkan-validation");
348 }
349 if (metaData.getBoolean(IMPELLER_OPENGL_GPU_TRACING_DATA_KEY, false)) {
350 shellArgs.
add(
"--enable-opengl-gpu-tracing");
351 }
352 if (metaData.getBoolean(IMPELLER_VULKAN_GPU_TRACING_DATA_KEY, false)) {
353 shellArgs.
add(
"--enable-vulkan-gpu-tracing");
354 }
355 String
backend = metaData.getString(IMPELLER_BACKEND_META_DATA_KEY);
357 shellArgs.
add(
"--impeller-backend=" +
backend);
358 }
359 }
360
361 final String leakVM = isLeakVM(metaData) ? "true" : "false";
362 shellArgs.
add(
"--leak-vm=" + leakVM);
363
364 long initTimeMillis = SystemClock.uptimeMillis() - initStartTimestampMillis;
365
367 applicationContext,
368 shellArgs.toArray(new String[0]),
369 kernelPath,
372 initTimeMillis);
373
374 initialized = true;
375 }
catch (Exception
e) {
376 Log.e(TAG,
"Flutter initialization failed.",
e);
377 throw new RuntimeException(
e);
378 }
379 }
void add(sk_sp< SkIDChangeListener > listener) SK_EXCLUDES(fMutex)
void init( @NonNull Context context, @NonNull String[] args, @Nullable String bundlePath, @NonNull String appStoragePath, @NonNull String engineCachesPath, long initTimeMillis)
final String flutterAssetsDir
final String isolateSnapshotData
final String domainNetworkPolicy
final String nativeLibraryDir
final String vmSnapshotData
final String aotSharedLibraryName
static final String VM_SNAPSHOT_DATA_KEY
static final String ISOLATE_SNAPSHOT_DATA_KEY
static final String AOT_SHARED_LIBRARY_NAME
static final String AOT_VMSERVICE_SHARED_LIBRARY_NAME
static final String SNAPSHOT_ASSET_PATH_KEY
Future< InitResult > initResultFuture
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
void Log(const char *format,...) SK_PRINTF_LIKE(1