From 9f1a91cc9277f3ab95097c9e82cf4714ddfef463 Mon Sep 17 00:00:00 2001 From: blagoev Date: Wed, 7 Jun 2023 21:47:07 +0300 Subject: [PATCH 01/13] initial sync conn bundle_id --- .vscode/settings.json | 5 +- example/pubspec.yaml | 2 +- .../example/windows/runner/Runner.rc | 10 ++-- flutter/realm_flutter/linux/CMakeLists.txt | 12 ++++- .../linux/include/realm/realm_plugin.h | 2 + flutter/realm_flutter/linux/realm_plugin.cpp | 9 ++++ flutter/realm_flutter/tests/pubspec.yaml | 2 +- flutter/realm_flutter/windows/CMakeLists.txt | 10 ++-- .../windows/include/realm/realm_plugin.h | 2 + .../realm_flutter/windows/realm_plugin.cpp | 10 ++++ lib/src/cli/metrics/metrics_command.dart | 53 ++++++++++++------- lib/src/native/realm_core.dart | 35 ++++++++---- 12 files changed, 110 insertions(+), 42 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 67475ed48..533ea4df1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -146,6 +146,9 @@ "string_view": "cpp", "rope": "cpp", "slist": "cpp", - "__mutex_base": "cpp" + "__mutex_base": "cpp", + "coroutine": "cpp", + "ranges": "cpp", + "span": "cpp" } } \ No newline at end of file diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 2fd8cfeca..02c699f88 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,4 +1,4 @@ -name: myapp +name: realm_dart_example description: A simple command-line application using Realm Dart SDK. publish_to: none diff --git a/flutter/realm_flutter/example/windows/runner/Runner.rc b/flutter/realm_flutter/example/windows/runner/Runner.rc index b63ecadc7..0319e46bb 100644 --- a/flutter/realm_flutter/example/windows/runner/Runner.rc +++ b/flutter/realm_flutter/example/windows/runner/Runner.rc @@ -60,14 +60,14 @@ IDI_APP_ICON ICON "resources\\app_icon.ico" // Version // -#ifdef FLUTTER_BUILD_NUMBER -#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER +#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) +#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD #else -#define VERSION_AS_NUMBER 1,0,0 +#define VERSION_AS_NUMBER 1,0,0,0 #endif -#ifdef FLUTTER_BUILD_NAME -#define VERSION_AS_STRING #FLUTTER_BUILD_NAME +#if defined(FLUTTER_VERSION) +#define VERSION_AS_STRING FLUTTER_VERSION #else #define VERSION_AS_STRING "1.0.0" #endif diff --git a/flutter/realm_flutter/linux/CMakeLists.txt b/flutter/realm_flutter/linux/CMakeLists.txt index 97d609005..9f18bb6d0 100644 --- a/flutter/realm_flutter/linux/CMakeLists.txt +++ b/flutter/realm_flutter/linux/CMakeLists.txt @@ -29,11 +29,21 @@ set(realm_bundled_libraries add_definitions(-DAPP_DIR_NAME="${APPLICATION_ID}") - # This works cause realm plugin is always accessed through the .plugin_symlinks directory. set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../ephemeral") include(${EPHEMERAL_DIR}/generated_config.cmake) +set(APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../..") +# message ("APP_DIR is ${APP_DIR}") +set(APP_PUBSPEC_FILE "${APP_DIR}/pubspec.yaml") +# message ("APP_PUBSPEC_FILE is ${APP_PUBSPEC_FILE}") +file(READ "${APP_PUBSPEC_FILE}" PUBSPEC_CONTENT) +string(REGEX MATCH "name:[ \r\n\t]*([a-z0-9_]*)" _ ${PUBSPEC_CONTENT}) +# message ("Pubspec name 0 is ${CMAKE_MATCH_0}") +# message ("Package name is ${CMAKE_MATCH_1}") +set(BUNDLE_ID ${CMAKE_MATCH_1}) + + # message ("FLUTTER_TOOL_ENVIRONMENT is ${FLUTTER_TOOL_ENVIRONMENT}") # message ("FLUTTER_ROOT is ${FLUTTER_ROOT}") diff --git a/flutter/realm_flutter/linux/include/realm/realm_plugin.h b/flutter/realm_flutter/linux/include/realm/realm_plugin.h index f6661135b..2689f003b 100644 --- a/flutter/realm_flutter/linux/include/realm/realm_plugin.h +++ b/flutter/realm_flutter/linux/include/realm/realm_plugin.h @@ -23,6 +23,8 @@ FLUTTER_PLUGIN_EXPORT void realm_plugin_register_with_registrar( FLUTTER_PLUGIN_EXPORT const char* realm_dart_get_app_directory(); +FLUTTER_PLUGIN_EXPORT const char* realm_dart_get_bundle_id(); + G_END_DECLS #endif // FLUTTER_PLUGIN_REALM_PLUGIN_H_ diff --git a/flutter/realm_flutter/linux/realm_plugin.cpp b/flutter/realm_flutter/linux/realm_plugin.cpp index 4843fe19f..84a873890 100644 --- a/flutter/realm_flutter/linux/realm_plugin.cpp +++ b/flutter/realm_flutter/linux/realm_plugin.cpp @@ -12,6 +12,10 @@ #define APP_DIR_NAME "realm_app" #endif +#ifndef BUNDLE_ID +#define BUNDLE_ID "realm_bundle_id" +#endif + #define REALM_PLUGIN(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj), realm_plugin_get_type(), \ RealmPlugin)) @@ -66,7 +70,12 @@ void realm_plugin_register_with_registrar(FlPluginRegistrar* registrar) { } static std::string appDirName = APP_DIR_NAME; +static std::string bundleId = BUNDLE_ID; const char* realm_dart_get_app_directory() { return appDirName.c_str(); } + +const char* realm_dart_get_bundle_id() { + return bundleId.c_str(); +} diff --git a/flutter/realm_flutter/tests/pubspec.yaml b/flutter/realm_flutter/tests/pubspec.yaml index 77e2b5ea2..f2a7c93d4 100644 --- a/flutter/realm_flutter/tests/pubspec.yaml +++ b/flutter/realm_flutter/tests/pubspec.yaml @@ -1,4 +1,4 @@ -name: tests +name: realm_tests description: A new Flutter project. publish_to: "none" diff --git a/flutter/realm_flutter/windows/CMakeLists.txt b/flutter/realm_flutter/windows/CMakeLists.txt index 64e04f3f0..1150445e6 100644 --- a/flutter/realm_flutter/windows/CMakeLists.txt +++ b/flutter/realm_flutter/windows/CMakeLists.txt @@ -28,21 +28,25 @@ set(realm_bundled_libraries # For example the tests app refers to the realm plugin using this path .../realm-dart/flutter/realm_flutter/tests/windows/flutter/ephemeral/.plugin_symlinks/realm/windows set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../ephemeral") include(${EPHEMERAL_DIR}/generated_config.cmake) + set(APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../..") # message ("APP_DIR is ${APP_DIR}") set(APP_PUBSPEC_FILE "${APP_DIR}/pubspec.yaml") # message ("APP_PUBSPEC_FILE is ${APP_PUBSPEC_FILE}") - file(READ "${APP_PUBSPEC_FILE}" PUBSPEC_CONTENT) -# name:\\s*([a-z0-9_]+) -# message ("${PUBSPEC_CONTENT}") string(REGEX MATCH "name:[ \r\n\t]*([a-z0-9_]*)" _ ${PUBSPEC_CONTENT}) # message ("Pubspec name 0 is ${CMAKE_MATCH_0}") # message ("Package name is ${CMAKE_MATCH_1}") set(APP_DIR_NAME ${CMAKE_MATCH_1}) +set(BUNDLE_ID ${CMAKE_MATCH_1}) +# string(ASCII 114, 101, 97, 108, 109, 32, 105, 115, 32, 103, 114, 101, 97, 116 PREFIX) +# string(PREPEND BUNDLE_ID ${PREFIX}) +# message ("BUNDLE_ID is ${BUNDLE_ID}") +# string(SHA256 ) #message ("BINARY_NAME is ${BINARY_NAME}") add_definitions(-DAPP_DIR_NAME="${APP_DIR_NAME}") +add_definitions(-DBUNDLE_ID="${BUNDLE_ID}") # message ("FLUTTER_TOOL_ENVIRONMENT is ${FLUTTER_TOOL_ENVIRONMENT}") diff --git a/flutter/realm_flutter/windows/include/realm/realm_plugin.h b/flutter/realm_flutter/windows/include/realm/realm_plugin.h index 4342f4c82..f9485cf2a 100644 --- a/flutter/realm_flutter/windows/include/realm/realm_plugin.h +++ b/flutter/realm_flutter/windows/include/realm/realm_plugin.h @@ -18,6 +18,8 @@ FLUTTER_PLUGIN_EXPORT void RealmPluginRegisterWithRegistrar( FLUTTER_PLUGIN_EXPORT const wchar_t* realm_dart_get_app_directory(); +FLUTTER_PLUGIN_EXPORT const char* realm_dart_get_bundle_id(); + #if defined(__cplusplus) } // extern "C" #endif diff --git a/flutter/realm_flutter/windows/realm_plugin.cpp b/flutter/realm_flutter/windows/realm_plugin.cpp index 3f597dce8..575f263af 100644 --- a/flutter/realm_flutter/windows/realm_plugin.cpp +++ b/flutter/realm_flutter/windows/realm_plugin.cpp @@ -20,6 +20,11 @@ #define APP_DIR_NAME "realm_app" #endif +#ifndef BUNDLE_ID +#define BUNDLE_ID "realm_bundle_id" +#endif + + // #pragma message("APP_DIR_NAME is " _CRT_STRINGIZE(APP_DIR_NAME)) namespace @@ -77,6 +82,7 @@ void RealmPluginRegisterWithRegistrar( } static std::wstring appDirName; +static std::string bundleId = BUNDLE_ID; // Returns the app directory on the current machine or null if getting the default directory fails // On Windows this is the C:\Users\username\AppData\Roaming\app_name directory @@ -99,4 +105,8 @@ const wchar_t* realm_dart_get_app_directory() { CoTaskMemFree(ppszPath); return appDirName.c_str(); +} + +const char* realm_dart_get_bundle_id() { + return bundleId.c_str(); } \ No newline at end of file diff --git a/lib/src/cli/metrics/metrics_command.dart b/lib/src/cli/metrics/metrics_command.dart index adc9b7ba0..a474f0579 100644 --- a/lib/src/cli/metrics/metrics_command.dart +++ b/lib/src/cli/metrics/metrics_command.dart @@ -35,7 +35,6 @@ import '../common/utils.dart'; const realmCoreVersion = '13.12.0'; class MetricsCommand extends Command { - @override final String description = 'Report anonymized builder metrics to Realm'; @@ -57,12 +56,27 @@ class MetricsCommand extends Command { Future uploadMetrics(Options options) async { final pubspecPath = options.pubspecPath; - final pubspec = Pubspec.parse(await File(pubspecPath).readAsString()); + final pubspecFile = File(pubspecPath); + + if (!pubspecFile.existsSync()) { + // Curently the pubspec file is a hard requirement for metrics to work. Skip metrics run if the file does not exists at the expected location. + // TODO: remove the pubspec file hard requirement and allow metrics to run with the neededdata gathered by other means. + // https://jira.mongodb.org/browse/RDART-815 + return; + } + + final pubspec = Pubspec.parse(await pubspecFile.readAsString()); hierarchicalLoggingEnabled = true; log.level = options.verbose ? Level.INFO : Level.WARNING; - var skipUpload = (isRealmCI || Platform.environment['CI'] != null || Platform.environment['REALM_DISABLE_ANALYTICS'] != null) && + var skipUpload = (isRealmCI || + Platform.environment['CI'] != null || + Platform.environment['REALM_DISABLE_ANALYTICS'] != null || + pubspec.name == "realm_tests" || + pubspec.name == "realm_example" || + pubspec.name == "realm_dart_example" || + pubspec.name == "realm_generator") && Platform.environment['REALM_DEBUG_ANALYTICS'] == null; if (skipUpload) { // skip early and don't do any work @@ -95,23 +109,22 @@ Future uploadMetrics(Options options) async { final realmVersion = realmDep is HostedDependency ? '${realmDep.version}' : '?'; final metrics = await generateMetrics( - distinctId: distinctId, - builderId: builderId, - targetOsType: options.targetOsType, - targetOsVersion: options.targetOsVersion, - anonymizedMacAddress: distinctId, - anonymizedBundleId: pubspec.name.strongHash(), - framework: frameworkName ?? "Unknown", - frameworkVersion: flutterInfo != null - ? [ - '${flutterInfo.frameworkVersion}', - if (flutterInfo.channel != null) '(${flutterInfo.channel})', // to mimic Platform.version - if (flutterInfo.frameworkCommitDate != null) '(${flutterInfo.frameworkCommitDate})', // -"- - ].join(' ') - : Platform.version, - realmVersion: realmVersion, - realmCoreVersion: realmCoreVersion - ); + distinctId: distinctId, + builderId: builderId, + targetOsType: options.targetOsType, + targetOsVersion: options.targetOsVersion, + anonymizedMacAddress: distinctId, + anonymizedBundleId: pubspec.name.strongHash(), + framework: frameworkName ?? "Unknown", + frameworkVersion: flutterInfo != null + ? [ + '${flutterInfo.frameworkVersion}', + if (flutterInfo.channel != null) '(${flutterInfo.channel})', // to mimic Platform.version + if (flutterInfo.frameworkCommitDate != null) '(${flutterInfo.frameworkCommitDate})', // -"- + ].join(' ') + : Platform.version, + realmVersion: realmVersion, + realmCoreVersion: realmCoreVersion); const encoder = JsonEncoder.withIndent(' '); final payload = encoder.convert(metrics.toJson()); diff --git a/lib/src/native/realm_core.dart b/lib/src/native/realm_core.dart index 454759b2b..313a8794c 100644 --- a/lib/src/native/realm_core.dart +++ b/lib/src/native/realm_core.dart @@ -64,6 +64,23 @@ final _realmLib = () { return result; }(); +final _pluginLib = () { + if (!isFlutterPlatform) { + throw UnsupportedError("Realm plugin library used outside Flutter"); + } + + String plugin = Platform.isWindows + ? 'realm_plugin.dll' + : Platform.isMacOS + ? 'realm.framework/realm' // use catalyst + : Platform.isLinux + ? "librealm_plugin.so" + : throw UnsupportedError("Platform ${Platform.operatingSystem} is not supported"); + + final pluginLib = DynamicLibrary.open(plugin); + return pluginLib; +}(); + // stamped into the library by the build system (see prepare-release.yml) const libraryVersion = '1.1.0'; @@ -2242,19 +2259,17 @@ class _RealmCore { } } - String _getAppDirectoryFromPlugin() { + String _getBundleId() { assert(isFlutterPlatform); + final getBundleIdFunc = _pluginLib.lookupFunction Function(), Pointer Function()>("realm_dart_get_bundle_id"); + final bundleIdPtr = getBundleIdFunc(); + return bundleIdPtr.cast().toDartString(); + } - String plugin = Platform.isWindows - ? 'realm_plugin.dll' - : Platform.isMacOS - ? 'realm.framework/realm' // use catalyst - : Platform.isLinux - ? "librealm_plugin.so" - : throw UnsupportedError("Platform ${Platform.operatingSystem} is not supported"); + String _getAppDirectoryFromPlugin() { + assert(isFlutterPlatform); - final pluginLib = DynamicLibrary.open(plugin); - final getAppDirFunc = pluginLib.lookupFunction Function(), Pointer Function()>("realm_dart_get_app_directory"); + final getAppDirFunc = _pluginLib.lookupFunction Function(), Pointer Function()>("realm_dart_get_app_directory"); final dirNamePtr = getAppDirFunc(); final dirName = Platform.isWindows ? dirNamePtr.cast().toDartString() : dirNamePtr.cast().toDartString(); From 94be95c78ecd710e32846296186c33cf42fbbee9 Mon Sep 17 00:00:00 2001 From: blagoev Date: Wed, 7 Jun 2023 23:32:13 +0300 Subject: [PATCH 02/13] fix linux cmake --- flutter/realm_flutter/linux/CMakeLists.txt | 4 +++- flutter/realm_flutter/macos/Classes/platform.mm | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/flutter/realm_flutter/linux/CMakeLists.txt b/flutter/realm_flutter/linux/CMakeLists.txt index 9f18bb6d0..46f485099 100644 --- a/flutter/realm_flutter/linux/CMakeLists.txt +++ b/flutter/realm_flutter/linux/CMakeLists.txt @@ -37,7 +37,9 @@ set(APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../..") # message ("APP_DIR is ${APP_DIR}") set(APP_PUBSPEC_FILE "${APP_DIR}/pubspec.yaml") # message ("APP_PUBSPEC_FILE is ${APP_PUBSPEC_FILE}") -file(READ "${APP_PUBSPEC_FILE}" PUBSPEC_CONTENT) +file(REAL_PATH ${APP_PUBSPEC_FILE} ABSOLUTE_PATH_APP_PUBSPEC_FILE) +# message ("ABSOLUTE_PATH_APP_PUBSPEC_FILE is ${ABSOLUTE_PATH_APP_PUBSPEC_FILE}") +file(READ "${ABSOLUTE_PATH_APP_PUBSPEC_FILE}" PUBSPEC_CONTENT) string(REGEX MATCH "name:[ \r\n\t]*([a-z0-9_]*)" _ ${PUBSPEC_CONTENT}) # message ("Pubspec name 0 is ${CMAKE_MATCH_0}") # message ("Package name is ${CMAKE_MATCH_1}") diff --git a/flutter/realm_flutter/macos/Classes/platform.mm b/flutter/realm_flutter/macos/Classes/platform.mm index e5de6e15d..e3b4eddd1 100644 --- a/flutter/realm_flutter/macos/Classes/platform.mm +++ b/flutter/realm_flutter/macos/Classes/platform.mm @@ -29,4 +29,15 @@ filesDir = ss.str(); return filesDir.c_str(); +} + +std::string app_bundle_id() +{ + std::string ret; + std::string bundle; + @autoreleasepool { + NSString *path = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES)[0]; + ret = path.UTF8String; + return ret; + } } \ No newline at end of file From d80dd91b802bf57732584e1aa2be2c9a495841ae Mon Sep 17 00:00:00 2001 From: blagoev Date: Thu, 8 Jun 2023 22:27:00 +0300 Subject: [PATCH 03/13] add bundleid to ios and macos --- flutter/realm_flutter/ios/Classes/platform.mm | 15 +++++++++++ .../realm_flutter/ios/Classes/realm_plugin.h | 10 +++++++ flutter/realm_flutter/ios/realm.podspec | 15 ++++++++--- .../realm_flutter/macos/Classes/platform.mm | 26 ++++++++++++------- flutter/realm_flutter/macos/realm.podspec | 12 +++++++-- .../tests/ios/Flutter/AppFrameworkInfo.plist | 2 +- flutter/realm_flutter/tests/ios/Podfile | 2 +- flutter/realm_flutter/tests/ios/Podfile.lock | 8 +++--- .../ios/Runner.xcodeproj/project.pbxproj | 5 +++- .../realm_flutter/tests/ios/Runner/Info.plist | 4 +++ lib/src/native/realm_core.dart | 8 +++++- test/app_test.dart | 7 +++++ 12 files changed, 91 insertions(+), 23 deletions(-) create mode 100644 flutter/realm_flutter/ios/Classes/platform.mm create mode 100644 flutter/realm_flutter/ios/Classes/realm_plugin.h diff --git a/flutter/realm_flutter/ios/Classes/platform.mm b/flutter/realm_flutter/ios/Classes/platform.mm new file mode 100644 index 000000000..9ede0b3c0 --- /dev/null +++ b/flutter/realm_flutter/ios/Classes/platform.mm @@ -0,0 +1,15 @@ +#import "realm_plugin.h" + +#include +#include + + +#ifndef BUNDLE_ID +#define BUNDLE_ID "realm_bundle_id" +#endif + +static std::string bundleId = BUNDLE_ID; + +RLM_API const char* realm_dart_get_bundle_id() { + return bundleId.c_str(); +} \ No newline at end of file diff --git a/flutter/realm_flutter/ios/Classes/realm_plugin.h b/flutter/realm_flutter/ios/Classes/realm_plugin.h new file mode 100644 index 000000000..803b4d88e --- /dev/null +++ b/flutter/realm_flutter/ios/Classes/realm_plugin.h @@ -0,0 +1,10 @@ +#ifndef FLUTTER_PLUGIN_REALM_PLUGIN_H_ +#define FLUTTER_PLUGIN_REALM_PLUGIN_H_ + +#ifdef __cplusplus +#define RLM_API extern "C" __attribute__((visibility("default"))) +#else +#define RLM_API +#endif // __cplusplus + +#endif // FLUTTER_PLUGIN_REALM_PLUGIN_H_ \ No newline at end of file diff --git a/flutter/realm_flutter/ios/realm.podspec b/flutter/realm_flutter/ios/realm.podspec index 5eceb3d15..c4214a9bf 100644 --- a/flutter/realm_flutter/ios/realm.podspec +++ b/flutter/realm_flutter/ios/realm.podspec @@ -8,6 +8,14 @@ realmPackageDir = File.expand_path(__dir__) # This works cause realm plugin is always accessed through the .symlinks directory. # For example the tests app refers to the realm plugin using this path .../realm-dart/flutter/realm_flutter/tests/ios/.symlinks/plugins/realm/ios project_dir = File.expand_path("../../../../", realmPackageDir) +puts "project dir is #{project_dir}" +app_dir = File.expand_path("../", project_dir) +puts "app dir is #{app_dir}" +contents = IO.read("#{app_dir}/pubspec.yaml") +match = contents.match("name:[ \r\n\t]*([a-z0-9_]*)") +bundleId = match[1] +puts "bundleId is #{bundleId}" + Pod::Spec.new do |s| s.name = 'realm' @@ -20,13 +28,12 @@ Pod::Spec.new do |s| s.license = { :file => '../LICENSE' } s.author = { 'Realm' => 'help@realm.io' } s.source = { :path => '.' } - s.source_files = 'Classes/**/*', - 'src/realm_dart.cpp' - 'src/realm_dart_scheduler.cpp' - s.public_header_files = 'Classes/**/*.h', + s.source_files = 'Classes/**/*' + s.public_header_files = 'Classes/**/*.h' s.vendored_frameworks = 'realm_dart.xcframework' s.dependency 'Flutter' s.platform = :ios, '8.0' + s.compiler_flags = "-DBUNDLE_ID='\"#{bundleId}\"'" s.library = 'c++', 'z', 'compression' s.swift_version = '5.0' diff --git a/flutter/realm_flutter/macos/Classes/platform.mm b/flutter/realm_flutter/macos/Classes/platform.mm index e3b4eddd1..3a92593b3 100644 --- a/flutter/realm_flutter/macos/Classes/platform.mm +++ b/flutter/realm_flutter/macos/Classes/platform.mm @@ -4,7 +4,12 @@ #import "realm_plugin.h" +#ifndef BUNDLE_ID +#define BUNDLE_ID "realm_bundle_id" +#endif + static std::string filesDir; +static std::string bundleId = BUNDLE_ID; std::string default_realm_file_directory() { @@ -31,13 +36,16 @@ return filesDir.c_str(); } -std::string app_bundle_id() -{ - std::string ret; - std::string bundle; - @autoreleasepool { - NSString *path = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES)[0]; - ret = path.UTF8String; - return ret; - } +// std::string get_app_bundle_id() +// { +// std::string ret; +// @autoreleasepool { +// NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; +// ret = bundleId.UTF8String; +// return ret; +// } +// } + +RLM_API const char* realm_dart_get_bundle_id() { + return bundleId.c_str(); } \ No newline at end of file diff --git a/flutter/realm_flutter/macos/realm.podspec b/flutter/realm_flutter/macos/realm.podspec index 2d6ea0325..429e60e2a 100644 --- a/flutter/realm_flutter/macos/realm.podspec +++ b/flutter/realm_flutter/macos/realm.podspec @@ -24,8 +24,15 @@ end # This works cause realm plugin is always accessed through the .symlinks directory. # For example the tests app refers to the realm plugin using this path .../realm-dart/flutter/realm_flutter/tests/macos/Flutter/ephemeral/.symlinks/plugins/realm/macos -#project_dir = File.expand_path("../../../../../../", realmPackageDir) -#puts "project dir is #{project_dir}" +project_dir = File.expand_path("../../../../../../", realmPackageDir) +puts "project dir is #{project_dir}" +app_dir = File.expand_path("../", project_dir) +puts "app dir is #{app_dir}" +contents = IO.read("#{app_dir}/pubspec.yaml") +match = contents.match("name:[ \r\n\t]*([a-z0-9_]*)") +bundleId = match[1] +puts "bundleId is #{bundleId}" + Pod::Spec.new do |s| s.name = 'realm' @@ -42,6 +49,7 @@ Pod::Spec.new do |s| s.dependency 'FlutterMacOS' s.platform = :osx, '10.11' + s.compiler_flags = "-DBUNDLE_ID='\"#{bundleId}\"'" s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } s.swift_version = '5.0' s.vendored_libraries = "#{realmLibName}" diff --git a/flutter/realm_flutter/tests/ios/Flutter/AppFrameworkInfo.plist b/flutter/realm_flutter/tests/ios/Flutter/AppFrameworkInfo.plist index 8d4492f97..9625e105d 100644 --- a/flutter/realm_flutter/tests/ios/Flutter/AppFrameworkInfo.plist +++ b/flutter/realm_flutter/tests/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 9.0 + 11.0 diff --git a/flutter/realm_flutter/tests/ios/Podfile b/flutter/realm_flutter/tests/ios/Podfile index bbf38dd7a..c8d1d1054 100644 --- a/flutter/realm_flutter/tests/ios/Podfile +++ b/flutter/realm_flutter/tests/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -# platform :ios, '9.0' +# platform :ios, '11.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/flutter/realm_flutter/tests/ios/Podfile.lock b/flutter/realm_flutter/tests/ios/Podfile.lock index d89d086c0..b5cd76e86 100644 --- a/flutter/realm_flutter/tests/ios/Podfile.lock +++ b/flutter/realm_flutter/tests/ios/Podfile.lock @@ -1,6 +1,6 @@ PODS: - Flutter (1.0.0) - - realm (0.2.0-alpha): + - realm (1.1.0): - Flutter DEPENDENCIES: @@ -14,9 +14,9 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/realm/ios" SPEC CHECKSUMS: - Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a - realm: 71339a0c9404880f0a28bf36261d9bccfaa1e0e9 + Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 + realm: 104bf411adc61b39e514af04e3ba63991848d3c1 -PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c +PODFILE CHECKSUM: becca988ffbff1a0c8cb1783db8d779d20baed78 COCOAPODS: 1.11.2 diff --git a/flutter/realm_flutter/tests/ios/Runner.xcodeproj/project.pbxproj b/flutter/realm_flutter/tests/ios/Runner.xcodeproj/project.pbxproj index a2d3d5db1..3b635d62d 100644 --- a/flutter/realm_flutter/tests/ios/Runner.xcodeproj/project.pbxproj +++ b/flutter/realm_flutter/tests/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -199,10 +199,12 @@ /* Begin PBXShellScriptBuildPhase section */ 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( @@ -235,6 +237,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); diff --git a/flutter/realm_flutter/tests/ios/Runner/Info.plist b/flutter/realm_flutter/tests/ios/Runner/Info.plist index d34500cad..ca253cbd9 100644 --- a/flutter/realm_flutter/tests/ios/Runner/Info.plist +++ b/flutter/realm_flutter/tests/ios/Runner/Info.plist @@ -41,5 +41,9 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + diff --git a/lib/src/native/realm_core.dart b/lib/src/native/realm_core.dart index 313a8794c..c3b08d7d8 100644 --- a/lib/src/native/realm_core.dart +++ b/lib/src/native/realm_core.dart @@ -2259,8 +2259,14 @@ class _RealmCore { } } - String _getBundleId() { + String getBundleId() { assert(isFlutterPlatform); + if (Platform.isIOS) { + final getBundleIdFunc1 = DynamicLibrary.executable().lookupFunction Function(), Pointer Function()>("realm_dart_get_bundle_id"); + final bundleIdPtr = getBundleIdFunc1(); + return bundleIdPtr.cast().toDartString(); + } + final getBundleIdFunc = _pluginLib.lookupFunction Function(), Pointer Function()>("realm_dart_get_bundle_id"); final bundleIdPtr = getBundleIdFunc(); return bundleIdPtr.cast().toDartString(); diff --git a/test/app_test.dart b/test/app_test.dart index ad25899e1..e8446162c 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -22,6 +22,7 @@ import 'package:test/expect.dart' hide throws; import 'package:path/path.dart' as path; import '../lib/realm.dart'; +import '../lib/src/native/realm_core.dart'; import 'test.dart'; Future main([List? args]) async { @@ -298,6 +299,12 @@ Future main([List? args]) async { throws("Switch user failed. Error code: 4101 . Message: User is no longer valid or is logged out"), ); }); + + test('bundle', () { + if (isFlutterPlatform) { + print("The bundle id is '${realmCore.getBundleId()}'"); + } + }); } extension PersonJ on Person { From 55e15481d7dce490265c58ee338292dd3f730036 Mon Sep 17 00:00:00 2001 From: blagoev Date: Sat, 10 Jun 2023 18:15:05 +0300 Subject: [PATCH 04/13] add bundle_id to android --- flutter/realm_flutter/android/build.gradle | 63 +- .../realm_flutter/android/gradle.properties | 1 + .../android/src/gen/RealmConfig.java | 5 + .../android/src/main/cpp/Android.mk | 97 --- .../android/src/main/cpp/Application.mk | 30 - .../android/src/main/cpp/CMakeLists.txt | 50 ++ .../android/src/main/cpp/dart_api_dl.cc | 67 -- .../android/src/main/cpp/dart_api_dl.h | 693 ------------------ .../android/src/main/cpp/dart_api_dl_impl.h | 21 - .../android/src/main/cpp/dart_io_extensions.h | 27 - .../android/src/main/cpp/dart_version.h | 16 - .../android/src/main/cpp/realm_flutter.cpp | 167 ----- .../android/src/main/cpp/realm_flutter.h | 479 ------------ .../src/main/java/io/realm/RealmPlugin.java | 6 +- .../example/android/build.gradle | 4 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../realm_flutter/tests/android/build.gradle | 4 +- .../tests/android/gradle.properties | 1 + .../gradle/wrapper/gradle-wrapper.properties | 2 +- flutter/realm_flutter/windows/CMakeLists.txt | 2 +- .../realm_flutter/windows/realm_plugin.cpp | 2 - lib/src/native/realm_bindings.dart | 12 + lib/src/native/realm_core.dart | 2 + src/android/platform.cpp | 13 +- src/android/platform.h | 2 +- src/realm_dart.h | 3 + 26 files changed, 154 insertions(+), 1617 deletions(-) create mode 100644 flutter/realm_flutter/android/src/gen/RealmConfig.java delete mode 100644 flutter/realm_flutter/android/src/main/cpp/Android.mk delete mode 100644 flutter/realm_flutter/android/src/main/cpp/Application.mk create mode 100644 flutter/realm_flutter/android/src/main/cpp/CMakeLists.txt delete mode 100644 flutter/realm_flutter/android/src/main/cpp/dart_api_dl.cc delete mode 100644 flutter/realm_flutter/android/src/main/cpp/dart_api_dl.h delete mode 100644 flutter/realm_flutter/android/src/main/cpp/dart_api_dl_impl.h delete mode 100644 flutter/realm_flutter/android/src/main/cpp/dart_io_extensions.h delete mode 100644 flutter/realm_flutter/android/src/main/cpp/dart_version.h delete mode 100644 flutter/realm_flutter/android/src/main/cpp/realm_flutter.cpp delete mode 100644 flutter/realm_flutter/android/src/main/cpp/realm_flutter.h diff --git a/flutter/realm_flutter/android/build.gradle b/flutter/realm_flutter/android/build.gradle index c447369fe..d760696a4 100644 --- a/flutter/realm_flutter/android/build.gradle +++ b/flutter/realm_flutter/android/build.gradle @@ -27,12 +27,15 @@ android { defaultConfig { minSdkVersion 16 ndk { - abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_x64' + abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' } } sourceSets { main { + java { + srcDirs = ['src/main/java', "$buildDir/realm-generated"] + } jniLibs.srcDirs += ["src/main/cpp/lib/"] } } @@ -40,11 +43,22 @@ android { lintOptions { disable 'InvalidPackage' } + + // externalNativeBuild { + // // cmake { + // // arguments "COMPILE_DEFINITIONS-DBUNDLE_ID=lubo" + // // } + +// externalNativeBuild { +// cmake { +// path "src/main/cpp/CMakeLists.txt" +// } +// } // externalNativeBuild { - // ndkBuild { - // path 'src/main/cpp/Android.mk' - // } + // // ndkBuild { + // // path 'src/main/cpp/Android.mk' + // // } // } } @@ -72,11 +86,14 @@ def getPaths() { } task runMetrics(type: Exec) { + outputs.upToDateWhen { false } + try { def appProject = project.rootProject.subprojects.find { p -> p.name == 'app' } def (flutterRoot, flutterExecutablePath) = getPaths() workingDir "${project.rootProject.projectDir}${File.separator}.." + String targetOsVersion if (appProject != null) { def conf = appProject.android.defaultConfig @@ -90,12 +107,46 @@ task runMetrics(type: Exec) { } task downloadRealmBinaries(type: Exec) { - def (flutterRoot, flutterExecutablePath) = getPaths() + outputs.upToDateWhen { false } + def (flutterRoot, flutterExecutablePath) = getPaths() workingDir "${project.rootProject.projectDir}${File.separator}.." commandLine flutterExecutablePath, 'pub', 'run', 'realm', 'install', '--target-os-type', 'android', '--flavor', 'flutter' } -preBuild.dependsOn runMetrics, downloadRealmBinaries +def getBundleId() { + try { + def pubSpecFilePath = "${project.rootProject.projectDir}${File.separator}..${File.separator}pubspec.yaml" + //println "pubSpecFilePath is ${pubSpecFilePath}" + def pubspecFile = new File("${project.rootProject.projectDir}${File.separator}..${File.separator}pubspec.yaml") + if (pubspecFile.exists()) { + def contents = pubspecFile.text + //println contents + def matches = contents =~ /name:[ \r\n\t]*([a-z0-9_]*)/ + def bundleId = matches[0][1] + //println "bundleId is ${bundleId}" + return bundleId + } + } + catch (e) { + println "Error getting bundle id $e" + } + + //fallback value + return project.rootProject.name; +} + +task generateRealmConfig(type: Copy) { + outputs.upToDateWhen { false } + + def bundleId = getBundleId(); + from 'src/gen' + into "$buildDir/realm-generated" + filter { line -> line.replaceAll('realm_bundle_id', "${bundleId}") } +} +//task printProjectTasks { +// project.getAllTasks(false).each { key, value -> value.each { task -> println("task=${task} dependsOn=${task.dependsOn}") } } +//} +preBuild.dependsOn runMetrics, downloadRealmBinaries, generateRealmConfig \ No newline at end of file diff --git a/flutter/realm_flutter/android/gradle.properties b/flutter/realm_flutter/android/gradle.properties index 94adc3a3f..a4e1f1a4e 100644 --- a/flutter/realm_flutter/android/gradle.properties +++ b/flutter/realm_flutter/android/gradle.properties @@ -1,3 +1,4 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true +android.native.buildOutput=verbose diff --git a/flutter/realm_flutter/android/src/gen/RealmConfig.java b/flutter/realm_flutter/android/src/gen/RealmConfig.java new file mode 100644 index 000000000..82e25a3ad --- /dev/null +++ b/flutter/realm_flutter/android/src/gen/RealmConfig.java @@ -0,0 +1,5 @@ +package io.realm; + +class RealmConfig { + public static final String bundleId = "realm_bundle_id"; +} \ No newline at end of file diff --git a/flutter/realm_flutter/android/src/main/cpp/Android.mk b/flutter/realm_flutter/android/src/main/cpp/Android.mk deleted file mode 100644 index 3b99b4d9e..000000000 --- a/flutter/realm_flutter/android/src/main/cpp/Android.mk +++ /dev/null @@ -1,97 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -# include $(CLEAR_VARS) -LOCAL_MODULE := crypto -LOCAL_SRC_FILES := lib/$(TARGET_ARCH_ABI)/libcrypto.a -include $(PREBUILT_STATIC_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := realm-android -LOCAL_SRC_FILES := lib/$(TARGET_ARCH_ABI)/librealm-android-$(TARGET_ARCH_ABI).a -include $(PREBUILT_STATIC_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := realm-parser-android -LOCAL_SRC_FILES := lib/$(TARGET_ARCH_ABI)/librealm-parser-android-$(TARGET_ARCH_ABI).a -include $(PREBUILT_STATIC_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := libflutter -LOCAL_SRC_FILES := lib/$(TARGET_ARCH_ABI)/libflutter.so -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := librealm_flutter - -REALM_DART_EXTENSION_SRC_PATH := ../../../../../../src -REALM_DART_EXTENSION_PATH := $(REALM_DART_EXTENSION_SRC_PATH)/realm-dart-extension -OBJECT_STORE_PATH := $(REALM_DART_EXTENSION_SRC_PATH)/object-store - -LOCAL_SRC_FILES := realm_flutter.cpp -LOCAL_SRC_FILES += dart_api_dl.cc -LOCAL_SRC_FILES += $(REALM_DART_EXTENSION_PATH)/dart/dart_init.cpp -LOCAL_SRC_FILES += $(REALM_DART_EXTENSION_PATH)/dart/dart_types.cpp -LOCAL_SRC_FILES += $(REALM_DART_EXTENSION_PATH)/realm-js-common/js_realm.cpp -LOCAL_SRC_FILES += $(REALM_DART_EXTENSION_PATH)/dart/platform.cpp -LOCAL_SRC_FILES += $(REALM_DART_EXTENSION_PATH)/realm_dart_extension.cpp - - -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/impl/collection_change_builder.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/impl/collection_notifier.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/impl/list_notifier.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/impl/object_notifier.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/impl/realm_coordinator.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/impl/results_notifier.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/impl/transact_log_handler.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/impl/weak_realm_notifier.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/impl/epoll/external_commit_helper.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/util/uuid.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/binding_callback_thread_observer.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/collection_notifications.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/index_set.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/list.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/object_schema.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/object_store.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/object.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/object_changeset.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/results.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/schema.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/shared_realm.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/thread_safe_reference.cpp -LOCAL_SRC_FILES += $(OBJECT_STORE_PATH)/src/util/scheduler.cpp - -REALM_DART_EXTENSION_FULL_PATH := $(LOCAL_PATH)/$(REALM_DART_EXTENSION_SRC_PATH)/realm-dart-extension -OBJECT_STORE_PATH_FULL_PATH := $(LOCAL_PATH)/$(REALM_DART_EXTENSION_SRC_PATH)/object-store -DART_INCLUDE := $(LOCAL_PATH)/$(REALM_DART_EXTENSION_SRC_PATH)/dart-include - -$(info REALM_DART_EXTENSION_FULL_PATH is $(REALM_DART_EXTENSION_FULL_PATH)) -$(info OBJECT_STORE_PATH_FULL_PATH is $(OBJECT_STORE_PATH_FULL_PATH)) - - -LOCAL_C_INCLUDES := $(REALM_DART_EXTENSION_FULL_PATH)/realm-js-common -LOCAL_C_INCLUDES += $(OBJECT_STORE_PATH_FULL_PATH)/src -LOCAL_C_INCLUDES += $(OBJECT_STORE_PATH_FULL_PATH)/external/json -LOCAL_C_INCLUDES += $(LOCAL_PATH)/lib/include -LOCAL_C_INCLUDES += $(LOCAL_PATH)/lib/include/openssl -LOCAL_C_INCLUDES += dart_io_extensions.h -LOCAL_C_INCLUDES += dart_api_dl.h -LOCAL_C_INCLUDES += dart_version.h -LOCAL_C_INCLUDES += dart_api_dl_impl.h -LOCAL_C_INCLUDES += $(REALM_DART_EXTENSION_FULL_PATH)/dart -LOCAL_C_INCLUDES += $(DART_INCLUDE) - -LOCAL_CPPFLAGS += -DFLUTTER - -#LOCAL_ALLOW_UNDEFINED_SYMBOLS := true - -LOCAL_STATIC_LIBRARIES := realm-parser-android -LOCAL_STATIC_LIBRARIES += realm-android -# LOCAL_STATIC_LIBRARIES += librealm-object-store -LOCAL_STATIC_LIBRARIES += crypto - -LOCAL_SHARED_LIBRARIES := libflutter - -# LOCAL_LDLIBS := -llog -landroid -lstlport -llibc++_static - -# LOCAL_SHARED_LIBRARIES := libjsc -include $(BUILD_SHARED_LIBRARY) diff --git a/flutter/realm_flutter/android/src/main/cpp/Application.mk b/flutter/realm_flutter/android/src/main/cpp/Application.mk deleted file mode 100644 index 9f0d73029..000000000 --- a/flutter/realm_flutter/android/src/main/cpp/Application.mk +++ /dev/null @@ -1,30 +0,0 @@ -APP_BUILD_SCRIPT := Android.mk - -APP_ABI := armeabi-v7a x86 -APP_PLATFORM := android-16 - -APP_MK_DIR := $(dir $(lastword $(MAKEFILE_LIST))) - -NDK_MODULE_PATH := $(APP_MK_DIR)$(HOST_DIRSEP)$(THIRD_PARTY_NDK_DIR)$(HOST_DIRSEP)$(APP_MK_DIR) - -APP_STL := c++_static -APP_CPPFLAGS := -std=c++14 -APP_CPPFLAGS += -frtti -APP_CPPFLAGS += -fexceptions -APP_CPPFLAGS += -DREALM_HAVE_CONFIG -APP_CPPFLAGS += -fomit-frame-pointer -APP_CPPFLAGS += -fvisibility=hidden - -# Make sure every shared lib includes a .note.gnu.build-id header -APP_LDFLAGS := -Wl,--build-id -APP_LDFLAGS += -llog -APP_LDFLAGS += -landroid -# APP_LDFLAGS += -llibc++_static -APP_LDFLAGS += -fvisibility=hidden - -# Workaround for getting UINT64_MAX defined -# https://stackoverflow.com/questions/16748392/cant-find-symbols-in-stdint-h -APP_CPPFLAGS += -D__STDC_LIMIT_MACROS=1 - - -NDK_TOOLCHAIN_VERSION := clang \ No newline at end of file diff --git a/flutter/realm_flutter/android/src/main/cpp/CMakeLists.txt b/flutter/realm_flutter/android/src/main/cpp/CMakeLists.txt new file mode 100644 index 000000000..f2287a32d --- /dev/null +++ b/flutter/realm_flutter/android/src/main/cpp/CMakeLists.txt @@ -0,0 +1,50 @@ +cmake_minimum_required(VERSION 3.10) +set(PROJECT_NAME "realm") + +project(${PROJECT_NAME} LANGUAGES CXX) + +set(PLUGIN_NAME "realm_plugin") + +set(CMAKE_VERBOSE_MAKEFILE TRUE CACHE BOOL "" FORCE) + +add_library(${PLUGIN_NAME} SHARED "realm_plugin.cpp") + +set(APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../..") +message("APP_DIR is ${APP_DIR}") +message("PROJECT_SOURCE_DIR is ${PROJECT_SOURCE_DIR}") + + +#function(print_directory_variables dir) +# # Dump variables: +# get_property(_variableNames DIRECTORY ${dir} PROPERTY VARIABLES) +# list (SORT _variableNames) +# foreach (_variableName ${_variableNames}) +# get_directory_property(_variableValue DIRECTORY ${dir} DEFINITION ${_variableName}) +# message(STATUS "DIR ${dir}: ${_variableName}=${_variableValue}") +# endforeach() +#endfunction(print_directory_variables) +# +#print_directory_variables(.) + +# execute_process(COMMAND "echo" +# OUTPUT_VARIABLE output +# RESULT_VARIABLE result +# COMMAND_ERROR_IS_FATAL ANY +# ) + +# set(APP_PUBSPEC_FILE "${APP_DIR}/pubspec.yaml") +# # message ("APP_PUBSPEC_FILE is ${APP_PUBSPEC_FILE}") +# file(READ "${APP_PUBSPEC_FILE}" PUBSPEC_CONTENT) +# string(REGEX MATCH "name:[ \r\n\t]*([a-z0-9_]*)" _ ${PUBSPEC_CONTENT}) +# # message ("Pubspec name 0 is ${CMAKE_MATCH_0}") +# # message ("Package name is ${CMAKE_MATCH_1}") +# set(APP_DIR_NAME ${CMAKE_MATCH_1}) +# set(BUNDLE_ID ${CMAKE_MATCH_1}) +# # string(ASCII 114, 101, 97, 108, 109, 32, 105, 115, 32, 103, 114, 101, 97, 116 PREFIX) +# # string(PREPEND BUNDLE_ID ${PREFIX}) +# # message ("BUNDLE_ID is ${BUNDLE_ID}") +# # string(SHA256 ) + +# #message ("BINARY_NAME is ${BINARY_NAME}") +# add_definitions(-DAPP_DIR_NAME="${APP_DIR_NAME}") +# add_definitions(-DBUNDLE_ID="${BUNDLE_ID}") \ No newline at end of file diff --git a/flutter/realm_flutter/android/src/main/cpp/dart_api_dl.cc b/flutter/realm_flutter/android/src/main/cpp/dart_api_dl.cc deleted file mode 100644 index 21b180fe0..000000000 --- a/flutter/realm_flutter/android/src/main/cpp/dart_api_dl.cc +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file - * for details. All rights reserved. Use of this source code is governed by a - * BSD-style license that can be found in the LICENSE file. - */ - -#include "dart_api_dl.h" /* NOLINT */ -#include "dart_version.h" /* NOLINT */ -#include "dart_api_dl_impl.h" /* NOLINT */ - -#include - -#include - -void init(); - -#define DART_API_DL_DEFINITIONS(name, R, A) name##_Type name##_DL = NULL; - -DART_API_ALL_DL_SYMBOLS(DART_API_DL_DEFINITIONS) - -#undef DART_API_DL_DEFINITIONS - -typedef void (*DartApiEntry_function)(); - -DartApiEntry_function FindFunctionPointer(const DartApiEntry* entries, - const char* name) { - while (entries->name != NULL) { - if (strcmp(entries->name, name) == 0) return entries->function; - entries++; - } - return NULL; -} - -intptr_t Dart_InitializeApiDL(void* data) { - DartApi* dart_api_data = (DartApi*)data; - - if (dart_api_data->major != DART_API_DL_MAJOR_VERSION) { - // If the DartVM we're running on does not have the same version as this - // file was compiled against, refuse to initialize. The symbols are not - // compatible. - return -1; - } - // Minor versions are allowed to be different. - // If the DartVM has a higher minor version, it will provide more symbols - // than we initialize here. - // If the DartVM has a lower minor version, it will not provide all symbols. - // In that case, we leave the missing symbols un-initialized. Those symbols - // should not be used by the Dart and native code. The client is responsible - // for checking the minor version number himself based on which symbols it - // is using. - // (If we would error out on this case, recompiling native code against a - // newer SDK would break all uses on older SDKs, which is too strict.) - - const DartApiEntry* dart_api_function_pointers = dart_api_data->functions; - -#define DART_API_DL_INIT(name, R, A) \ - name##_DL = \ - (name##_Type)(FindFunctionPointer(dart_api_function_pointers, #name)); - DART_API_ALL_DL_SYMBOLS(DART_API_DL_INIT) -#undef DART_API_DL_INIT - - __android_log_print(ANDROID_LOG_DEBUG, "RealmFlutter", "Dart_InitializeApiDL calling init()"); - init(); - __android_log_print(ANDROID_LOG_DEBUG, "RealmFlutter", "Dart_InitializeApiDL done"); - - return 0; -} diff --git a/flutter/realm_flutter/android/src/main/cpp/dart_api_dl.h b/flutter/realm_flutter/android/src/main/cpp/dart_api_dl.h deleted file mode 100644 index f3ab238c8..000000000 --- a/flutter/realm_flutter/android/src/main/cpp/dart_api_dl.h +++ /dev/null @@ -1,693 +0,0 @@ -/* - * Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file - * for details. All rights reserved. Use of this source code is governed by a - * BSD-style license that can be found in the LICENSE file. - */ - -#ifndef RUNTIME_INCLUDE_DART_API_DL_H_ -#define RUNTIME_INCLUDE_DART_API_DL_H_ - -#include "dart_api.h" /* NOLINT */ -#include "dart_native_api.h" /* NOLINT */ - -/** \mainpage Dynamically Linked Dart API - * - * This exposes a subset of symbols from dart_api.h and dart_native_api.h - * available in every Dart embedder through dynamic linking. - * - * All symbols are postfixed with _DL to indicate that they are dynamically - * linked and to prevent conflicts with the original symbol. - * - * Link `dart_api_dl.c` file into your library and invoke - * `Dart_InitializeApiDL` with `NativeApi.initializeApiDLData`. - */ - -#ifdef __cplusplus -#define DART_EXTERN extern "C" -#else -#define DART_EXTERN extern -#endif - -// DART_EXTERN intptr_t Dart_InitializeApiDL(void* data); - -__attribute__ ((visibility ("default"))) extern "C" intptr_t Dart_InitializeApiDL(void* data); - - -// ============================================================================ -// IMPORTANT! Never update these signatures without properly updating -// DART_API_DL_MAJOR_VERSION and DART_API_DL_MINOR_VERSION. -// -// Verbatim copy of `dart_native_api.h` and `dart_api.h` symbol names and types -// to trigger compile-time errors if the sybols in those files are updated -// without updating these. -// -// Function return and argument types, and typedefs are carbon copied. Structs -// are typechecked nominally in C/C++, so they are not copied, instead a -// comment is added to their definition. -typedef int64_t Dart_Port_DL; - -typedef void (*Dart_NativeMessageHandler_DL)(Dart_Port_DL dest_port_id, - Dart_CObject* message); - -// dart_native_api.h symbols can be called on any thread. -#define DART_NATIVE_API_DL_SYMBOLS(F) \ - /***** dart_native_api.h *****/ \ - /* Dart_Port */ \ - F(Dart_PostCObject, bool, (Dart_Port_DL port_id, Dart_CObject * message)) \ - F(Dart_PostInteger, bool, (Dart_Port_DL port_id, int64_t message)) \ - F(Dart_NewNativePort, Dart_Port_DL, \ - (const char* name, Dart_NativeMessageHandler_DL handler, \ - bool handle_concurrently)) \ - F(Dart_CloseNativePort, bool, (Dart_Port_DL native_port_id)) - -// dart_api.h symbols can only be called on Dart threads. -#define DART_API_DL_SYMBOLS(F) \ - /***** dart_api.h *****/ \ - /* Errors */ \ - F(Dart_IsError, bool, (Dart_Handle handle)) \ - F(Dart_IsApiError, bool, (Dart_Handle handle)) \ - F(Dart_IsUnhandledExceptionError, bool, (Dart_Handle handle)) \ - F(Dart_IsCompilationError, bool, (Dart_Handle handle)) \ - F(Dart_IsFatalError, bool, (Dart_Handle handle)) \ - F(Dart_GetError, const char*, (Dart_Handle handle)) \ - F(Dart_ErrorHasException, bool, (Dart_Handle handle)) \ - F(Dart_ErrorGetException, Dart_Handle, (Dart_Handle handle)) \ - F(Dart_ErrorGetStackTrace, Dart_Handle, (Dart_Handle handle)) \ - F(Dart_NewApiError, Dart_Handle, (const char* error)) \ - F(Dart_NewCompilationError, Dart_Handle, (const char* error)) \ - F(Dart_NewUnhandledExceptionError, Dart_Handle, (Dart_Handle exception)) \ - F(Dart_PropagateError, void, (Dart_Handle handle)) \ - /* Dart_Handle, Dart_PersistentHandle, Dart_WeakPersistentHandle */ \ - F(Dart_HandleFromPersistent, Dart_Handle, (Dart_PersistentHandle object)) \ - F(Dart_HandleFromWeakPersistent, Dart_Handle, \ - (Dart_WeakPersistentHandle object)) \ - F(Dart_NewPersistentHandle, Dart_PersistentHandle, (Dart_Handle object)) \ - F(Dart_SetPersistentHandle, void, \ - (Dart_PersistentHandle obj1, Dart_Handle obj2)) \ - F(Dart_DeletePersistentHandle, void, (Dart_PersistentHandle object)) \ - F(Dart_NewWeakPersistentHandle, Dart_WeakPersistentHandle, \ - (Dart_Handle object, void* peer, intptr_t external_allocation_size, \ - Dart_HandleFinalizer callback)) \ - F(Dart_DeleteWeakPersistentHandle, void, (Dart_WeakPersistentHandle object)) \ - F(Dart_UpdateExternalSize, void, \ - (Dart_WeakPersistentHandle object, intptr_t external_allocation_size)) \ - F(Dart_NewFinalizableHandle, Dart_FinalizableHandle, \ - (Dart_Handle object, void* peer, intptr_t external_allocation_size, \ - Dart_HandleFinalizer callback)) \ - F(Dart_DeleteFinalizableHandle, void, \ - (Dart_FinalizableHandle object, Dart_Handle strong_ref_to_object)) \ - F(Dart_UpdateFinalizableExternalSize, void, \ - (Dart_FinalizableHandle object, Dart_Handle strong_ref_to_object, \ - intptr_t external_allocation_size)) \ - /* Dart_Port */ \ - F(Dart_Post, bool, (Dart_Port_DL port_id, Dart_Handle object)) \ - F(Dart_NewSendPort, Dart_Handle, (Dart_Port_DL port_id)) \ - F(Dart_SendPortGetId, Dart_Handle, \ - (Dart_Handle port, Dart_Port_DL * port_id)) \ - /* Scopes */ \ - F(Dart_EnterScope, void, ()) \ -F(Dart_ExitScope, void, ()) \ - \ - \ -/* extenders*/ \ - \ -F(Dart_Allocate, Dart_Handle, (Dart_Handle type)) \ - \ -F(Dart_AllocateWithNativeFields, Dart_Handle, ( \ - Dart_Handle type, \ - intptr_t num_native_fields, \ - const intptr_t* native_fields)) \ - \ -F(Dart_BooleanValue, Dart_Handle, (Dart_Handle boolean_obj, \ - bool* value)) \ - \ -F(Dart_ClassLibrary, Dart_Handle, (Dart_Handle cls_type)) \ - \ -F(Dart_ClassName, Dart_Handle, (Dart_Handle cls_type)) \ - \ -F(Dart_Cleanup, char*, ()) \ - \ -F(Dart_ClosureFunction, Dart_Handle, (Dart_Handle closure)) \ - \ -F(Dart_CreateIsolateGroup, Dart_Isolate, ( \ - const char* script_uri, \ - const char* name, \ - const uint8_t* isolate_snapshot_data, \ - const uint8_t* isolate_snapshot_instructions, \ - Dart_IsolateFlags* flags, \ - void* isolate_group_data, \ - void* isolate_data, \ - char** error)) \ - \ -F(Dart_CreateIsolateGroupFromKernel, Dart_Isolate, ( \ - const char* script_uri, \ - const char* name, \ - const uint8_t* kernel_buffer, \ - intptr_t kernel_buffer_size, \ - Dart_IsolateFlags* flags, \ - void* isolate_group_data, \ - void* isolate_data, \ - char** error)) \ - \ -F(Dart_CurrentIsolate, Dart_Isolate, ()) \ - \ -F(Dart_CurrentIsolateData, void*, ()) \ - \ -F(Dart_CurrentIsolateGroup, Dart_IsolateGroup, ()) \ - \ -F(Dart_CurrentIsolateGroupData, void*, ()) \ - \ -F(Dart_DebugName, Dart_Handle, ()) \ - \ -F(Dart_DoubleValue, Dart_Handle, (Dart_Handle double_obj, \ - double* value)) \ - \ -F(Dart_DumpNativeStackTrace, void, (void* context)) \ - \ -F(Dart_EmptyString, Dart_Handle, ()) \ - \ -F(Dart_EnterIsolate, void, (Dart_Isolate isolate)) \ - \ -F(Dart_ExitIsolate, void, ()) \ - \ -F(Dart_False, Dart_Handle, ()) \ - \ -F(Dart_FunctionIsStatic, Dart_Handle, (Dart_Handle function, \ - bool* is_static)) \ - \ -F(Dart_FunctionName, Dart_Handle, (Dart_Handle function)) \ - \ -F(Dart_FunctionOwner, Dart_Handle, (Dart_Handle function)) \ - \ -F(Dart_GetClass, Dart_Handle, (Dart_Handle library, \ - Dart_Handle class_name)) \ - \ -F(Dart_GetDataFromByteBuffer, Dart_Handle, ( \ - Dart_Handle byte_buffer)) \ - \ -F(Dart_GetField, Dart_Handle, (Dart_Handle container, \ - Dart_Handle name)) \ - \ -F(Dart_GetImportsOfScheme, Dart_Handle, (Dart_Handle scheme)) \ - \ -F(Dart_GetLoadedLibraries, Dart_Handle, ()) \ - \ -F(Dart_GetMessageNotifyCallback, Dart_MessageNotifyCallback, ()) \ - \ -F(Dart_GetNativeArguments, Dart_Handle, ( \ - Dart_NativeArguments args, \ - int num_arguments, \ - const Dart_NativeArgument_Descriptor* arg_descriptors, \ - Dart_NativeArgument_Value* arg_values)) \ - \ -F(Dart_GetNativeArgument, Dart_Handle, ( \ - Dart_NativeArguments args, \ - int index)) \ - \ -F(Dart_GetNativeBooleanArgument, Dart_Handle, ( \ - Dart_NativeArguments args, \ - int index, \ - bool* value)) \ - \ -F(Dart_GetNativeDoubleArgument, Dart_Handle, ( \ - Dart_NativeArguments args, \ - int index, \ - double* value)) \ - \ -F(Dart_GetNativeArgumentCount, int, (Dart_NativeArguments args)) \ - \ -F(Dart_GetNativeFieldsOfArgument, Dart_Handle, ( \ - Dart_NativeArguments args, \ - int arg_index, \ - int num_fields, \ - intptr_t* field_values)) \ - \ -F(Dart_GetNativeInstanceField, Dart_Handle, (Dart_Handle obj, \ - int index, \ - intptr_t* value)) \ - \ -F(Dart_GetNativeInstanceFieldCount, Dart_Handle, ( \ - Dart_Handle obj, \ - int* count)) \ - \ -F(Dart_GetNativeIntegerArgument, Dart_Handle, ( \ - Dart_NativeArguments args, \ - int index, \ - int64_t* value)) \ - \ -F(Dart_GetNativeIsolateGroupData, void*, ( \ - Dart_NativeArguments args)) \ - \ -F(Dart_SetNativeResolver, Dart_Handle, (Dart_Handle library, \ - Dart_NativeEntryResolver resolver, \ - Dart_NativeEntrySymbol symbol)) \ - \ -F(Dart_GetNativeResolver, Dart_Handle, (Dart_Handle library, \ - Dart_NativeEntryResolver* resolver)) \ - \ -F(Dart_GetNativeStringArgument, Dart_Handle, ( \ - Dart_NativeArguments args, \ - int arg_index, \ - void** peer)) \ - \ -F(Dart_GetNativeSymbol, Dart_Handle, ( \ - Dart_Handle library, \ - Dart_NativeEntrySymbol* resolver)) \ - \ -F(Dart_GetNonNullableType, Dart_Handle, (Dart_Handle library, \ - Dart_Handle class_name, \ - intptr_t number_of_type_arguments, \ - Dart_Handle* type_arguments)) \ - \ -F(Dart_GetNullableType, Dart_Handle, ( \ - Dart_Handle library, \ - Dart_Handle class_name, \ - intptr_t number_of_type_arguments, \ - Dart_Handle* type_arguments)) \ - \ -F(Dart_GetPeer, Dart_Handle, (Dart_Handle object, void** peer)) \ - \ -F(Dart_GetStaticMethodClosure, Dart_Handle, ( \ - Dart_Handle library, \ - Dart_Handle cls_type, \ - Dart_Handle function_name)) \ - \ -F(Dart_GetStickyError, Dart_Handle, ()) \ - \ -F(Dart_GetType, Dart_Handle, (Dart_Handle library, \ - Dart_Handle class_name, \ - intptr_t number_of_type_arguments, \ - Dart_Handle* type_arguments)) \ - \ -F(Dart_GetTypeOfExternalTypedData, Dart_TypedData_Type, ( \ - Dart_Handle object)) \ - \ -F(Dart_GetTypeOfTypedData, Dart_TypedData_Type, ( \ - Dart_Handle object)) \ - \ -F(Dart_HasStickyError, bool, ()) \ - \ -F(Dart_IdentityEquals, bool, (Dart_Handle obj1, \ - Dart_Handle obj2)) \ - \ -F(Dart_InstanceGetType, Dart_Handle, (Dart_Handle instance)) \ - \ -F(Dart_IntegerFitsIntoInt64, Dart_Handle, (Dart_Handle integer, \ - bool* fits)) \ - \ -F(Dart_IntegerFitsIntoUint64, Dart_Handle, (Dart_Handle integer, \ - bool* fits)) \ - \ -F(Dart_IntegerToHexCString, Dart_Handle, (Dart_Handle integer, \ - const char** value)) \ - \ -F(Dart_IntegerToInt64, Dart_Handle, (Dart_Handle integer, \ - int64_t* value)) \ - \ -F(Dart_IntegerToUint64, Dart_Handle, (Dart_Handle integer, \ - uint64_t* value)) \ - \ -F(Dart_Invoke, Dart_Handle, (Dart_Handle target, \ - Dart_Handle name, \ - int number_of_arguments, \ - Dart_Handle* arguments)) \ - \ -F(Dart_InvokeClosure, Dart_Handle, (Dart_Handle closure, \ - int number_of_arguments, \ - Dart_Handle* arguments)) \ - \ -F(Dart_InvokeConstructor, Dart_Handle, (Dart_Handle object, \ - Dart_Handle name, \ - int number_of_arguments, \ - Dart_Handle* arguments)) \ - \ -F(Dart_IsBoolean, bool, (Dart_Handle object)) \ - \ -F(Dart_IsByteBuffer, bool, (Dart_Handle object)) \ - \ -F(Dart_IsClosure, bool, (Dart_Handle object)) \ - \ -F(Dart_IsDouble, bool, (Dart_Handle object)) \ - \ -F(Dart_IsExternalString, bool, (Dart_Handle object)) \ - \ -F(Dart_IsFunction, bool, (Dart_Handle handle)) \ - \ -F(Dart_IsFuture, bool, (Dart_Handle object)) \ - \ -F(Dart_IsInstance, bool, (Dart_Handle object)) \ - \ -F(Dart_IsInteger, bool, (Dart_Handle object)) \ - \ -F(Dart_IsKernel, bool, (const uint8_t* buffer, \ - intptr_t buffer_size)) \ - \ -F(Dart_IsKernelIsolate, bool, (Dart_Isolate isolate)) \ - \ -F(Dart_IsLegacyType, Dart_Handle, (Dart_Handle type, \ - bool* result)) \ - \ -F(Dart_IsLibrary, bool, (Dart_Handle object)) \ - \ -F(Dart_IsList, bool, (Dart_Handle object)) \ - \ -F(Dart_IsMap, bool, (Dart_Handle object)) \ - \ -F(Dart_IsNonNullableType, Dart_Handle, (Dart_Handle type, \ - bool* result)) \ - \ -F(Dart_IsNull, bool, (Dart_Handle object)) \ - \ -F(Dart_IsNumber, bool, (Dart_Handle object)) \ - \ -F(Dart_IsolateData, void*, (Dart_Isolate isolate)) \ - \ -F(Dart_IsolateFlagsInitialize, void, (Dart_IsolateFlags* flags)) \ - \ -F(Dart_IsolateGroupData, void*, (Dart_Isolate isolate)) \ - \ -F(Dart_IsolateMakeRunnable, char*, (Dart_Isolate isolate)) \ - \ -F(Dart_IsolateServiceId, const char*, (Dart_Isolate isolate)) \ - \ -F(Dart_IsPausedOnExit, bool, ()) \ - \ -F(Dart_IsPausedOnStart, bool, ()) \ - \ -F(Dart_IsPrecompiledRuntime, bool, ()) \ - \ -F(Dart_IsServiceIsolate, bool, (Dart_Isolate isolate)) \ - \ -F(Dart_IsString, bool, (Dart_Handle object)) \ - \ -F(Dart_IsStringLatin1, bool, (Dart_Handle object)) \ - \ -F(Dart_IsTearOff, bool, (Dart_Handle object)) \ - \ -F(Dart_IsType, bool, (Dart_Handle handle)) \ - \ -F(Dart_IsTypedData, bool, (Dart_Handle object)) \ - \ -F(Dart_IsTypeVariable, bool, (Dart_Handle handle)) \ - \ -F(Dart_IsVariable, bool, (Dart_Handle handle)) \ - \ -F(Dart_IsVMFlagSet, bool, (const char* flag_name)) \ - \ -F(Dart_KernelIsolateIsRunning, bool, ()) \ - \ -F(Dart_KernelListDependencies, Dart_KernelCompilationResult, ()) \ - \ -F(Dart_KernelPort, Dart_Port, ()) \ - \ -F(Dart_KillIsolate, void, (Dart_Isolate isolate)) \ - \ -F(Dart_LibraryHandleError, Dart_Handle, (Dart_Handle library, \ - Dart_Handle error)) \ - \ -F(Dart_LibraryResolvedUrl, Dart_Handle, (Dart_Handle library)) \ - \ -F(Dart_LibraryUrl, Dart_Handle, (Dart_Handle library)) \ - \ -F(Dart_ListGetAsBytes, Dart_Handle, (Dart_Handle list, \ - intptr_t offset, \ - uint8_t* native_array, \ - intptr_t length)) \ - \ -F(Dart_ListGetAt, Dart_Handle, (Dart_Handle list, \ - intptr_t index)) \ - \ -F(Dart_ListGetRange, Dart_Handle, (Dart_Handle list, \ - intptr_t offset, \ - intptr_t length, \ - Dart_Handle* result)) \ - \ -F(Dart_ListLength, Dart_Handle, (Dart_Handle list, \ - intptr_t* length)) \ - \ -F(Dart_ListSetAsBytes, Dart_Handle, (Dart_Handle list, \ - intptr_t offset, \ - const uint8_t* native_array, \ - intptr_t length)) \ - \ -F(Dart_ListSetAt, Dart_Handle, (Dart_Handle list, \ - intptr_t index, \ - Dart_Handle value)) \ - \ -F(Dart_LoadLibraryFromKernel, Dart_Handle, ( \ - const uint8_t* kernel_buffer, \ - intptr_t kernel_buffer_size)) \ - \ -F(Dart_LoadScriptFromKernel, Dart_Handle, ( \ - const uint8_t* kernel_buffer, \ - intptr_t kernel_size)) \ - \ -F(Dart_LookupLibrary, Dart_Handle, (Dart_Handle url)) \ - \ -F(Dart_MapContainsKey, Dart_Handle, (Dart_Handle map, \ - Dart_Handle key)) \ - \ -F(Dart_MapGetAt, Dart_Handle, (Dart_Handle map, Dart_Handle key)) \ - \ -F(Dart_MapKeys, Dart_Handle, (Dart_Handle map)) \ - \ -F(Dart_New, Dart_Handle, (Dart_Handle type, \ - Dart_Handle constructor_name, \ - int number_of_arguments, \ - Dart_Handle* arguments)) \ - \ -F(Dart_NewBoolean, Dart_Handle, (bool value)) \ - \ -F(Dart_NewByteBuffer, Dart_Handle, (Dart_Handle typed_data)) \ - \ -F(Dart_NewDouble, Dart_Handle, (double value)) \ - \ -F(Dart_NewExternalLatin1String, Dart_Handle, ( \ - const uint8_t* latin1_array, \ - intptr_t length, \ - void* peer, \ - intptr_t external_allocation_size, \ - Dart_HandleFinalizer callback)) \ - \ -F(Dart_NewExternalTypedData, Dart_Handle, ( \ - Dart_TypedData_Type type, \ - void* data, \ - intptr_t length)) \ - \ -F(Dart_NewExternalTypedDataWithFinalizer, Dart_Handle, ( \ - Dart_TypedData_Type type, \ - void* data, \ - intptr_t length, \ - void* peer, \ - intptr_t external_allocation_size, \ - Dart_HandleFinalizer callback)) \ - \ -F(Dart_NewExternalUTF16String, Dart_Handle, ( \ - const uint16_t* utf16_array, \ - intptr_t length, \ - void* peer, \ - intptr_t external_allocation_size, \ - Dart_HandleFinalizer callback)) \ - \ -F(Dart_NewInteger, Dart_Handle, (int64_t value)) \ - \ -F(Dart_NewIntegerFromHexCString, Dart_Handle, ( \ - const char* value)) \ - \ -F(Dart_NewIntegerFromUint64, Dart_Handle, (uint64_t value)) \ - \ -F(Dart_NewList, Dart_Handle, (intptr_t length)) \ - \ -F(Dart_NewListOf, Dart_Handle, (Dart_CoreType_Id element_type_id, \ - intptr_t length)) \ - \ -F(Dart_NewListOfType, Dart_Handle, (Dart_Handle element_type, \ - intptr_t length)) \ - \ -F(Dart_NewListOfTypeFilled, Dart_Handle, ( \ - Dart_Handle element_type, \ - Dart_Handle fill_object, \ - intptr_t length)) \ - \ -F(Dart_NewStringFromCString, Dart_Handle, (const char* str)) \ - \ -F(Dart_NewStringFromUTF16, Dart_Handle, ( \ - const uint16_t* utf16_array, \ - intptr_t length)) \ - \ -F(Dart_NewStringFromUTF32, Dart_Handle, ( \ - const int32_t* utf32_array, \ - intptr_t length)) \ - \ -F(Dart_NewStringFromUTF8, Dart_Handle, ( \ - const uint8_t* utf8_array, \ - intptr_t length)) \ - \ -F(Dart_NewTypedData, Dart_Handle, (Dart_TypedData_Type type, \ - intptr_t length)) \ - \ -F(Dart_NotifyIdle, void, (int64_t deadline)) \ - \ -F(Dart_NotifyLowMemory, void, ()) \ - \ -F(Dart_Null, Dart_Handle, ()) \ - \ -F(Dart_ObjectEquals, Dart_Handle, (Dart_Handle obj1, \ - Dart_Handle obj2, \ - bool* equal)) \ - \ -F(Dart_ObjectIsType, Dart_Handle, (Dart_Handle object, \ - Dart_Handle type, \ - bool* instanceof)) \ - \ -F(Dart_PrepareToAbort, void, ()) \ - \ -F(Dart_ReThrowException, Dart_Handle, (Dart_Handle exception, \ - Dart_Handle stacktrace)) \ - \ -F(Dart_RootLibrary, Dart_Handle, ()) \ - \ -F(Dart_ScopeAllocate, uint8_t*, (intptr_t size)) \ - \ -F(Dart_SetBooleanReturnValue, void, (Dart_NativeArguments args, \ - bool retval)) \ - \ -F(Dart_SetDartLibrarySourcesKernel, void, ( \ - const uint8_t* platform_kernel, \ - const intptr_t platform_kernel_size)) \ - \ -F(Dart_SetDoubleReturnValue, void, (Dart_NativeArguments args, \ - double retval)) \ - \ -F(Dart_SetEnvironmentCallback, Dart_Handle, ( \ - Dart_EnvironmentCallback callback)) \ - \ -F(Dart_SetField, Dart_Handle, (Dart_Handle container, \ - Dart_Handle name, \ - Dart_Handle value)) \ - \ -F(Dart_SetIntegerReturnValue, void, (Dart_NativeArguments args, \ - int64_t retval)) \ - \ -F(Dart_SetLibraryTagHandler, Dart_Handle, ( \ - Dart_LibraryTagHandler handler)) \ - \ -F(Dart_SetMessageNotifyCallback, void, ( \ - Dart_MessageNotifyCallback message_notify_callback)) \ - \ -F(Dart_SetNativeInstanceField, Dart_Handle, (Dart_Handle obj, \ - int index, \ - intptr_t value)) \ - \ -F(Dart_SetPausedOnExit, void, (bool paused)) \ - \ -F(Dart_SetPausedOnStart, void, (bool paused)) \ - \ -F(Dart_SetPeer, Dart_Handle, (Dart_Handle object, void* peer)) \ - \ -F(Dart_SetReturnValue, void, (Dart_NativeArguments args, \ - Dart_Handle retval)) \ - \ -F(Dart_SetRootLibrary, Dart_Handle, (Dart_Handle library)) \ - \ -F(Dart_SetShouldPauseOnExit, void, (bool should_pause)) \ - \ -F(Dart_SetShouldPauseOnStart, void, (bool should_pause)) \ - \ -F(Dart_SetStickyError, void, (Dart_Handle error)) \ - \ -F(Dart_SetWeakHandleReturnValue, void, ( \ - Dart_NativeArguments args, \ - Dart_WeakPersistentHandle rval)) \ - \ -F(Dart_ShouldPauseOnExit, bool, ()) \ - \ -F(Dart_ShouldPauseOnStart, bool, ()) \ - \ -F(Dart_WaitForEvent, Dart_Handle, (int64_t timeout_millis)) \ - \ -F(Dart_WriteProfileToTimeline, bool, (Dart_Port main_port, \ - char** error)) \ - \ -F(Dart_ShutdownIsolate, void, ()) \ - \ -F(Dart_StartProfiling, void, ()) \ - \ -F(Dart_StopProfiling, void, ()) \ - \ -F(Dart_StringGetProperties, Dart_Handle, (Dart_Handle str, \ - intptr_t* char_size, \ - intptr_t* str_len, \ - void** peer)) \ - \ -F(Dart_StringLength, Dart_Handle, (Dart_Handle str, \ - intptr_t* length)) \ - \ -F(Dart_StringStorageSize, Dart_Handle, (Dart_Handle str, \ - intptr_t* size)) \ - \ -F(Dart_StringToCString, Dart_Handle, (Dart_Handle str, \ - const char** cstr)) \ - \ -F(Dart_StringToLatin1, Dart_Handle, (Dart_Handle str, \ - uint8_t* latin1_array, \ - intptr_t* length)) \ - \ -F(Dart_StringToUTF16, Dart_Handle, (Dart_Handle str, \ - uint16_t* utf16_array, \ - intptr_t* length)) \ - \ -F(Dart_StringToUTF8, Dart_Handle, (Dart_Handle str, \ - uint8_t** utf8_array, \ - intptr_t* length)) \ - \ -F(Dart_ThreadDisableProfiling, void, ()) \ - \ -F(Dart_ThreadEnableProfiling, void, ()) \ - \ -F(Dart_ThrowException, Dart_Handle, (Dart_Handle exception)) \ - \ -F(Dart_ToString, Dart_Handle, (Dart_Handle object)) \ - \ -F(Dart_True, Dart_Handle, ()) \ - \ -F(Dart_TypedDataAcquireData, Dart_Handle, (Dart_Handle object, \ - Dart_TypedData_Type* type, \ - void** data, \ - intptr_t* len)) \ - \ -F(Dart_TypedDataReleaseData, Dart_Handle, (Dart_Handle object)) \ - \ -F(Dart_TypeDynamic, Dart_Handle, ()) \ - \ -F(Dart_TypeNever, Dart_Handle, ()) \ - \ -F(Dart_TypeToNonNullableType, Dart_Handle, (Dart_Handle type)) \ - \ -F(Dart_TypeToNullableType, Dart_Handle, (Dart_Handle type)) \ - \ -F(Dart_TypeVoid, Dart_Handle, ()) \ - \ -F(Dart_VersionString, const char*, ()) \ - - -#define DART_API_ALL_DL_SYMBOLS(F) \ - DART_NATIVE_API_DL_SYMBOLS(F) \ - DART_API_DL_SYMBOLS(F) -// IMPORTANT! Never update these signatures without properly updating -// DART_API_DL_MAJOR_VERSION and DART_API_DL_MINOR_VERSION. -// -// End of verbatim copy. -// ============================================================================ - -#define DART_API_DL_DECLARATIONS(name, R, A) \ - typedef R(*name##_Type) A; \ - DART_EXTERN name##_Type name##_DL; - -DART_API_ALL_DL_SYMBOLS(DART_API_DL_DECLARATIONS) - -#undef DART_API_DL_DEFINITIONS - -#undef DART_EXTERN - -#endif /* RUNTIME_INCLUDE_DART_API_DL_H_ */ /* NOLINT */ diff --git a/flutter/realm_flutter/android/src/main/cpp/dart_api_dl_impl.h b/flutter/realm_flutter/android/src/main/cpp/dart_api_dl_impl.h deleted file mode 100644 index ad13a4b81..000000000 --- a/flutter/realm_flutter/android/src/main/cpp/dart_api_dl_impl.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file - * for details. All rights reserved. Use of this source code is governed by a - * BSD-style license that can be found in the LICENSE file. - */ - -#ifndef RUNTIME_INCLUDE_INTERNAL_DART_API_DL_IMPL_H_ -#define RUNTIME_INCLUDE_INTERNAL_DART_API_DL_IMPL_H_ - -typedef struct { - const char* name; - void (*function)(); -} DartApiEntry; - -typedef struct { - const int major; - const int minor; - const DartApiEntry* const functions; -} DartApi; - -#endif /* RUNTIME_INCLUDE_INTERNAL_DART_API_DL_IMPL_H_ */ /* NOLINT */ diff --git a/flutter/realm_flutter/android/src/main/cpp/dart_io_extensions.h b/flutter/realm_flutter/android/src/main/cpp/dart_io_extensions.h deleted file mode 100644 index 68a0c1fb3..000000000 --- a/flutter/realm_flutter/android/src/main/cpp/dart_io_extensions.h +++ /dev/null @@ -1,27 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -#ifndef ANDROID_DART_IO_EXTENSIONS_H -#define ANDROID_DART_IO_EXTENSIONS_H - -//#define DART_EXTENSION_EXPORT __attribute__ ((visibility ("default"))) __attribute((used)) - -typedef void (*Dart_ExtensionInitCallback)(); -DART_EXPORT bool Dart_SetInitCallback(Dart_ExtensionInitCallback callback); - -#endif //ANDROID_DART_IO_EXTENSIONS_H diff --git a/flutter/realm_flutter/android/src/main/cpp/dart_version.h b/flutter/realm_flutter/android/src/main/cpp/dart_version.h deleted file mode 100644 index b3b492439..000000000 --- a/flutter/realm_flutter/android/src/main/cpp/dart_version.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file - * for details. All rights reserved. Use of this source code is governed by a - * BSD-style license that can be found in the LICENSE file. - */ - -#ifndef RUNTIME_INCLUDE_DART_VERSION_H_ -#define RUNTIME_INCLUDE_DART_VERSION_H_ - -// On breaking changes the major version is increased. -// On backwards compatible changes the minor version is increased. -// The versioning covers the symbols exposed in dart_api_dl.h -#define DART_API_DL_MAJOR_VERSION 2 -#define DART_API_DL_MINOR_VERSION 0 - -#endif /* RUNTIME_INCLUDE_DART_VERSION_H_ */ /* NOLINT */ diff --git a/flutter/realm_flutter/android/src/main/cpp/realm_flutter.cpp b/flutter/realm_flutter/android/src/main/cpp/realm_flutter.cpp deleted file mode 100644 index 0f1b4eed3..000000000 --- a/flutter/realm_flutter/android/src/main/cpp/realm_flutter.cpp +++ /dev/null @@ -1,167 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include - -#include "dart_api.h" -#include "dart_native_api.h" - -#include "dart_io_extensions.h" -#include "dart_init.hpp" -#include "dart_api_dl.h" - -#include "realm_flutter.h" - -#include -bool initialized = false; -std::string filesDir; -void flutterNativeExtensionDoWork(Dart_NativeArguments arguments) { - __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "flutterNativeExtensionDoWork called"); -} - -Dart_NativeFunction ResolveName(Dart_Handle name, int argc, bool* auto_setup_scope) { - __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "ResolveName called"); - if (!Dart_IsString(name)) { - return NULL; - } - - Dart_NativeFunction result = NULL; - if (auto_setup_scope == NULL) { - return NULL; - } - - const char* cname; - Dart_StringToCString(name, &cname); - __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "ResolveName name: %s", cname); - return flutterNativeExtensionDoWork; - //return NULL; -} - -void init() { - if (initialized) { - __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "init called again. exitting"); - return; - } - - __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "init function called"); - - void* p = (void*)Dart_CurrentIsolate(); - if (p != nullptr) { - __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "Isoleate non null"); - } - else { - __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "Isoleate is null"); - }; - - - //__android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "calling Dart_NewStringFromCString"); -// Dart_Handle res = Dart_NewStringFromCString("package:FlutterNativeExtension"); -// -// __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "Dart_NewStringFromCString finsihed"); -// -// __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "calling Dart_IsError"); -// if (Dart_IsError(res)) { -// __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "Dart_NewStringFromCString returned error"); -// } else { -// __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "Dart_NewStringFromCString returned success"); -// } - - - Dart_Handle realmLibStr = Dart_NewStringFromCString("package:realm/realm.dart"); - auto realmLib = Dart_LookupLibrary(realmLibStr); - if (Dart_IsError(realmLib)) { - __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "Dart_LookupLibrary extension returned error"); - } else { - __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "Dart_LookupLibrary extension returned success. realm.dart library found"); - - - __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "calling realm::dartvm::dart_init"); - realm::dartvm::dart_init(Dart_CurrentIsolate(), realmLib, filesDir); - __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "realm::dartvm::dart_init completed"); - } - - -// print loaded libs -// auto libs = Dart_GetLoadedLibraries(); -// intptr_t len; -// Dart_ListLength(libs, &len); -// for (size_t i = 0; i < len; i++) -// { -// auto lib = Dart_ListGetAt(libs, i); -// auto name = Dart_LibraryResolvedUrl(lib); -// const char* nameStr; -// Dart_StringToCString(name, &nameStr); -// //printf("%s \n", nameStr); -// __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "Dart_LookupLibrary num:%d name: %s", i, nameStr); -// } - - - -// Dart_Handle lib = Dart_LookupLibrary(res); -// if (Dart_IsError(lib)) { -// __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", " Dart_LookupLibrary returned error"); -// auto error = Dart_GetError(lib); -// __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "Dart_LookupLibrary failed: %s", error); -// } else { -// __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", " Dart_LookupLibrary returned success"); -// } - - - //auto rootLib = Dart_RootLibrary(); - - // Dart_Handle result_code = Dart_SetNativeResolver(extensionLib, ResolveName, NULL); - // if (Dart_IsError(result_code)) { - // __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "Dart_SetNativeResolver returned error"); - // auto error = Dart_GetError(result_code); - // __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "Dart_LookupLibrary failed: %s", error); - // } else { - // __android_log_print(ANDROID_LOG_DEBUG, "FlutterNativeExtension", "Dart_SetNativeResolver returned success"); - // } - - initialized = true; -} - -extern "C" JNIEXPORT jstring JNICALL Java_com_blagoev_FlutterNativeExtension_MainActivity_stringFromJNI(JNIEnv* env, jobject /* this */) { - - void* p = (void*)Dart_CurrentIsolate(); - - //bool result = Dart_SetInitCallback(init); - bool result = p != nullptr; - std::string hello = "Hello from C++. Dart_CurrentIsolate returns: " + std::to_string((long long)p); - if (!result) { - hello += " Dart_SetInitCallback SUCCESS"; - } else { - hello += " Dart_SetInitCallback FAIL"; - } - - - return env->NewStringUTF(hello.c_str()); -} - -extern "C" JNIEXPORT void JNICALL Java_io_realm_realm_1flutter_RealmFlutter_native_1initRealm(JNIEnv *env, jobject thiz, jstring fileDir) { - __android_log_print(ANDROID_LOG_DEBUG, "RealmFlutter", "getting filesDir"); - const char* strFileDir = env->GetStringUTFChars(fileDir, NULL); - filesDir = strFileDir; - env->ReleaseStringUTFChars(fileDir, strFileDir); - __android_log_print(ANDROID_LOG_DEBUG, "RealmFlutter", "filesDir: %s", filesDir.c_str()); - - //__android_log_print(ANDROID_LOG_DEBUG, "RealmFlutter", "calling Dart_SetInitCallback"); - //bool result = Dart_SetInitCallback(init); - // __android_log_print(ANDROID_LOG_DEBUG, "RealmFlutter", "Dart_SetInitCallback success"); -} \ No newline at end of file diff --git a/flutter/realm_flutter/android/src/main/cpp/realm_flutter.h b/flutter/realm_flutter/android/src/main/cpp/realm_flutter.h deleted file mode 100644 index a7ec3fb41..000000000 --- a/flutter/realm_flutter/android/src/main/cpp/realm_flutter.h +++ /dev/null @@ -1,479 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2021 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -#ifndef ANDROID_REALM_FLUTTER_H -#define ANDROID_REALM_FLUTTER_H - -#include "dart_api_dl.h" - -#define Dart_PostCObject Dart_PostCObject_DL - -#define Dart_PostInteger Dart_PostInteger_DL - -#define Dart_NewNativePort Dart_NewNativePort_DL - -#define Dart_CloseNativePort Dart_CloseNativePort_DL - -#define Dart_IsError Dart_IsError_DL - -#define Dart_IsApiError Dart_IsApiError_DL - -#define Dart_IsUnhandledExceptionError Dart_IsUnhandledExceptionError_DL - -#define Dart_IsCompilationError Dart_IsCompilationError_DL - -#define Dart_IsFatalError Dart_IsFatalError_DL - -#define Dart_GetError Dart_GetError_DL - -#define Dart_ErrorHasException Dart_ErrorHasException_DL - -#define Dart_ErrorGetException Dart_ErrorGetException_DL - -#define Dart_ErrorGetStackTrace Dart_ErrorGetStackTrace_DL - -#define Dart_NewApiError Dart_NewApiError_DL - -#define Dart_NewCompilationError Dart_NewCompilationError_DL - -#define Dart_NewUnhandledExceptionError Dart_NewUnhandledExceptionError_DL - -#define Dart_PropagateError Dart_PropagateError_DL - -#define Dart_ToString Dart_ToString_DL - -#define Dart_IdentityEquals Dart_IdentityEquals_DL - -#define Dart_HandleFromPersistent Dart_HandleFromPersistent_DL - -#define Dart_HandleFromWeakPersistent Dart_HandleFromWeakPersistent_DL - -#define Dart_NewPersistentHandle Dart_NewPersistentHandle_DL - -#define Dart_SetPersistentHandle Dart_SetPersistentHandle_DL - -#define Dart_DeletePersistentHandle Dart_DeletePersistentHandle_DL - -#define Dart_NewWeakPersistentHandle Dart_NewWeakPersistentHandle_DL - -#define Dart_DeleteWeakPersistentHandle Dart_DeleteWeakPersistentHandle_DL - -#define Dart_Post Dart_Post_DL - -#define Dart_NewSendPort Dart_NewSendPort_DL - -#define Dart_SendPortGetId Dart_SendPortGetId_DL - -#define Dart_EnterScope Dart_EnterScope_DL - -#define Dart_ExitScope Dart_ExitScope_DL - - - - - - - - - - - - - -#define Dart_Allocate Dart_Allocate_DL - -#define Dart_AllocateWithNativeFields Dart_AllocateWithNativeFields_DL - -#define Dart_BooleanValue Dart_BooleanValue_DL - -#define Dart_ClassLibrary Dart_ClassLibrary_DL - -#define Dart_ClassName Dart_ClassName_DL - -#define Dart_Cleanup Dart_Cleanup_DL - -#define Dart_ClosureFunction Dart_ClosureFunction_DL - -#define Dart_CreateIsolateGroup Dart_CreateIsolateGroup_DL - -#define Dart_CreateIsolateGroupFromKernel Dart_CreateIsolateGroupFromKernel_DL - -#define Dart_CurrentIsolate Dart_CurrentIsolate_DL - -#define Dart_CurrentIsolateData Dart_CurrentIsolateData_DL - -#define Dart_CurrentIsolateGroup Dart_CurrentIsolateGroup_DL - -#define Dart_CurrentIsolateGroupData Dart_CurrentIsolateGroupData_DL - -#define Dart_DebugName Dart_DebugName_DL - -#define Dart_DoubleValue Dart_DoubleValue_DL - -#define Dart_DumpNativeStackTrace Dart_DumpNativeStackTrace_DL - -#define Dart_EmptyString Dart_EmptyString_DL - -#define Dart_EnterIsolate Dart_EnterIsolate_DL - -#define Dart_ExitIsolate Dart_ExitIsolate_DL - -#define Dart_False Dart_False_DL - -#define Dart_FunctionIsStatic Dart_FunctionIsStatic_DL - -#define Dart_FunctionName Dart_FunctionName_DL - -#define Dart_FunctionOwner Dart_FunctionOwner_DL - -#define Dart_GetClass Dart_GetClass_DL - -#define Dart_GetDataFromByteBuffer Dart_GetDataFromByteBuffer_DL - -#define Dart_GetField Dart_GetField_DL - -#define Dart_GetImportsOfScheme Dart_GetImportsOfScheme_DL - -#define Dart_GetLoadedLibraries Dart_GetLoadedLibraries_DL - -#define Dart_GetMessageNotifyCallback Dart_GetMessageNotifyCallback_DL - -#define Dart_GetNativeArguments Dart_GetNativeArguments_DL - -#define Dart_GetNativeArgument Dart_GetNativeArgument_DL - -#define Dart_GetNativeBooleanArgument Dart_GetNativeBooleanArgument_DL - -#define Dart_GetNativeDoubleArgument Dart_GetNativeDoubleArgument_DL - -#define Dart_GetNativeArgumentCount Dart_GetNativeArgumentCount_DL - -#define Dart_GetNativeFieldsOfArgument Dart_GetNativeFieldsOfArgument_DL - -#define Dart_GetNativeInstanceField Dart_GetNativeInstanceField_DL - -#define Dart_GetNativeInstanceFieldCount Dart_GetNativeInstanceFieldCount_DL - -#define Dart_GetNativeIntegerArgument Dart_GetNativeIntegerArgument_DL - -#define Dart_GetNativeIsolateGroupData Dart_GetNativeIsolateGroupData_DL - -#define Dart_GetNativeResolver Dart_GetNativeResolver_DL - -#define Dart_SetNativeResolver Dart_SetNativeResolver_DL - -#define Dart_GetNativeStringArgument Dart_GetNativeStringArgument_DL - -#define Dart_GetNativeSymbol Dart_GetNativeSymbol_DL - -#define Dart_GetNonNullableType Dart_GetNonNullableType_DL - -#define Dart_GetNullableType Dart_GetNullableType_DL - -#define Dart_GetPeer Dart_GetPeer_DL - -#define Dart_GetStaticMethodClosure Dart_GetStaticMethodClosure_DL - -#define Dart_GetStickyError Dart_GetStickyError_DL - -#define Dart_GetType Dart_GetType_DL - -#define Dart_GetTypeOfExternalTypedData Dart_GetTypeOfExternalTypedData_DL - -#define Dart_GetTypeOfTypedData Dart_GetTypeOfTypedData_DL - -#define Dart_HasStickyError Dart_HasStickyError_DL - -#define Dart_IdentityEquals Dart_IdentityEquals_DL - -#define Dart_InstanceGetType Dart_InstanceGetType_DL - -#define Dart_IntegerFitsIntoInt64 Dart_IntegerFitsIntoInt64_DL - -#define Dart_IntegerFitsIntoUint64 Dart_IntegerFitsIntoUint64_DL - -#define Dart_IntegerToHexCString Dart_IntegerToHexCString_DL - -#define Dart_IntegerToInt64 Dart_IntegerToInt64_DL - -#define Dart_IntegerToUint64 Dart_IntegerToUint64_DL - -#define Dart_Invoke Dart_Invoke_DL - - -#define Dart_InvokeClosure Dart_InvokeClosure_DL - -#define Dart_InvokeConstructor Dart_InvokeConstructor_DL - -#define Dart_IsBoolean Dart_IsBoolean_DL - -#define Dart_IsByteBuffer Dart_IsByteBuffer_DL - -#define Dart_IsClosure Dart_IsClosure_DL - -#define Dart_IsDouble Dart_IsDouble_DL - -#define Dart_IsExternalString Dart_IsExternalString_DL - -#define Dart_IsFunction Dart_IsFunction_DL - -#define Dart_IsFuture Dart_IsFuture_DL - -#define Dart_IsInstance Dart_IsInstance_DL - -#define Dart_IsInteger Dart_IsInteger_DL - -#define Dart_IsKernel Dart_IsKernel_DL - -#define Dart_IsKernelIsolate Dart_IsKernelIsolate_DL - -#define Dart_IsLegacyType Dart_IsLegacyType_DL - -#define Dart_IsLibrary Dart_IsLibrary_DL - -#define Dart_IsList Dart_IsList_DL - -#define Dart_IsMap Dart_IsMap_DL - -#define Dart_IsNonNullableType Dart_IsNonNullableType_DL - -#define Dart_IsNull Dart_IsNull_DL - -#define Dart_IsNumber Dart_IsNumber_DL - -#define Dart_IsolateData Dart_IsolateData_DL - -#define Dart_IsolateFlagsInitialize Dart_IsolateFlagsInitialize_DL - -#define Dart_IsolateGroupData Dart_IsolateGroupData_DL - -#define Dart_IsolateMakeRunnable Dart_IsolateMakeRunnable_DL - -#define Dart_IsolateServiceId Dart_IsolateServiceId_DL - -#define Dart_IsPausedOnExit Dart_IsPausedOnExit_DL - -#define Dart_IsPausedOnStart Dart_IsPausedOnStart_DL - -#define Dart_IsPrecompiledRuntime Dart_IsPrecompiledRuntime_DL - -#define Dart_IsServiceIsolate Dart_IsServiceIsolate_DL - -#define Dart_IsString Dart_IsString_DL - -#define Dart_IsStringLatin1 Dart_IsStringLatin1_DL - -#define Dart_IsTearOff Dart_IsTearOff_DL - -#define Dart_IsType Dart_IsType_DL - -#define Dart_IsTypedData Dart_IsTypedData_DL - -#define Dart_IsTypeVariable Dart_IsTypeVariable_DL - -#define Dart_IsVariable Dart_IsVariable_DL - -#define Dart_IsVMFlagSet Dart_IsVMFlagSet_DL - -#define Dart_KernelIsolateIsRunning Dart_KernelIsolateIsRunning_DL - -#define Dart_KernelListDependencies Dart_KernelListDependencies_DL - -#define Dart_KernelPort Dart_KernelPort_DL - -#define Dart_KillIsolate Dart_KillIsolate_DL - -#define Dart_LibraryHandleError Dart_LibraryHandleError_DL - -#define Dart_LibraryResolvedUrl Dart_LibraryResolvedUrl_DL - -#define Dart_LibraryUrl Dart_LibraryUrl_DL - -#define Dart_ListGetAsBytes Dart_ListGetAsBytes_DL - -#define Dart_ListGetAt Dart_ListGetAt_DL - -#define Dart_ListGetRange Dart_ListGetRange_DL - -#define Dart_ListLength Dart_ListLength_DL - -#define Dart_ListSetAsBytes Dart_ListSetAsBytes_DL - -#define Dart_ListSetAt Dart_ListSetAt_DL - -#define Dart_LoadLibraryFromKernel Dart_LoadLibraryFromKernel_DL - -#define Dart_LoadScriptFromKernel Dart_LoadScriptFromKernel_DL - -#define Dart_LookupLibrary Dart_LookupLibrary_DL - -#define Dart_MapContainsKey Dart_MapContainsKey_DL - -#define Dart_MapGetAt Dart_MapGetAt_DL - -#define Dart_MapKeys Dart_MapKeys_DL - -#define Dart_New Dart_New_DL - -#define Dart_NewBoolean Dart_NewBoolean_DL - -#define Dart_NewByteBuffer Dart_NewByteBuffer_DL - -#define Dart_NewDouble Dart_NewDouble_DL - -#define Dart_NewExternalLatin1String Dart_NewExternalLatin1String_DL - -#define Dart_NewExternalTypedData Dart_NewExternalTypedData_DL - -#define Dart_NewExternalTypedDataWithFinalizer Dart_NewExternalTypedDataWithFinalizer_DL - -#define Dart_NewExternalUTF16String Dart_NewExternalUTF16String_DL - -#define Dart_NewInteger Dart_NewInteger_DL - -#define Dart_NewIntegerFromHexCString Dart_NewIntegerFromHexCString_DL - -#define Dart_NewIntegerFromUint64 Dart_NewIntegerFromUint64_DL - -#define Dart_NewList Dart_NewList_DL - -#define Dart_NewListOf Dart_NewListOf_DL - -#define Dart_NewListOfType Dart_NewListOfType_DL - -#define Dart_NewListOfTypeFilled Dart_NewListOfTypeFilled_DL - -#define Dart_NewStringFromCString Dart_NewStringFromCString_DL - -#define Dart_NewStringFromUTF16 Dart_NewStringFromUTF16_DL - -#define Dart_NewStringFromUTF32 Dart_NewStringFromUTF32_DL - -#define Dart_NewStringFromUTF8 Dart_NewStringFromUTF8_DL - -#define Dart_NewTypedData Dart_NewTypedData_DL - -#define Dart_NotifyIdle Dart_NotifyIdle_DL - -#define Dart_NotifyLowMemory Dart_NotifyLowMemory_DL - -#define Dart_Null Dart_Null_DL - -#define Dart_ObjectEquals Dart_ObjectEquals_DL - -#define Dart_ObjectIsType Dart_ObjectIsType_DL - -#define Dart_PrepareToAbort Dart_PrepareToAbort_DL - -#define Dart_ReThrowException Dart_ReThrowException_DL - -#define Dart_RootLibrary Dart_RootLibrary_DL - -#define Dart_ScopeAllocate Dart_ScopeAllocate_DL - -#define Dart_SetBooleanReturnValue Dart_SetBooleanReturnValue_DL - -#define Dart_SetDartLibrarySourcesKernel Dart_SetDartLibrarySourcesKernel_DL - -#define Dart_SetDoubleReturnValue Dart_SetDoubleReturnValue_DL - -#define Dart_SetEnvironmentCallback Dart_SetEnvironmentCallback_DL - -#define Dart_SetField Dart_SetField_DL - -#define Dart_SetIntegerReturnValue Dart_SetIntegerReturnValue_DL - -#define Dart_SetLibraryTagHandler Dart_SetLibraryTagHandler_DL - -#define Dart_SetMessageNotifyCallback Dart_SetMessageNotifyCallback_DL - -#define Dart_SetNativeInstanceField Dart_SetNativeInstanceField_DL - -#define Dart_SetPausedOnExit Dart_SetPausedOnExit_DL - -#define Dart_SetPausedOnStart Dart_SetPausedOnStart_DL - -#define Dart_SetPeer Dart_SetPeer_DL - -#define Dart_SetReturnValue Dart_SetReturnValue_DL - -#define Dart_SetRootLibrary Dart_SetRootLibrary_DL - -#define Dart_SetShouldPauseOnExit Dart_SetShouldPauseOnExit_DL - -#define Dart_SetShouldPauseOnStart Dart_SetShouldPauseOnStart_DL - -#define Dart_SetStickyError Dart_SetStickyError_DL - -#define Dart_SetWeakHandleReturnValue Dart_SetWeakHandleReturnValue_DL - -#define Dart_ShouldPauseOnExit Dart_ShouldPauseOnExit_DL - -#define Dart_ShouldPauseOnStart Dart_ShouldPauseOnStart_DL - -#define Dart_WaitForEvent Dart_WaitForEvent_DL - -#define Dart_WriteProfileToTimeline Dart_WriteProfileToTimeline_DL - -#define Dart_ShutdownIsolate Dart_ShutdownIsolate_DL - -#define Dart_StartProfiling Dart_StartProfiling_DL - -#define Dart_StopProfiling Dart_StopProfiling_DL - -#define Dart_StringGetProperties Dart_StringGetProperties_DL - -#define Dart_StringLength Dart_StringLength_DL - -#define Dart_StringStorageSize Dart_StringStorageSize_DL - -#define Dart_StringToCString Dart_StringToCString_DL - -#define Dart_StringToLatin1 Dart_StringToLatin1_DL - -#define Dart_StringToUTF16 Dart_StringToUTF16_DL - -#define Dart_StringToUTF8 Dart_StringToUTF8_DL - -#define Dart_ThreadDisableProfiling Dart_ThreadDisableProfiling_DL - -#define Dart_ThreadEnableProfiling Dart_ThreadEnableProfiling_DL - -#define Dart_ThrowException Dart_ThrowException_DL - -#define Dart_ToString Dart_ToString_DL - -#define Dart_True Dart_True_DL - -#define Dart_TypedDataAcquireData Dart_TypedDataAcquireData_DL - -#define Dart_TypedDataReleaseData Dart_TypedDataReleaseData_DL - -#define Dart_TypeDynamic Dart_TypeDynamic_DL - -#define Dart_TypeNever Dart_TypeNever_DL - -#define Dart_TypeToNonNullableType Dart_TypeToNonNullableType_DL - -#define Dart_TypeToNullableType Dart_TypeToNullableType_DL - -#define Dart_TypeVoid Dart_TypeVoid_DL - -#define Dart_VersionString Dart_VersionString_DL - -#endif //ANDROID_REALM_FLUTTER_H diff --git a/flutter/realm_flutter/android/src/main/java/io/realm/RealmPlugin.java b/flutter/realm_flutter/android/src/main/java/io/realm/RealmPlugin.java index 85b513b5b..680b85f8a 100644 --- a/flutter/realm_flutter/android/src/main/java/io/realm/RealmPlugin.java +++ b/flutter/realm_flutter/android/src/main/java/io/realm/RealmPlugin.java @@ -24,6 +24,7 @@ import java.io.IOException; import android.util.Log; +import io.flutter.BuildConfig; import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; @@ -31,7 +32,7 @@ import io.flutter.plugin.common.MethodChannel.Result; public class RealmPlugin implements FlutterPlugin, MethodCallHandler { - private static native void native_initRealm(String filesDir, String deviceName, String deviceVersion); + private static native void native_initRealm(String filesDir, String deviceName, String deviceVersion, String bundleId); public static void initRealm(Context context) { String filesDir; @@ -41,7 +42,8 @@ public static void initRealm(Context context) { throw new IllegalStateException(e); } - native_initRealm(filesDir, android.os.Build.MANUFACTURER, android.os.Build.MODEL); + // RealmConfig is generated on build and located at {appDir}/build/realm-generated/RealmConfig.java + native_initRealm(filesDir, android.os.Build.MANUFACTURER, android.os.Build.MODEL, RealmConfig.bundleId); } /// The MethodChannel that will the communication between Flutter and native Android diff --git a/flutter/realm_flutter/example/android/build.gradle b/flutter/realm_flutter/example/android/build.gradle index 622ddc5c1..60a43fdeb 100644 --- a/flutter/realm_flutter/example/android/build.gradle +++ b/flutter/realm_flutter/example/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:7.3.0' } } @@ -22,6 +22,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/flutter/realm_flutter/example/android/gradle/wrapper/gradle-wrapper.properties b/flutter/realm_flutter/example/android/gradle/wrapper/gradle-wrapper.properties index bc6a58afd..cfe88f690 100644 --- a/flutter/realm_flutter/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/flutter/realm_flutter/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip diff --git a/flutter/realm_flutter/tests/android/build.gradle b/flutter/realm_flutter/tests/android/build.gradle index b48e07b8e..4342a3f24 100644 --- a/flutter/realm_flutter/tests/android/build.gradle +++ b/flutter/realm_flutter/tests/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:7.3.0' } } @@ -28,6 +28,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/flutter/realm_flutter/tests/android/gradle.properties b/flutter/realm_flutter/tests/android/gradle.properties index 94adc3a3f..a4e1f1a4e 100644 --- a/flutter/realm_flutter/tests/android/gradle.properties +++ b/flutter/realm_flutter/tests/android/gradle.properties @@ -1,3 +1,4 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true +android.native.buildOutput=verbose diff --git a/flutter/realm_flutter/tests/android/gradle/wrapper/gradle-wrapper.properties b/flutter/realm_flutter/tests/android/gradle/wrapper/gradle-wrapper.properties index bc6a58afd..6b665338b 100644 --- a/flutter/realm_flutter/tests/android/gradle/wrapper/gradle-wrapper.properties +++ b/flutter/realm_flutter/tests/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip diff --git a/flutter/realm_flutter/windows/CMakeLists.txt b/flutter/realm_flutter/windows/CMakeLists.txt index 1150445e6..9efe07dd3 100644 --- a/flutter/realm_flutter/windows/CMakeLists.txt +++ b/flutter/realm_flutter/windows/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.19) +cmake_minimum_required(VERSION 3.10) set(PROJECT_NAME "realm") project(${PROJECT_NAME} LANGUAGES CXX) diff --git a/flutter/realm_flutter/windows/realm_plugin.cpp b/flutter/realm_flutter/windows/realm_plugin.cpp index 575f263af..0fc31ec27 100644 --- a/flutter/realm_flutter/windows/realm_plugin.cpp +++ b/flutter/realm_flutter/windows/realm_plugin.cpp @@ -24,7 +24,6 @@ #define BUNDLE_ID "realm_bundle_id" #endif - // #pragma message("APP_DIR_NAME is " _CRT_STRINGIZE(APP_DIR_NAME)) namespace @@ -45,7 +44,6 @@ class RealmPlugin : public flutter::Plugin std::unique_ptr> result); }; -// static void RealmPlugin::RegisterWithRegistrar(flutter::PluginRegistrarWindows* registrar) { //TODO: Remove 'channel' variable if not needed https://github.com/realm/realm-dart/issues/694 diff --git a/lib/src/native/realm_bindings.dart b/lib/src/native/realm_bindings.dart index f32f0a751..293cca09b 100644 --- a/lib/src/native/realm_bindings.dart +++ b/lib/src/native/realm_bindings.dart @@ -3440,6 +3440,16 @@ class RealmLibrary { _realm_dart_delete_persistent_handlePtr .asFunction)>(); + ffi.Pointer realm_dart_get_bundle_id() { + return _realm_dart_get_bundle_id(); + } + + late final _realm_dart_get_bundle_idPtr = + _lookup Function()>>( + 'realm_dart_get_bundle_id'); + late final _realm_dart_get_bundle_id = _realm_dart_get_bundle_idPtr + .asFunction Function()>(); + ffi.Pointer realm_dart_get_device_name() { return _realm_dart_get_device_name(); } @@ -10871,6 +10881,8 @@ class _SymbolAddresses { ffi.Pointer)>> get realm_dart_delete_persistent_handle => _library._realm_dart_delete_persistent_handlePtr; + ffi.Pointer Function()>> + get realm_dart_get_bundle_id => _library._realm_dart_get_bundle_idPtr; ffi.Pointer Function()>> get realm_dart_get_device_name => _library._realm_dart_get_device_namePtr; ffi.Pointer Function()>> diff --git a/lib/src/native/realm_core.dart b/lib/src/native/realm_core.dart index c3b08d7d8..fb10229c5 100644 --- a/lib/src/native/realm_core.dart +++ b/lib/src/native/realm_core.dart @@ -2265,6 +2265,8 @@ class _RealmCore { final getBundleIdFunc1 = DynamicLibrary.executable().lookupFunction Function(), Pointer Function()>("realm_dart_get_bundle_id"); final bundleIdPtr = getBundleIdFunc1(); return bundleIdPtr.cast().toDartString(); + } else if(Platform.isAndroid) { + return _realmLib.realm_dart_get_bundle_id().cast().toDartString(); } final getBundleIdFunc = _pluginLib.lookupFunction Function(), Pointer Function()>("realm_dart_get_bundle_id"); diff --git a/src/android/platform.cpp b/src/android/platform.cpp index e3202948a..64638a24e 100644 --- a/src/android/platform.cpp +++ b/src/android/platform.cpp @@ -25,8 +25,9 @@ static std::string mFilesDir; static std::string mDeviceName; static std::string mDeviceVersion; +static std::string mBundleId; -extern "C" JNIEXPORT void Java_io_realm_RealmPlugin_native_1initRealm(JNIEnv *env, jobject thiz, jstring filesDir, jstring deviceName, jstring deviceVersion) { +extern "C" JNIEXPORT void Java_io_realm_RealmPlugin_native_1initRealm(JNIEnv * env, jobject thiz, jstring filesDir, jstring deviceName, jstring deviceVersion, jstring bundleId) { const char* strFilesDir = env->GetStringUTFChars(filesDir, NULL); mFilesDir = std::string(strFilesDir); env->ReleaseStringUTFChars(filesDir, strFilesDir); @@ -34,10 +35,14 @@ extern "C" JNIEXPORT void Java_io_realm_RealmPlugin_native_1initRealm(JNIEnv *en const char* strDeviceName = env->GetStringUTFChars(deviceName, NULL); mDeviceName = std::string(strDeviceName); env->ReleaseStringUTFChars(deviceName, strDeviceName); - + const char* strDeviceVersion = env->GetStringUTFChars(deviceVersion, NULL); mDeviceVersion = std::string(strDeviceVersion); env->ReleaseStringUTFChars(deviceVersion, strDeviceVersion); + + const char* strBundleId = env->GetStringUTFChars(bundleId, NULL); + mBundleId = std::string(strBundleId); + env->ReleaseStringUTFChars(bundleId, strBundleId); } extern "C" JNIEXPORT const char* realm_dart_get_files_path() { @@ -51,3 +56,7 @@ extern "C" JNIEXPORT const char* realm_dart_get_device_name() { extern "C" JNIEXPORT const char* realm_dart_get_device_version() { return mDeviceVersion.c_str(); } + +extern "C" JNIEXPORT const char* realm_dart_get_bundle_id() { + return mBundleId.c_str(); +} diff --git a/src/android/platform.h b/src/android/platform.h index b3417662a..de924759d 100644 --- a/src/android/platform.h +++ b/src/android/platform.h @@ -18,5 +18,5 @@ #ifndef FFI_GEN #include -extern "C" JNIEXPORT void Java_io_realm_RealmPlugin_native_1initRealm(JNIEnv *env, jobject thiz, jstring filesDir, jstring deviceName, jstring deviceVersion); +extern "C" JNIEXPORT void Java_io_realm_RealmPlugin_native_1initRealm(JNIEnv *env, jobject thiz, jstring filesDir, jstring deviceName, jstring deviceVersion, jstring bundleId); #endif diff --git a/src/realm_dart.h b/src/realm_dart.h index 2c7152e6e..1f43b2fa1 100644 --- a/src/realm_dart.h +++ b/src/realm_dart.h @@ -36,6 +36,9 @@ RLM_API const char* realm_dart_get_files_path(); RLM_API const char* realm_dart_get_device_name(); RLM_API const char* realm_dart_get_device_version(); +// implemented for Android only +RLM_API const char* realm_dart_get_bundle_id(); + RLM_API const char* realm_get_library_cpu_arch(); typedef struct realm_dart_userdata_async* realm_dart_userdata_async_t; From 543409a146d9c17b5176887eac9a178c61dba4fd Mon Sep 17 00:00:00 2001 From: blagoev Date: Sun, 11 Jun 2023 12:11:28 +0300 Subject: [PATCH 05/13] switch to java 11 on ci bump agp version --- .github/workflows/ci.yml | 6 +++ flutter/realm_flutter/android/build.gradle | 50 +++++++------------ .../android/src/main/cpp/CMakeLists.txt | 32 ++---------- .../android/src/main/cpp/realm_plugin.cpp | 2 + .../realm_flutter/windows/realm_plugin.cpp | 1 - 5 files changed, 29 insertions(+), 62 deletions(-) create mode 100644 flutter/realm_flutter/android/src/main/cpp/realm_plugin.cpp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bee4987aa..b0fbe4f26 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -494,6 +494,12 @@ jobs: with: submodules: 'recursive' + - name: Set up Java + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: 11 + - name: Fetch artifacts uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 with: diff --git a/flutter/realm_flutter/android/build.gradle b/flutter/realm_flutter/android/build.gradle index d760696a4..0302168ab 100644 --- a/flutter/realm_flutter/android/build.gradle +++ b/flutter/realm_flutter/android/build.gradle @@ -4,18 +4,18 @@ version '1.0' buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.2.0' + classpath 'com.android.tools.build:gradle:7.3.0' } } rootProject.allprojects { repositories { google() - jcenter() + mavenCentral() } } @@ -44,22 +44,12 @@ android { disable 'InvalidPackage' } - // externalNativeBuild { - // // cmake { - // // arguments "COMPILE_DEFINITIONS-DBUNDLE_ID=lubo" - // // } - -// externalNativeBuild { -// cmake { -// path "src/main/cpp/CMakeLists.txt" -// } -// } - - // externalNativeBuild { - // // ndkBuild { - // // path 'src/main/cpp/Android.mk' - // // } - // } + //We don't need native build for now. This will enable it. + //externalNativeBuild { + // cmake { + // path "src/main/cpp/CMakeLists.txt" + // } + //} } def getPaths() { @@ -85,7 +75,7 @@ def getPaths() { return [flutterRoot, flutterExecutablePath] } -task runMetrics(type: Exec) { +tasks.register("runMetrics", Exec) { outputs.upToDateWhen { false } try { @@ -102,11 +92,11 @@ task runMetrics(type: Exec) { commandLine flutterExecutablePath, 'pub', 'run', 'realm', 'metrics', '--flutter-root', flutterRoot, '--target-os-type', 'android', '--target-os-version', targetOsVersion } catch (e) { - println "Error running metrics command $e" + logger.error "Error running metrics command $e" } } -task downloadRealmBinaries(type: Exec) { +tasks.register("downloadRealmBinaries", Exec) { outputs.upToDateWhen { false } def (flutterRoot, flutterExecutablePath) = getPaths() @@ -117,26 +107,26 @@ task downloadRealmBinaries(type: Exec) { def getBundleId() { try { def pubSpecFilePath = "${project.rootProject.projectDir}${File.separator}..${File.separator}pubspec.yaml" - //println "pubSpecFilePath is ${pubSpecFilePath}" + logger.info "pubSpecFilePath is ${pubSpecFilePath}" def pubspecFile = new File("${project.rootProject.projectDir}${File.separator}..${File.separator}pubspec.yaml") if (pubspecFile.exists()) { def contents = pubspecFile.text - //println contents + logger.info contents def matches = contents =~ /name:[ \r\n\t]*([a-z0-9_]*)/ def bundleId = matches[0][1] - //println "bundleId is ${bundleId}" + logger.info "bundleId is ${bundleId}" return bundleId } } catch (e) { - println "Error getting bundle id $e" + logger.error "Error getting bundle id $e" } //fallback value - return project.rootProject.name; + return "realm_bundle_id"; } -task generateRealmConfig(type: Copy) { +tasks.register("generateRealmConfig", Copy) { outputs.upToDateWhen { false } def bundleId = getBundleId(); @@ -145,8 +135,4 @@ task generateRealmConfig(type: Copy) { filter { line -> line.replaceAll('realm_bundle_id', "${bundleId}") } } -//task printProjectTasks { -// project.getAllTasks(false).each { key, value -> value.each { task -> println("task=${task} dependsOn=${task.dependsOn}") } } -//} - preBuild.dependsOn runMetrics, downloadRealmBinaries, generateRealmConfig \ No newline at end of file diff --git a/flutter/realm_flutter/android/src/main/cpp/CMakeLists.txt b/flutter/realm_flutter/android/src/main/cpp/CMakeLists.txt index f2287a32d..170f74e8a 100644 --- a/flutter/realm_flutter/android/src/main/cpp/CMakeLists.txt +++ b/flutter/realm_flutter/android/src/main/cpp/CMakeLists.txt @@ -5,15 +5,12 @@ project(${PROJECT_NAME} LANGUAGES CXX) set(PLUGIN_NAME "realm_plugin") +#make cmake output visible in build log file set(CMAKE_VERBOSE_MAKEFILE TRUE CACHE BOOL "" FORCE) add_library(${PLUGIN_NAME} SHARED "realm_plugin.cpp") -set(APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../..") -message("APP_DIR is ${APP_DIR}") -message("PROJECT_SOURCE_DIR is ${PROJECT_SOURCE_DIR}") - - +# print cmake variables #function(print_directory_variables dir) # # Dump variables: # get_property(_variableNames DIRECTORY ${dir} PROPERTY VARIABLES) @@ -24,27 +21,4 @@ message("PROJECT_SOURCE_DIR is ${PROJECT_SOURCE_DIR}") # endforeach() #endfunction(print_directory_variables) # -#print_directory_variables(.) - -# execute_process(COMMAND "echo" -# OUTPUT_VARIABLE output -# RESULT_VARIABLE result -# COMMAND_ERROR_IS_FATAL ANY -# ) - -# set(APP_PUBSPEC_FILE "${APP_DIR}/pubspec.yaml") -# # message ("APP_PUBSPEC_FILE is ${APP_PUBSPEC_FILE}") -# file(READ "${APP_PUBSPEC_FILE}" PUBSPEC_CONTENT) -# string(REGEX MATCH "name:[ \r\n\t]*([a-z0-9_]*)" _ ${PUBSPEC_CONTENT}) -# # message ("Pubspec name 0 is ${CMAKE_MATCH_0}") -# # message ("Package name is ${CMAKE_MATCH_1}") -# set(APP_DIR_NAME ${CMAKE_MATCH_1}) -# set(BUNDLE_ID ${CMAKE_MATCH_1}) -# # string(ASCII 114, 101, 97, 108, 109, 32, 105, 115, 32, 103, 114, 101, 97, 116 PREFIX) -# # string(PREPEND BUNDLE_ID ${PREFIX}) -# # message ("BUNDLE_ID is ${BUNDLE_ID}") -# # string(SHA256 ) - -# #message ("BINARY_NAME is ${BINARY_NAME}") -# add_definitions(-DAPP_DIR_NAME="${APP_DIR_NAME}") -# add_definitions(-DBUNDLE_ID="${BUNDLE_ID}") \ No newline at end of file +#print_directory_variables(.) \ No newline at end of file diff --git a/flutter/realm_flutter/android/src/main/cpp/realm_plugin.cpp b/flutter/realm_flutter/android/src/main/cpp/realm_plugin.cpp new file mode 100644 index 000000000..16dc4b765 --- /dev/null +++ b/flutter/realm_flutter/android/src/main/cpp/realm_plugin.cpp @@ -0,0 +1,2 @@ +#include + diff --git a/flutter/realm_flutter/windows/realm_plugin.cpp b/flutter/realm_flutter/windows/realm_plugin.cpp index 0fc31ec27..87da7ab15 100644 --- a/flutter/realm_flutter/windows/realm_plugin.cpp +++ b/flutter/realm_flutter/windows/realm_plugin.cpp @@ -14,7 +14,6 @@ #include #include -#include #ifndef APP_DIR_NAME #define APP_DIR_NAME "realm_app" From a0acbb5659306f30f47dd41b582909c72ce2a3d3 Mon Sep 17 00:00:00 2001 From: blagoev Date: Sun, 11 Jun 2023 12:30:44 +0300 Subject: [PATCH 06/13] refactor getBundleId --- flutter/realm_flutter/macos/Classes/platform.mm | 10 ---------- flutter/realm_flutter/windows/CMakeLists.txt | 5 ----- lib/src/native/realm_core.dart | 11 ++++++----- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/flutter/realm_flutter/macos/Classes/platform.mm b/flutter/realm_flutter/macos/Classes/platform.mm index 3a92593b3..90d7acfa5 100644 --- a/flutter/realm_flutter/macos/Classes/platform.mm +++ b/flutter/realm_flutter/macos/Classes/platform.mm @@ -35,16 +35,6 @@ return filesDir.c_str(); } - -// std::string get_app_bundle_id() -// { -// std::string ret; -// @autoreleasepool { -// NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; -// ret = bundleId.UTF8String; -// return ret; -// } -// } RLM_API const char* realm_dart_get_bundle_id() { return bundleId.c_str(); diff --git a/flutter/realm_flutter/windows/CMakeLists.txt b/flutter/realm_flutter/windows/CMakeLists.txt index 9efe07dd3..01aeda434 100644 --- a/flutter/realm_flutter/windows/CMakeLists.txt +++ b/flutter/realm_flutter/windows/CMakeLists.txt @@ -39,12 +39,7 @@ string(REGEX MATCH "name:[ \r\n\t]*([a-z0-9_]*)" _ ${PUBSPEC_CONTENT}) # message ("Package name is ${CMAKE_MATCH_1}") set(APP_DIR_NAME ${CMAKE_MATCH_1}) set(BUNDLE_ID ${CMAKE_MATCH_1}) -# string(ASCII 114, 101, 97, 108, 109, 32, 105, 115, 32, 103, 114, 101, 97, 116 PREFIX) -# string(PREPEND BUNDLE_ID ${PREFIX}) -# message ("BUNDLE_ID is ${BUNDLE_ID}") -# string(SHA256 ) -#message ("BINARY_NAME is ${BINARY_NAME}") add_definitions(-DAPP_DIR_NAME="${APP_DIR_NAME}") add_definitions(-DBUNDLE_ID="${BUNDLE_ID}") diff --git a/lib/src/native/realm_core.dart b/lib/src/native/realm_core.dart index fb10229c5..bb12e45de 100644 --- a/lib/src/native/realm_core.dart +++ b/lib/src/native/realm_core.dart @@ -69,6 +69,10 @@ final _pluginLib = () { throw UnsupportedError("Realm plugin library used outside Flutter"); } + if (Platform.isIOS) { + return DynamicLibrary.executable(); + } + String plugin = Platform.isWindows ? 'realm_plugin.dll' : Platform.isMacOS @@ -2261,11 +2265,8 @@ class _RealmCore { String getBundleId() { assert(isFlutterPlatform); - if (Platform.isIOS) { - final getBundleIdFunc1 = DynamicLibrary.executable().lookupFunction Function(), Pointer Function()>("realm_dart_get_bundle_id"); - final bundleIdPtr = getBundleIdFunc1(); - return bundleIdPtr.cast().toDartString(); - } else if(Platform.isAndroid) { + + if(Platform.isAndroid) { return _realmLib.realm_dart_get_bundle_id().cast().toDartString(); } From 8694b471787a182534ee3d7c6c8b55f42f2e857d Mon Sep 17 00:00:00 2001 From: blagoev Date: Sun, 11 Jun 2023 12:59:06 +0300 Subject: [PATCH 07/13] fix name --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0fbe4f26..a013e2a38 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -672,7 +672,7 @@ jobs: run: echo ${{ steps.publish-coverage.outputs.coveralls-api-result }} slack-on-failure: - name: Slack on failure in main + name: Report failure in main branch needs: - cleanup-dart-matrix - cleanup-flutter-matrix From 06db6ad610360beb00c64529fcb65a34d096df39 Mon Sep 17 00:00:00 2001 From: blagoev Date: Sun, 11 Jun 2023 13:14:19 +0300 Subject: [PATCH 08/13] fix bundleid test --- test/app_test.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/app_test.dart b/test/app_test.dart index e8446162c..8a16227e4 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -300,10 +300,12 @@ Future main([List? args]) async { ); }); - test('bundle', () { - if (isFlutterPlatform) { - print("The bundle id is '${realmCore.getBundleId()}'"); + test('Test bundleId', () { + if (!isFlutterPlatform) { + return; } + + expect(realmCore.getBundleId(), "realm_tests"); }); } From e7f8682b21b34207ff7a46ea250a0c33d0858b63 Mon Sep 17 00:00:00 2001 From: blagoev Date: Sun, 11 Jun 2023 13:28:27 +0300 Subject: [PATCH 09/13] fix cmake on linukst --- flutter/realm_flutter/linux/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flutter/realm_flutter/linux/CMakeLists.txt b/flutter/realm_flutter/linux/CMakeLists.txt index 46f485099..fda78fa0d 100644 --- a/flutter/realm_flutter/linux/CMakeLists.txt +++ b/flutter/realm_flutter/linux/CMakeLists.txt @@ -45,6 +45,9 @@ string(REGEX MATCH "name:[ \r\n\t]*([a-z0-9_]*)" _ ${PUBSPEC_CONTENT}) # message ("Package name is ${CMAKE_MATCH_1}") set(BUNDLE_ID ${CMAKE_MATCH_1}) +add_definitions(-DAPP_DIR_NAME="${APP_DIR_NAME}") +add_definitions(-DBUNDLE_ID="${BUNDLE_ID}") + # message ("FLUTTER_TOOL_ENVIRONMENT is ${FLUTTER_TOOL_ENVIRONMENT}") # message ("FLUTTER_ROOT is ${FLUTTER_ROOT}") From 4992a8a89f76665a90c46226fd377a0b33d41bcc Mon Sep 17 00:00:00 2001 From: blagoev Date: Sun, 11 Jun 2023 13:47:50 +0300 Subject: [PATCH 10/13] fix linux cmake --- flutter/realm_flutter/linux/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/flutter/realm_flutter/linux/CMakeLists.txt b/flutter/realm_flutter/linux/CMakeLists.txt index fda78fa0d..8a0694e98 100644 --- a/flutter/realm_flutter/linux/CMakeLists.txt +++ b/flutter/realm_flutter/linux/CMakeLists.txt @@ -27,8 +27,6 @@ set(realm_bundled_libraries # message ("PROJECT_SOURCE_DIR is ${PROJECT_SOURCE_DIR}") # message ("CMAKE_CURRENT_SOURCE_DIR is ${CMAKE_CURRENT_SOURCE_DIR}") -add_definitions(-DAPP_DIR_NAME="${APPLICATION_ID}") - # This works cause realm plugin is always accessed through the .plugin_symlinks directory. set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../ephemeral") include(${EPHEMERAL_DIR}/generated_config.cmake) @@ -45,7 +43,7 @@ string(REGEX MATCH "name:[ \r\n\t]*([a-z0-9_]*)" _ ${PUBSPEC_CONTENT}) # message ("Package name is ${CMAKE_MATCH_1}") set(BUNDLE_ID ${CMAKE_MATCH_1}) -add_definitions(-DAPP_DIR_NAME="${APP_DIR_NAME}") +add_definitions(-DAPP_DIR_NAME="${APPLICATION_ID}") add_definitions(-DBUNDLE_ID="${BUNDLE_ID}") From 510e8f7f0debc6a69b3247b07ba8ac923f356d98 Mon Sep 17 00:00:00 2001 From: blagoev Date: Sun, 11 Jun 2023 14:54:04 +0300 Subject: [PATCH 11/13] add bundleid to Dart --- example/bin/myapp.dart | 4 +++- example/pubspec.yaml | 2 +- lib/src/cli/metrics/metrics_command.dart | 5 +--- lib/src/native/realm_core.dart | 30 ++++++++++++++++++------ test/app_test.dart | 6 +---- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/example/bin/myapp.dart b/example/bin/myapp.dart index 3aef1615f..e0667d54c 100644 --- a/example/bin/myapp.dart +++ b/example/bin/myapp.dart @@ -62,6 +62,8 @@ void main(List arguments) async { await Future.delayed(Duration(milliseconds: 1)); realm.close(); - + + //This is only needed in Dart apps as a workaround for https://github.com/dart-lang/sdk/issues/49083 + Realm.shutdown(); print("Done"); } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 02c699f88..2fd8cfeca 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,4 +1,4 @@ -name: realm_dart_example +name: myapp description: A simple command-line application using Realm Dart SDK. publish_to: none diff --git a/lib/src/cli/metrics/metrics_command.dart b/lib/src/cli/metrics/metrics_command.dart index a474f0579..04b1c046a 100644 --- a/lib/src/cli/metrics/metrics_command.dart +++ b/lib/src/cli/metrics/metrics_command.dart @@ -73,10 +73,7 @@ Future uploadMetrics(Options options) async { var skipUpload = (isRealmCI || Platform.environment['CI'] != null || Platform.environment['REALM_DISABLE_ANALYTICS'] != null || - pubspec.name == "realm_tests" || - pubspec.name == "realm_example" || - pubspec.name == "realm_dart_example" || - pubspec.name == "realm_generator") && + Directory.current.absolute.path.contains("realm-dart")) && Platform.environment['REALM_DEBUG_ANALYTICS'] == null; if (skipUpload) { // skip early and don't do any work diff --git a/lib/src/native/realm_core.dart b/lib/src/native/realm_core.dart index bb12e45de..98275329e 100644 --- a/lib/src/native/realm_core.dart +++ b/lib/src/native/realm_core.dart @@ -23,6 +23,7 @@ import 'dart:ffi'; import 'dart:io'; import 'dart:typed_data'; +import 'package:pubspec_parse/pubspec_parse.dart'; import 'package:cancellation_token/cancellation_token.dart'; // Hide StringUtf8Pointer.toNativeUtf8 and StringUtf16Pointer since these allows silently allocating memory. Use toUtf8Ptr instead import 'package:ffi/ffi.dart' hide StringUtf8Pointer, StringUtf16Pointer; @@ -2264,15 +2265,30 @@ class _RealmCore { } String getBundleId() { - assert(isFlutterPlatform); - - if(Platform.isAndroid) { - return _realmLib.realm_dart_get_bundle_id().cast().toDartString(); + try { + if (!isFlutterPlatform) { + var pubspecPath = path.join(path.current, 'pubspec.yaml'); + var pubspecFile = File(pubspecPath); + + if (pubspecFile.existsSync()) { + final pubspec = Pubspec.parse(pubspecFile.readAsStringSync()); + return pubspec.name; + } + } + + if (Platform.isAndroid) { + return _realmLib.realm_dart_get_bundle_id().cast().toDartString(); + } + + final getBundleIdFunc = _pluginLib.lookupFunction Function(), Pointer Function()>("realm_dart_get_bundle_id"); + final bundleIdPtr = getBundleIdFunc(); + return bundleIdPtr.cast().toDartString(); + } on Exception catch (_) { + //Never fail on bundleId. Use fallback value. } - final getBundleIdFunc = _pluginLib.lookupFunction Function(), Pointer Function()>("realm_dart_get_bundle_id"); - final bundleIdPtr = getBundleIdFunc(); - return bundleIdPtr.cast().toDartString(); + //Fallback value + return "realm_bundle_id"; } String _getAppDirectoryFromPlugin() { diff --git a/test/app_test.dart b/test/app_test.dart index 8a16227e4..cfeb33f1b 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -301,11 +301,7 @@ Future main([List? args]) async { }); test('Test bundleId', () { - if (!isFlutterPlatform) { - return; - } - - expect(realmCore.getBundleId(), "realm_tests"); + expect(realmCore.getBundleId(), isFlutterPlatform ? "realm_tests" : "realm_dart"); }); } From 29e6bb59f6b10567adda76db8566e958151fd9b7 Mon Sep 17 00:00:00 2001 From: blagoev Date: Sun, 11 Jun 2023 15:20:29 +0300 Subject: [PATCH 12/13] do set app bundle id. anonymize bundle id --- lib/src/native/realm_core.dart | 47 ++++++++++++++++++++-------------- test/app_test.dart | 12 ++++++--- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/lib/src/native/realm_core.dart b/lib/src/native/realm_core.dart index 98275329e..50bf84db0 100644 --- a/lib/src/native/realm_core.dart +++ b/lib/src/native/realm_core.dart @@ -23,6 +23,7 @@ import 'dart:ffi'; import 'dart:io'; import 'dart:typed_data'; +import 'package:crypto/crypto.dart'; import 'package:pubspec_parse/pubspec_parse.dart'; import 'package:cancellation_token/cancellation_token.dart'; // Hide StringUtf8Pointer.toNativeUtf8 and StringUtf16Pointer since these allows silently allocating memory. Use toUtf8Ptr instead @@ -1528,6 +1529,8 @@ class _RealmCore { _realmLib.realm_app_config_set_default_request_timeout(handle._pointer, configuration.defaultRequestTimeout.inMilliseconds); + _realmLib.realm_app_config_set_bundle_id(handle._pointer, getBundleId().toCharPtr(arena)); + if (configuration.localAppName != null) { _realmLib.realm_app_config_set_local_app_name(handle._pointer, configuration.localAppName!.toCharPtr(arena)); } else { @@ -2265,30 +2268,36 @@ class _RealmCore { } String getBundleId() { - try { - if (!isFlutterPlatform) { - var pubspecPath = path.join(path.current, 'pubspec.yaml'); - var pubspecFile = File(pubspecPath); + readBundleId () { + try { + if (!isFlutterPlatform) { + var pubspecPath = path.join(path.current, 'pubspec.yaml'); + var pubspecFile = File(pubspecPath); - if (pubspecFile.existsSync()) { - final pubspec = Pubspec.parse(pubspecFile.readAsStringSync()); - return pubspec.name; + if (pubspecFile.existsSync()) { + final pubspec = Pubspec.parse(pubspecFile.readAsStringSync()); + return pubspec.name; + } } - } - if (Platform.isAndroid) { - return _realmLib.realm_dart_get_bundle_id().cast().toDartString(); - } + if (Platform.isAndroid) { + return _realmLib.realm_dart_get_bundle_id().cast().toDartString(); + } - final getBundleIdFunc = _pluginLib.lookupFunction Function(), Pointer Function()>("realm_dart_get_bundle_id"); - final bundleIdPtr = getBundleIdFunc(); - return bundleIdPtr.cast().toDartString(); - } on Exception catch (_) { - //Never fail on bundleId. Use fallback value. - } + final getBundleIdFunc = _pluginLib.lookupFunction Function(), Pointer Function()>("realm_dart_get_bundle_id"); + final bundleIdPtr = getBundleIdFunc(); + return bundleIdPtr.cast().toDartString(); + } on Exception catch (_) { + //Never fail on bundleId. Use fallback value. + } - //Fallback value - return "realm_bundle_id"; + //Fallback value + return "realm_bundle_id"; + }; + + String bundleId = readBundleId(); + const salt = [82, 101, 97, 108, 109, 32, 105, 115, 32, 103, 114, 101, 97, 116]; + return base64Encode(sha256.convert([...salt, ...utf8.encode(bundleId)]).bytes); } String _getAppDirectoryFromPlugin() { diff --git a/test/app_test.dart b/test/app_test.dart index cfeb33f1b..2c92b4752 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -20,6 +20,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:test/expect.dart' hide throws; import 'package:path/path.dart' as path; +import 'package:crypto/crypto.dart'; import '../lib/realm.dart'; import '../lib/src/native/realm_core.dart'; @@ -253,8 +254,8 @@ Future main([List? args]) async { final dynamic response = await user.functions.call('userFuncTwoArgs', [arg1.toJson(), arg2.toJson()]); expect(response, isNotNull); final map = response as Map; - final receivedPerson1 = PersonJ.fromJson(map['arg1'] as Map); - final receivedPerson2 = PersonJ.fromJson(map['arg2'] as Map); + final receivedPerson1 = PersonExt.fromJson(map['arg1'] as Map); + final receivedPerson2 = PersonExt.fromJson(map['arg2'] as Map); expect(receivedPerson1.name, arg1.name); expect(receivedPerson2.name, arg2.name); }); @@ -301,11 +302,14 @@ Future main([List? args]) async { }); test('Test bundleId', () { - expect(realmCore.getBundleId(), isFlutterPlatform ? "realm_tests" : "realm_dart"); + final text = isFlutterPlatform ? "realm_tests" : "realm_dart"; + const salt = [82, 101, 97, 108, 109, 32, 105, 115, 32, 103, 114, 101, 97, 116]; + final expected = base64Encode(sha256.convert([...salt, ...utf8.encode(text)]).bytes); + expect(realmCore.getBundleId(), expected); }); } -extension PersonJ on Person { +extension PersonExt on Person { static Person fromJson(Map json) => Person(json['name'] as String); Map toJson() => {'name': name}; } From 730670a7783cf02f018ee9535f8153782ef47616 Mon Sep 17 00:00:00 2001 From: blagoev Date: Sun, 11 Jun 2023 15:54:00 +0300 Subject: [PATCH 13/13] fixes --- src/android/platform.cpp | 2 +- src/android/platform.h | 2 +- test/app_test.dart | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/android/platform.cpp b/src/android/platform.cpp index 64638a24e..79254e534 100644 --- a/src/android/platform.cpp +++ b/src/android/platform.cpp @@ -27,7 +27,7 @@ static std::string mDeviceName; static std::string mDeviceVersion; static std::string mBundleId; -extern "C" JNIEXPORT void Java_io_realm_RealmPlugin_native_1initRealm(JNIEnv * env, jobject thiz, jstring filesDir, jstring deviceName, jstring deviceVersion, jstring bundleId) { +extern "C" JNIEXPORT void Java_io_realm_RealmPlugin_native_1initRealm(JNIEnv* env, jobject thiz, jstring filesDir, jstring deviceName, jstring deviceVersion, jstring bundleId) { const char* strFilesDir = env->GetStringUTFChars(filesDir, NULL); mFilesDir = std::string(strFilesDir); env->ReleaseStringUTFChars(filesDir, strFilesDir); diff --git a/src/android/platform.h b/src/android/platform.h index de924759d..4afedf023 100644 --- a/src/android/platform.h +++ b/src/android/platform.h @@ -18,5 +18,5 @@ #ifndef FFI_GEN #include -extern "C" JNIEXPORT void Java_io_realm_RealmPlugin_native_1initRealm(JNIEnv *env, jobject thiz, jstring filesDir, jstring deviceName, jstring deviceVersion, jstring bundleId); +extern "C" JNIEXPORT void Java_io_realm_RealmPlugin_native_1initRealm(JNIEnv* env, jobject thiz, jstring filesDir, jstring deviceName, jstring deviceVersion, jstring bundleId); #endif diff --git a/test/app_test.dart b/test/app_test.dart index 2c92b4752..9c6445d5b 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -301,7 +301,7 @@ Future main([List? args]) async { ); }); - test('Test bundleId', () { + test('bundleId is salted, hashed and encoded', () { final text = isFlutterPlatform ? "realm_tests" : "realm_dart"; const salt = [82, 101, 97, 108, 109, 32, 105, 115, 32, 103, 114, 101, 97, 116]; final expected = base64Encode(sha256.convert([...salt, ...utf8.encode(text)]).bytes);