Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e24ebfc

Browse files
committed
Move dart complete into platform_view_android
1 parent b9255eb commit e24ebfc

File tree

4 files changed

+75
-46
lines changed

4 files changed

+75
-46
lines changed

fml/platform/posix/native_library_posix.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ fml::RefPtr<NativeLibrary> NativeLibrary::CreateForCurrentProcess() {
5858
}
5959

6060
const uint8_t* NativeLibrary::ResolveSymbol(const char* symbol) {
61+
FML_LOG(ERROR) << "RESOLVING";
62+
FML_LOG(ERROR) << "RESOLVING: " << (handle_ == nullptr);
6163
auto* resolved_symbol = static_cast<const uint8_t*>(::dlsym(handle_, symbol));
6264
if (resolved_symbol == nullptr) {
6365
FML_DLOG(INFO) << "Could not resolve symbol in library: " << symbol;

shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ public FlutterEngine(
285285

286286
this.localizationPlugin = new LocalizationPlugin(context, localizationChannel);
287287

288-
dynamicFeatureManager = new PlayStoreDynamicFeatureManager(context, flutterJNI);
289288

290289
this.flutterJNI = flutterJNI;
290+
dynamicFeatureManager = new PlayStoreDynamicFeatureManager(context, flutterJNI);
291291
if (flutterLoader == null) {
292292
flutterLoader = FlutterInjector.instance().flutterLoader();
293293
}

shell/platform/android/io/flutter/embedding/engine/dynamicfeatures/PlayStoreDynamicFeatureManager.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
*/
3737
public class PlayStoreDynamicFeatureManager implements DynamicFeatureManager {
3838

39-
private SplitInstallManager splitInstallManager;
40-
private Map<Integer, String> sessionIdToName;
41-
private Map<Integer, Integer> sessionIdToLoadingUnitId;
42-
private FlutterJNI flutterJNI;
43-
private Context context;
39+
private @NonNull SplitInstallManager splitInstallManager;
40+
private @NonNull Map<Integer, String> sessionIdToName;
41+
private @NonNull Map<Integer, Integer> sessionIdToLoadingUnitId;
42+
private @NonNull FlutterJNI flutterJNI;
43+
private @NonNull Context context;
4444

4545
private FeatureInstallStateUpdatedListener listener;
4646

@@ -98,8 +98,9 @@ public void onStateUpdate(SplitInstallSessionState state) {
9898
}
9999
}
100100

101-
public PlayStoreDynamicFeatureManager(Context context, FlutterJNI flutterJNI) {
101+
public PlayStoreDynamicFeatureManager(@NonNull Context context, @NonNull FlutterJNI flutterJNI) {
102102
this.context = context;
103+
this.flutterJNI = flutterJNI;
103104
splitInstallManager = SplitInstallManagerFactory.create(context);
104105
listener = new FeatureInstallStateUpdatedListener();
105106
splitInstallManager.registerListener(listener);
@@ -108,7 +109,7 @@ public PlayStoreDynamicFeatureManager(Context context, FlutterJNI flutterJNI) {
108109
}
109110

110111
public void downloadModule(@NonNull String moduleName, int loadingUnitId) {
111-
Log.e("flutter", "INSTALLING MODULE " + moduleName);
112+
Log.e("flutter", "INSTALLING MODULE " + moduleName + " " + flutterJNI);
112113
if (splitInstallManager.getInstalledModules().contains(moduleName)) {
113114
loadDartModules(moduleName, loadingUnitId);
114115
return;
@@ -153,7 +154,7 @@ public void downloadModule(@NonNull String moduleName, int loadingUnitId) {
153154
}
154155

155156
public void extractModule(@NonNull String moduleName, int loadingUnitId) {
156-
Log.e("flutter", "Extracting \"" + moduleName + "\"");
157+
Log.e("flutter", "Extracting \"" + moduleName + "\" " + flutterJNI);
157158

158159
try {
159160
context = context.createPackageContext(context.getPackageName(), 0);
@@ -169,14 +170,14 @@ public void extractModule(@NonNull String moduleName, int loadingUnitId) {
169170
}
170171

171172
public void loadDartModules(@NonNull String moduleName, int loadingUnitId) {
172-
Log.e("flutter", "Loading dart modules \"" + moduleName + "\"");
173-
SplitInstallHelper.loadLibrary(context, "app.so-2.part");
173+
Log.e("flutter", "Loading dart modules \"" + moduleName + "\" " + flutterJNI);
174+
// SplitInstallHelper.loadLibrary(context, "app.so-2.part");
174175
ApplicationInfo appInfo = getApplicationInfo(context);
175176
// Prior to API 23, cleartext traffic is allowed.
176-
boolean clearTextPermitted = true;
177-
if (android.os.Build.VERSION.SDK_INT >= 23) {
178-
clearTextPermitted = NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted();
179-
}
177+
// boolean clearTextPermitted = true;
178+
// if (android.os.Build.VERSION.SDK_INT >= 23) {
179+
// clearTextPermitted = NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted();
180+
// }
180181

181182
String aotSharedLibraryName = "app.so-" + loadingUnitId + ".part.so";
182183
String nativeLibraryDir = appInfo.nativeLibraryDir;
@@ -197,6 +198,8 @@ public void loadDartModules(@NonNull String moduleName, int loadingUnitId) {
197198
// final boolean clearTextPermitted;
198199
AssetManager assetManager = context.getAssets();
199200

201+
Log.e("flutter", "FLUTTER JNI var: " + flutterJNI + " " + (flutterJNI == null));
202+
200203
// find one or more .so file and initiate callbacks from https://github.com/flutter/flutter/issues/62229
201204
flutterJNI.loadDartLibrary(loadingUnitId, nativeLibraryDir, aotSharedLibraryName, assetManager);
202205
}

shell/platform/android/platform_view_android.cc

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#include <utility>
99

1010
#include "flutter/fml/command_line.h"
11+
#include "flutter/fml/native_library.h"
1112
#include "flutter/fml/synchronization/waitable_event.h"
13+
#include "flutter/runtime/dart_snapshot.h"
1214
#include "flutter/shell/common/shell_io_manager.h"
1315
#include "flutter/shell/common/switches.h"
1416
#include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
@@ -335,38 +337,60 @@ Dart_Handle PlatformViewAndroid::OnDartLoadLibrary(intptr_t loading_unit_id) {
335337
Dart_Handle PlatformViewAndroid::CompleteDartLoadLibrary(
336338
intptr_t loading_unit_id,
337339
std::string lib_name) {
338-
std::vector<std::string> args;
339-
args.push_back("flutter");
340-
args.push_back("--aot-shared-library-name=" + lib_name);
341-
// args.push_back("--" + "aot-shared-library-name" + "=" +
342-
// fml::jni::JavaStringToString(env, jLibPath));
343-
// shellArgs.add(
344-
// "--" + AOT_SHARED_LIBRARY_NAME + "=" +
345-
// flutterApplicationInfo.aotSharedLibraryName);
346-
347-
// // Most devices can load the AOT shared library based on the library name
348-
// // with no directory path. Provide a fully qualified path to the library
349-
// // as a workaround for devices where that fails.
350-
// shellArgs.add(
351-
// "--"
352-
// + AOT_SHARED_LIBRARY_NAME
353-
// + "="
354-
// + flutterApplicationInfo.nativeLibraryDir
355-
// + File.separator
356-
// + flutterApplicationInfo.aotSharedLibraryName);
357-
auto command_line = fml::CommandLineFromIterators(args.begin(), args.end());
358-
359-
auto settings = SettingsFromCommandLine(command_line);
360-
361-
fml::RefPtr<DartSnapshot> isolateSnapshot =
362-
DartSnapshot::IsolateSnapshotFromSettings(settings);
363-
364-
// ANDROID_SHELL_HOLDER->Launch(std::move(config));
365-
366-
Dart_Handle result = Dart_DeferredLoadComplete(
367-
loading_unit_id, isolateSnapshot->GetDataMapping(),
368-
isolateSnapshot->GetInstructionsMapping());
340+
FML_LOG(ERROR) << "COMPLETING";
341+
fml::RefPtr<fml::NativeLibrary> native_lib =
342+
fml::NativeLibrary::Create(lib_name.c_str());
343+
const uint8_t* isolate_data =
344+
native_lib->ResolveSymbol(DartSnapshot::kIsolateDataSymbol);
345+
FML_LOG(ERROR) << "COMPLETING " << isolate_data;
346+
const uint8_t* isolate_instructions =
347+
native_lib->ResolveSymbol(DartSnapshot::kIsolateInstructionsSymbol);
348+
FML_LOG(ERROR) << "COMPLETING " << isolate_instructions;
349+
350+
Dart_Handle result = Dart_DeferredLoadComplete(loading_unit_id, isolate_data,
351+
isolate_instructions);
352+
FML_LOG(ERROR) << "COMPLETING " << result;
369353
return result;
354+
355+
// std::vector<std::string> args;
356+
// args.push_back("flutter");
357+
// args.push_back("--aot-shared-library-name=" + lib_name);
358+
// // args.push_back("--" + "aot-shared-library-name" + "=" +
359+
// // fml::jni::JavaStringToString(env, jLibPath));
360+
// // shellArgs.add(
361+
// // "--" + AOT_SHARED_LIBRARY_NAME + "=" +
362+
// // flutterApplicationInfo.aotSharedLibraryName);
363+
364+
// // // Most devices can load the AOT shared library based on the library
365+
// name
366+
// // // with no directory path. Provide a fully qualified path to the
367+
// library
368+
// // // as a workaround for devices where that fails.
369+
// // shellArgs.add(
370+
// // "--"
371+
// // + AOT_SHARED_LIBRARY_NAME
372+
// // + "="
373+
// // + flutterApplicationInfo.nativeLibraryDir
374+
// // + File.separator
375+
// // + flutterApplicationInfo.aotSharedLibraryName);
376+
// auto command_line = fml::CommandLineFromIterators(args.begin(),
377+
// args.end());
378+
379+
// auto settings = SettingsFromCommandLine(command_line);
380+
381+
// for (std::string str : settings.application_library_path) {
382+
// FML_LOG(ERROR) << "LIBNAME: " << str;
383+
// }
384+
385+
// fml::RefPtr<DartSnapshot> isolateSnapshot =
386+
// DartSnapshot::IsolateSnapshotFromSettings(settings);
387+
388+
// // ANDROID_SHELL_HOLDER->Launch(std::move(config));
389+
390+
// Dart_Handle result = Dart_DeferredLoadComplete(
391+
// loading_unit_id, isolateSnapshot->GetDataMapping(),
392+
// isolateSnapshot->GetInstructionsMapping());
393+
// return result;
370394
}
371395

372396
void PlatformViewAndroid::InstallFirstFrameCallback() {

0 commit comments

Comments
 (0)