Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

Updated Wiki: Use on Android

$
0
0

How to use the C++ REST SDK on Android (2.3+)

The C++ REST SDK prefers static linking for Android since version 2.3. This makes it much simpler for both Native Activities and Java-based Activities since there is only one shared object file.

However, in order to prevent conflicts with other code, you must provide a pointer to the JVM to the SDK before it can initialize. This pointer is provided through the method cpprest_init(vm) which is located in the pplx/pplxtasks.h header file.

Note: If you do not do this, your application will terminate upon attempting to create a task.

Native Activity (android_main)

For most NativeActivity projects, if you have an entry point like
void android_main(struct android_app* state) {

You can add the following code at the top of the android_main function:
    cpprest_init(state->activity->vm);

Other Shared Libraries (JNI_OnLoad)

For most shared library projects, you will simply need to copy the following code into your main cpp file:
extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
    JNIEnv* env;
    if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
    {
        return -1;
    }

    cpprest_init(vm);
    return JNI_VERSION_1_6;
}


Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>