diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 075a3e0..b07ad26 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -23,9 +23,8 @@ "C:/Users/ekibun/AppData/Local/Android/Sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include" ], "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE" + "__ANDROID__", + "__LINUX__" ], "windowsSdkVersion": "10.0.18362.0", "compilerPath": "C:/Users/ekibun/AppData/Local/Android/Sdk/cmake/3.10.2.4988404/bin/cmake.exe", @@ -41,9 +40,7 @@ "/usr/include/**" ], "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE" + "__LINUX__" ], "windowsSdkVersion": "10.0.18362.0", "compilerPath": "/usr/bin/clang++", diff --git a/CHANGELOG.md b/CHANGELOG.md index 58b5fcc..d24048f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,12 @@ * @Author: ekibun * @Date: 2020-08-08 08:16:50 * @LastEditors: ekibun - * @LastEditTime: 2020-08-25 18:12:51 + * @LastEditTime: 2020-08-26 23:37:16 --> +## 0.0.4 + +* remove C++ std limitation for linux and android. + ## 0.0.3 * fix js memory leak. diff --git a/README.md b/README.md index 297044f..3baca3b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ * @Author: ekibun * @Date: 2020-08-08 08:16:50 * @LastEditors: ekibun - * @LastEditTime: 2020-08-20 13:58:47 + * @LastEditTime: 2020-08-26 23:02:05 --> # flutter_qjs @@ -76,6 +76,3 @@ try { ``` [This example](example/lib/test.dart) contains a complete demonstration on how to use this plugin. - -**notice:** -To use this plugin in Linux desktop application, you must change `cxx_std_14` to `cxx_std_17` in your project's `CMakeLists.txt`. \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index cb0ede2..1043ba8 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -33,11 +33,6 @@ android { } defaultConfig { minSdkVersion 16 - externalNativeBuild { - cmake { - cppFlags "-std=c++17" - } - } } lintOptions { disable 'InvalidPackage' @@ -45,12 +40,12 @@ android { kotlinOptions { jvmTarget = "1.8" } - externalNativeBuild { - cmake { - path "src/main/jni/CMakeLists.txt" - version "3.10.2" - } - } + externalNativeBuild { + cmake { + path "src/main/jni/CMakeLists.txt" + version "3.10.2" + } + } } dependencies { diff --git a/android/src/main/jni/CMakeLists.txt b/android/src/main/jni/CMakeLists.txt index 137e5a0..d79bbfb 100644 --- a/android/src/main/jni/CMakeLists.txt +++ b/android/src/main/jni/CMakeLists.txt @@ -30,6 +30,7 @@ target_sources(${JNI_LIB_NAME} PUBLIC ${QUICK_JS_LIB_DIR}/libunicode.c ${QUICK_JS_LIB_DIR}/quickjs.c ) +target_compile_features(${JNI_LIB_NAME} PUBLIC cxx_std_17) # Searches for a specified prebuilt library and stores the path as a # variable. Because CMake includes system libraries in the search path by diff --git a/android/src/main/kotlin/soko/ekibun/flutter_qjs/FlutterQjsPlugin.kt b/android/src/main/kotlin/soko/ekibun/flutter_qjs/FlutterQjsPlugin.kt index da55b5c..0eaa2cf 100644 --- a/android/src/main/kotlin/soko/ekibun/flutter_qjs/FlutterQjsPlugin.kt +++ b/android/src/main/kotlin/soko/ekibun/flutter_qjs/FlutterQjsPlugin.kt @@ -29,7 +29,6 @@ class FlutterQjsPlugin: FlutterPlugin, MethodCallHandler { override fun onMethodCall(call: MethodCall, result: Result) { if (call.method == "createEngine") { val engine: Long = JniBridge.instance.createEngine(channelwrapper) - println(engine) result.success(engine) } else if (call.method == "evaluate") { val engine: Long = call.argument("engine")!! @@ -43,7 +42,6 @@ class FlutterQjsPlugin: FlutterPlugin, MethodCallHandler { JniBridge.instance.call(engine, function, args, ResultWrapper(handler, result)) } else if (call.method == "close") { val engine: Long = call.arguments() - println(engine) JniBridge.instance.close(engine) result.success(null) } else { diff --git a/cxx/js_engine.hpp b/cxx/js_engine.hpp index 5441e56..e02d423 100644 --- a/cxx/js_engine.hpp +++ b/cxx/js_engine.hpp @@ -3,7 +3,7 @@ * @Author: ekibun * @Date: 2020-08-08 10:30:59 * @LastEditors: ekibun - * @LastEditTime: 2020-08-20 11:11:30 + * @LastEditTime: 2020-08-26 23:35:20 */ #pragma once @@ -53,7 +53,8 @@ namespace qjs void handleException(qjs::Value exc) { - std::cout << getStackTrack(exc) << std::endl; + printf("%s", getStackTrack(exc).c_str()); + std::cout << std::endl; } public: @@ -125,7 +126,7 @@ namespace qjs if (err <= 0) { if (err < 0) - std::cout << getStackTrack(ctx.getException()) << std::endl; + handleException(ctx.getException()); break; } } diff --git a/cxx/quickjs/quickjs.c b/cxx/quickjs/quickjs.c index 441e2c5..0a5af12 100644 --- a/cxx/quickjs/quickjs.c +++ b/cxx/quickjs/quickjs.c @@ -37,12 +37,6 @@ #include #endif -#if defined(__ANDROID__) -#include -#undef printf -#define printf(...) __android_log_print(ANDROID_LOG_INFO, "qjs", __VA_ARGS__) -#endif - #ifdef _MSC_VER #include @@ -1704,7 +1698,7 @@ static inline size_t js_def_malloc_usable_size(void *ptr) return malloc_size(ptr); #elif defined(_WIN32) return _msize(ptr); -#elif defined(EMSCRIPTEN) +#elif defined(EMSCRIPTEN) || defined(__ANDROID__) return 0; #elif defined(__linux__) return malloc_usable_size(ptr); @@ -1778,7 +1772,7 @@ static const JSMallocFunctions def_malloc_funcs = { malloc_size, #elif defined(_WIN32) (size_t (*)(const void *))_msize, -#elif defined(EMSCRIPTEN) +#elif defined(EMSCRIPTEN) || defined(__ANDROID__) NULL, #elif defined(__linux__) (size_t (*)(const void *))malloc_usable_size, diff --git a/cxx/quickjs/quickjs.h b/cxx/quickjs/quickjs.h index 335e1cc..461ca17 100644 --- a/cxx/quickjs/quickjs.h +++ b/cxx/quickjs/quickjs.h @@ -28,6 +28,11 @@ #include #include +#if defined(__ANDROID__) +#include +#define printf(...) __android_log_print(ANDROID_LOG_INFO, "qjs", __VA_ARGS__) +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/example/android/.project b/example/android/.project deleted file mode 100644 index 3964dd3..0000000 --- a/example/android/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - android - Project android created by Buildship. - - - - - org.eclipse.buildship.core.gradleprojectbuilder - - - - - - org.eclipse.buildship.core.gradleprojectnature - - diff --git a/example/android/.settings/org.eclipse.buildship.core.prefs b/example/android/.settings/org.eclipse.buildship.core.prefs deleted file mode 100644 index 3bee8f2..0000000 --- a/example/android/.settings/org.eclipse.buildship.core.prefs +++ /dev/null @@ -1,13 +0,0 @@ -arguments= -auto.sync=false -build.scans.enabled=false -connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) -connection.project.dir= -eclipse.preferences.version=1 -gradle.user.home= -java.home=C\:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2019.3.2/jbr -jvm.arguments= -offline.mode=false -override.workspace.settings=true -show.console.view=true -show.executions.view=true diff --git a/example/android/app/.classpath b/example/android/app/.classpath deleted file mode 100644 index 4a04201..0000000 --- a/example/android/app/.classpath +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/example/android/app/.project b/example/android/app/.project deleted file mode 100644 index ac485d7..0000000 --- a/example/android/app/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - app - Project app created by Buildship. - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.buildship.core.gradleprojectbuilder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.buildship.core.gradleprojectnature - - diff --git a/example/android/app/.settings/org.eclipse.buildship.core.prefs b/example/android/app/.settings/org.eclipse.buildship.core.prefs deleted file mode 100644 index b1886ad..0000000 --- a/example/android/app/.settings/org.eclipse.buildship.core.prefs +++ /dev/null @@ -1,2 +0,0 @@ -connection.project.dir=.. -eclipse.preferences.version=1 diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 8917303..9be3f1f 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 28 + compileSdkVersion 29 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -40,7 +40,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "soko.ekibun.example" minSdkVersion 16 - targetSdkVersion 28 + targetSdkVersion 29 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } diff --git a/example/android/app/src/main/kotlin/soko/ekibun/flutter_qjs_example/MainActivity.kt b/example/android/app/src/main/kotlin/soko/ekibun/flutter_qjs_example/MainActivity.kt deleted file mode 100644 index 1449f1f..0000000 --- a/example/android/app/src/main/kotlin/soko/ekibun/flutter_qjs_example/MainActivity.kt +++ /dev/null @@ -1,6 +0,0 @@ -package soko.ekibun.flutter_qjs_example - -import io.flutter.embedding.android.FlutterActivity - -class MainActivity: FlutterActivity() { -} diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 38c8d45..a673820 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,4 +1,4 @@ org.gradle.jvmargs=-Xmx1536M -android.enableR8=true android.useAndroidX=true android.enableJetifier=true +android.enableR8=true diff --git a/example/linux/CMakeLists.txt b/example/linux/CMakeLists.txt index 0795bcc..9fc26d8 100644 --- a/example/linux/CMakeLists.txt +++ b/example/linux/CMakeLists.txt @@ -18,7 +18,7 @@ endif() # Compilation settings that should be applied to most targets. function(APPLY_STANDARD_SETTINGS TARGET) - target_compile_features(${TARGET} PUBLIC cxx_std_17) + target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") diff --git a/example/pubspec.lock b/example/pubspec.lock index 053897a..b1839d1 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -75,7 +75,7 @@ packages: path: ".." relative: true source: path - version: "0.0.3" + version: "0.0.4" flutter_test: dependency: "direct dev" description: flutter diff --git a/lib/flutter_qjs.dart b/lib/flutter_qjs.dart index 01a5cc7..7f8bd8b 100644 --- a/lib/flutter_qjs.dart +++ b/lib/flutter_qjs.dart @@ -3,7 +3,7 @@ * @Author: ekibun * @Date: 2020-08-08 08:29:09 * @LastEditors: ekibun - * @LastEditTime: 2020-08-20 14:43:40 + * @LastEditTime: 2020-08-26 23:11:10 */ import 'dart:async'; import 'dart:io'; @@ -24,7 +24,6 @@ class FlutterJs { _ensureEngine() async { if (_engine == null) { _engine = await _FlutterJs.instance._channel.invokeMethod("createEngine"); - print(_engine); } } diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index 805d99b..9fb8aaf 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -22,6 +22,7 @@ add_library(${PLUGIN_NAME} SHARED ) apply_standard_settings(${PLUGIN_NAME}) +target_compile_features(${PLUGIN_NAME} PUBLIC cxx_std_17) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) diff --git a/pubspec.yaml b/pubspec.yaml index badaf17..cf435dd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_qjs description: This plugin is a simple js engine for flutter using the `quickjs` project. Plugin currently supports Windows, Linux, and Android. -version: 0.0.3 +version: 0.0.4 homepage: https://github.com/ekibun/flutter_qjs environment: