libmx3 / mx3 Goto Github PK
View Code? Open in Web Editor NEWa sample project showcasing/collecting cross platform techniques on mobile
License: MIT License
a sample project showcasing/collecting cross platform techniques on mobile
License: MIT License
This would be a good example of a third party lib too complex for gyp, that is also pretty generally applicable.
Api constructor run twice if i invoke post of thread in hanle class.I don't know why!can you tell me?i really need your help.
How do c++ call java in the demo for Djinni?
Has anyone experimented with different options for an ORM to sit on top of SQLite?
Callback java method from C++ thread failed all the time!why?can you tell me?
Callback java method is OK.But when i create a thread and callback a method of java at interval.The APP crashed all the time.And i don't know why.I really need your help!
So at my company we've developed at shared c++ library for our mobile apps and we modeled our projects after this libmx3 example and similar projects, but wanted to ask about how you guys set up the repos. Do you have the android and ios project repos as submodules of the repo containing the c++ code, or is there a good way to keep them separate but easily updatable? If they're submodules or folders in the main repo holding the c++ code as well, then do the mobile devs need to work in the main c++ repo? I tried to do a little research on this and it seems like it's best to keep the repos next to each other, but it seems more natural to have the c++ library stuff as a submodule of the mobile projects, however that doesn't seem possible with this current setup. Any thoughts or advice you can share?
Thanks!
when I run make play
at directory root this error appears:
> Could not GET 'https://plugins.gradle.org/api/gradle/2.3/plugin/use/com.github.jlouns.cpe/0.1.0'.
> peer not authenticated
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.```
how can I fix this? thanks in advance.
We've setup the database and stuff but we should probably hit an API, persist it and view it in a list view.
Any ideas how to do it?
➜ mx3 git:(develop) make android
./run_djinni.sh
Already up to date: Djinni
Parsing...
Resolving...
Generating...
Copying generated code to final directories...
djinni completed.
ANDROID_BUILD_TOP=dirname deps/gyp/gyp --depth=. -f android -DOS=android --root-target libmx3_android -Icommon.gypi mx3.gyp
Usage: gyp_main.py [options ...] [build_file ...]
gyp_main.py: error: no such option: --root-target
make: *** [GypAndroid.mk] Error 2
i also upgrade gyp node-gyp and installed build-essential python-dev but it make no change to this error could you guys help me
It looks like m_ui_thread thread is not attached to the JNI environment at (djinni_support.cpp:48)/.
const jint get_res = g_cachedJVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
returns -2 (JNI_EDETACHED)
********** Crash dump: **********
Build fingerprint: 'google/occam/mako:4.3/JWR66Y/776638:user/release-keys'
pid: 19194, tid: 19207, name: com.mx3 >>> com.mx3 <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
Stack frame #00 pc 0001e348 /system/lib/libc.so
Stack frame #1 pc 0001c510 /system/lib/libc.so (abort+4)
Stack frame #2 pc 00013e87 /data/app-lib/com.mx3-1/libmx3_android.so: Routine djinni::jniGetThreadEnv() at mx3/example_android/app/../../deps/djinni/support-lib/jni/djinni_support.cpp:48
Stack frame #3 pc 00012d57 /data/app-lib/com.mx3-1/libmx3_android.so: Routine djinni_generated::NativeEventLoop::JavaProxy::post(std::shared_ptr<mx3_gen::AsyncTask> const&) at mx3/example_android/app/../../android/jni_gen/native_event_loop.cpp:14
This isn't so much of an issue as a suggestion for a pattern. I ran across this repo: https://github.com/mattstevens/xcode-googletest. He enumerates the gtest cases into XCTest cases, which enables the tests to be controlled via the test interface in Xcode. This allows for a pretty sweet test-driven workflow for library development.
Gyp won't generate a test bundle as far as I can see, so what I've done is create a test project that includes the test cases and this runner class. I set up gyp to make my library produce a framework, which the test bundle cleanly links to.
This setup is still a little finnicky - sometimes the test cases show up in the test interface in xcode, sometimes not. But I still like it a lot better than relying strictly on gtest's command line output. If anyone experiments with this and can find a way to make this a reliable pattern, please post!
make android
is failing with below error:
[x86_64] Compile++ : mx3_android <= native_api.cpp
../../deps/sqlite3/sqlite3.c: In function 'sqlite3TempInMemory':
../../deps/sqlite3/sqlite3.c:121876:55: error: unused parameter 'db' [-Werror=unused-parameter]
SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3 *db){
^
[mips64] Compile++ : mx3_android <= jni_main.cpp
../../deps/sqlite3/sqlite3.c: In function 'sqlite3TempInMemory':
../../deps/sqlite3/sqlite3.c:121876:55: error: unused parameter 'db' [-Werror=unused-parameter]
SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3 *db){
^
[armeabi] Compile++ thumb: mx3_android <= native_api.cpp
../../deps/sqlite3/sqlite3.c: In function 'sqlite3TempInMemory':
../../deps/sqlite3/sqlite3.c:121876:55: error: unused parameter 'db' [-Werror=unused-parameter]
SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3 *db){
^
../../deps/sqlite3/sqlite3.c: At top level:
cc1: error: unrecognized command line option "-Wno-unused-const-variable" [-Werror]
cc1: all warnings being treated as errors
SQLITE_TEMP_STORE=3 define is triggering the unused parameter warning which -Werror is forcing as error. Wno-unused-const-variable is unrecognized. As a workaround, I tried removing -Werror from common.gypi and was able to build successfully but with unused parameter warnings.
Hi, this is really a good design, but since on iOS, UI can only be updated in main thread, is there any way we can back to main thread from network thread to update UI in C++ layer, or should iOS/Android handles the main thread themselves (in Objective-C and Java layer) ?
There's a gyp generator for creating a MS Visual Studio project, but I can't test / verify that without a copy of windows. halp
Currently i am trying to develop crossplatform mobile library with visual studio 2015.
I am investigating your sources.
My question is that following function makes shared_ptr map and creates CppProxy of java from jni,
But why do you make it WeakReference. what happen you just do jniEnv->NewObject alone?
Android Java new does not work as WeakReference?
It is rather Java question than jni.
/static/ jobject JniCppProxyCache::get(const std::shared_ptr & cppObj,
JNIEnv * jniEnv,
const CppProxyClassInfo & proxyClass,
jobject (*factory)(const std::shared_ptr &,
JNIEnv *,
const CppProxyClassInfo &))
{
CppProxyCacheState & st = CppProxyCacheState::get();
const std::lock_guardstd::mutex lock(st.mtx);
auto it = st.m.find(cppObj.get());
if (it != st.m.end())
{
// It's in the map. See if the WeakReference still points to an object.
if (jobject javaObj = it->second.get(jniEnv))
{
return javaObj;
}
else
{
// The WeakReference is expired, so prune it from the map eagerly.
st.m.erase(it);
}
}
jobject wrapper = factory(cppObj, jniEnv, proxyClass);
/* Make a Java WeakRef object */
st.m.emplace(cppObj.get(), JavaWeakRef(jniEnv, wrapper));
return wrapper;
}
I'm trying to build this project with yosemite.
I run
git submodule update --init
make play
i get this error
xcodebuild -project build_mac/mx3.xcodeproj -configuration Debug -target play_objc | xcpretty -c && ./build/Debug/play_objc
▸ Building mx3/libmx3_objc [Debug]
⌦ There is no SDK with the name or path '/Users/tchheng/src/crossplatform/mx3/deps/macosx10.8'
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
/bin/sh: ./build/Debug/play_objc: No such file or directory
make: *** [play] Error 127
I'm in the process of building a production app based on these techniques, and as I do so I'm wondering - is this a reasonable place to share war stories and exchange tips? Steven, was that your intent in creating this project? As an example, I'm currently struggling mightily with attaching ndk-gdb to my Android app. That's not exactly in the domain of this source project, but I'd love to participate in a community of people trying to make native C++ development great on mobile.
It would be great to have a pattern for integrating prebuilt static libraries. Sometimes there are libraries where the configuration and build scripts are complex and not easily convertible to gyp. Pointing to them is a problem especially for Android, for which there will be multiple copies of the binary for the different target architectures.
I've received the following error:
* What went wrong:
Execution failed for task ':app:preBuild'.
> failed to find Build Tools revision 21.1.1
By means of the Android Maintenance Tool it's not possible to install that revision.
The 21.1.2 is the only one available. I'm working on with the sdk for linux 64 bit.
Still working through understanding all that is going on in the examples and came across a comment
"// todo(kabbes) this isn't thread safe" in UserListVmHandle::_notify_new_data()
Could anyone shed light on what is not thread safe here?
Sorry for the very basic question. I like the idea of mx3 and would like to experiment with it for a POC for a client. If I already have two existing POCs completed for iOS and Android that I'd like to integrate this in to is there a way to do that or should I just build a new project and then reintegrate my UI code? I'm thinking the latter is the best way to go since the make would overwrite the current Android and iOS dirs?
I was literally lost trying to write that stuff. I got one working, but its pretty terrible as far as examples go.
I'm try make android
from untouched example, Here's what I got so far.
Gradle 2.3
Android SDK Tools 21.1.2
Android Build Tools 22
./gradlew djinni
:djinniBuild UP-TO-DATE
:djinniGen UP-TO-DATE
:djinniOutSyncCpp UP-TO-DATE
:djinniOutSyncJava UP-TO-DATE
:djinniOutSyncJni UP-TO-DATE
:djinniOutSyncObjc UP-TO-DATE
:djinniOutSync UP-TO-DATE
:djinni UP-TO-DATE
BUILD SUCCESSFUL
Total time: 3.82 secs
ANDROID_BUILD_TOP=dirname deps/gyp/gyp --depth=. -f android -DOS=android --root-target libmx3_android -Icommon.gypi mx3.gyp
cd example_android && ./gradlew app:assembleDebug && cd ..
WARNING [Project: :app] Current NDK support is deprecated. Alternative will be provided in the future.
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/pirsquare/bit/mx3/example_android/app/build.gradle' line: 44
* What went wrong:
A problem occurred evaluating project ':app'.
> Neither path nor baseDir may be null or empty string. path='null' basedir='/Users/pirsquare/bit/mx3/example_android/app'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.796 secs
make: *** [android] Error 1
iOS is build fine anyway, Any help would be appreciated.
Thanks
If you put a UITableView
in it, I'll show how to load data from sqlite.
Current example is great but when I try to add more function to api e.g.
[api hello]
I just can't find which file (should be some.cpp
right?) to edit or add method. (noob!)
I even try search all getUsername
from example to see how it implement and where is came from.
but so far I found only generated code with warning DO NOT MODIFY!
Any hint would be nice, I'm losing half day already 🐢
I have read the demo of todo app's demo: todo-app-using-djinni-and-sqlite.
It's great.
And I have a question:
If the app need store many big files like photos. How should i to manage the photo files .Use sqlite to store them i think is will be slow in storage and read.
Should i need import another c++ file manage lib to manage big files .So android and ios could use it both?
Thanks a lot!
This will ease the transition onto windows
after running make play, I am presented with the following error message:
▸ Building mx3/play_objc [Debug]
▸ Compiling play.m
2015-01-16 12:48:50.640 play_objc[31184:895832] *** Terminating app due to uncaught exception 'unable to open database file', reason: 'unable to open database file'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff940d566c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8c7e876e objc_exception_throw + 43
2 CoreFoundation 0x00007fff940d551d +[NSException raise:format:] + 205
3 play_objc 0x000000010f9b45f4 _ZN6djinni27throwNSExceptionFromCurrentEPKc + 212
4 play_objc 0x000000010f9924e6 +[MX3ApiCppProxy createApi:uiThread:httpImpl:] + 790
5 play_objc 0x000000010f9912be main + 142
6 libdyld.dylib 0x00007fff94f775c9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
/bin/sh: line 1: 31184 Abort trap: 6 ./build/Debug/play_objc
make: *** [play] Error 134
Please help me build this project for iOS.
Thanks
I'll try to explain myself, I don't know if it makes sense...
I'm thinking that the src/
folder should not contain any application-specific code, it should have only code that would benefit everyone.
So maybe there should be another example_src/
or similar for C++ code that will generally not be useful to other people, like Api::has_user()
? And maybe the same for objc/
, have another example_objc/
that will have all the VersionEye/GitHub stuff.
Do you think it'd be a good idea?
record_with_const = record +c +j +o { const const_value: i32 = 8; }
Djinni will generate record_with_const_base,not record_with_const.At the same time djinni will generate class RecordWithConstBase!It will cause compilation errors.
Trying to build the Android example and it is failing in some python files. Here is my console output:
Joeys-MacBook-Pro:mx3 joeywessel$ make android
./deps/gradle/gradlew djinni
:djinniBuild UP-TO-DATE
:djinniGen UP-TO-DATE
:djinniOutSyncCpp UP-TO-DATE
:djinniOutSyncJava UP-TO-DATE
:djinniOutSyncJni UP-TO-DATE
:djinniOutSyncObjc UP-TO-DATE
:djinniOutSync UP-TO-DATE
:djinni UP-TO-DATE
BUILD SUCCESSFUL
Total time: 3.208 secs
ANDROID_BUILD_TOP=dirname deps/gyp/gyp --depth=. -f android -DOS=android --root-target libmx3_android -Icommon.gypi mx3.gyp
Traceback (most recent call last):
File "deps/gyp/gyp_main.py", line 18, in <module>
sys.exit(gyp.script_main())
File "deps/gyp/pylib/gyp/__init__.py", line 533, in script_main
return main(sys.argv[1:])
File "deps/gyp/pylib/gyp/__init__.py", line 526, in main
return gyp_main(args)
File "deps/gyp/pylib/gyp/__init__.py", line 502, in gyp_main
params, options.check, options.circular_check)
File "deps/gyp/pylib/gyp/__init__.py", line 91, in Load
generator = __import__(generator_name, globals(), locals(), generator_name)
ImportError: No module named android
make: *** [GypAndroid.mk] Error 1
Dropbox has recently released a project open source called djinni which would be exceptionally helpful for this type of project.
Hello,
I'm trying to build the example for the android platform, but it fails with the error below:
###:~/### (master)$ make android
git clone --depth 1 https://chromium.googlesource.com/external/gyp.git ./deps/gyp
Cloning into './deps/gyp'...
remote: Sending approximately 10.51 MiB ...
remote: Counting objects: 1779, done
remote: Finding sources: 100% (1779/1779)
remote: Total 1779 (delta 353), reused 1057 (delta 353)
Receiving objects: 100% (1779/1779), 895.36 KiB | 0 bytes/s, done.
Resolving deltas: 100% (353/353), done.
Checking connectivity... done.
./deps/gradle/gradlew djinni
:djinniBuild UP-TO-DATE
:djinniGen UP-TO-DATE
:djinniOutSyncCpp UP-TO-DATE
:djinniOutSyncJava UP-TO-DATE
:djinniOutSyncJni UP-TO-DATE
:djinniOutSyncObjc UP-TO-DATE
:djinniOutSync UP-TO-DATE
:djinni UP-TO-DATE
BUILD SUCCESSFUL
Total time: 2.572 secs
ANDROID_BUILD_TOP=dirname deps/gyp/gyp --depth=. -f android -DOS=android --root-target libmx3_android -Icommon.gypi mx3.gyp
Usage: gyp_main.py [options ...] [build_file ...]
gyp_main.py: error: no such option: --root-target
Makefile:40: recipe for target 'GypAndroid.mk' failed
make: *** [GypAndroid.mk] Error 2
It looks fine, indeed I have for ./deps/gyp/gyp -h as follows:
Usage: gyp_main.py [options ...] [build_file ...]
Options:
-h, --help show this help message and exit
--build=CONFIGS configuration for build after project generation
--check check format of gyp files
--config-dir=CONFIG_DIR
The location for configuration files like
include.gypi.
-d DEBUGMODE, --debug=DEBUGMODE
turn on a debugging mode for debugging GYP. Supported
modes are "variables", "includes" and "general" or
"all" for all of them.
-D VAR=VAL sets variable VAR to value VAL
--depth=PATH set DEPTH gyp variable to a relative path to PATH
-f FORMATS, --format=FORMATS
output formats to generate
-G FLAG=VAL sets generator flag FLAG to VAL
--generator-output=DIR
puts generated build files under DIR
--ignore-environment do not read options from environment variables
-I INCLUDE, --include=INCLUDE
files to include in all loaded .gyp files
--msvs-version=MSVS_VERSION
Deprecated; use -G msvs_version=MSVS_VERSION instead
--no-circular-check don't check for circular relationships between files
--parallel Use multiprocessing for speed (experimental)
-S SUFFIX, --suffix=SUFFIX
suffix to add to generated files
--toplevel-dir=DIR directory to use as the root of the source tree
What does the root-target option stay for?
Thank you in advance for your help.
I'm getting a runtime error in android when I build with NDK r10d and api android-21 or android-22. Build with android-19 doesn't have the issue.
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "atof" referenced by "libmx3_android.so"...
Seems some bits have been moved around from 19 onwards
Should use NSURLSession (supported from iOS7).
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
[callback onNetworkError];
} else {
int16_t httpCode = [(NSHTTPURLResponse*) response statusCode];
NSString * strData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[callback onSuccess:httpCode data: strData];
}
}] resume];
Great example overall. Keep up the good work 👍
So the more I've become familiar with the example the only way I've seen that the C++ code talks back to the native code is with callbacks. Is there another way to talk from the C++ side of the code to the native side? Or do you just have to use the callback pattern that is being used to go from C++ to native?
When using make play
I get the following output:
~/Documents/Projekte/iOS/mx3[add_xcpretty*]$ make play
xcodebuild -project build_mac/mx3.xcodeproj -configuration Debug -target play_objc | xcpretty -c && ./build/Debug/play_objc
▸ Building mx3/libmx3_objc [Debug]
▸ Compiling MX3Api.mm
▸ Building library libmx3_objc.a
▸ Building mx3/libmx3 [Debug]
▸ Building leveldb/leveldb [Debug]
▸ Building json11/json11 [Debug]
▸ Building sqlite3/sqlite3 [Debug]
▸ Building CppSQLite/CppSQLite [Debug]
▸ Building mx3/play_objc [Debug]
⌦ Undefined symbols for architecture x86_64
> Symbol: mx3::EventLoop::EventLoop()
> Referenced from: mx3::objc::ObjcEventLoop::ObjcEventLoop(NSObject<OS_dispatch_queue>*) in libmx3_objc.a(MX3Api.o)
⌦ ld: symbol(s) not found for architecture x86_64
⌦ clang: error: linker command failed with exit code 1 (use -v to see invocation)
** BUILD FAILED **
The following build commands failed:
Ld build/Debug/play_objc normal x86_64
(1 failure)
/bin/sh: ./build/Debug/play_objc: No such file or directory
make: *** [play] Error 127
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.