I cannot get an Android Wear project to use C++. I am able to get a "Phone and Tablet" project to use C++. Here is what I have done.
Here is an image of the SDK Tools I have installed. I also have SDK API Levels 24-27 installed.
I create a new project. I check "Include C++ support". I check "Wear" (API 26: Android 8.0 (Oreo)). I select "Next" a bunch.
For C++ Standard I have tried all three (Toolchain Default, C++11, c++14).
- I do not check
-fexceptions
or-frtti
.
- I do not check
In the project that is created under the "mobile" Module, I have a "cpp" folder, but I do not have one under the "wear" Module.
If I create a project without "Phone and Tablet" support ("mobile" Module), then I still do not get a "cpp" folder under the "wear" Module.
I tried forcing the project to use C++ under the "wear" Module. Here is what I did.
I modified
build.gradle
(Module: wear) to look like thisapply plugin: 'com.android.application' android { compileSdkVersion 26 defaultConfig { applicationId "com.example.xorgaming.watchtestcpp" minSdkVersion 25 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { cppFlags "-std=c++11" } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } externalNativeBuild { cmake { path "CMakeLists.txt" } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.google.android.support:wearable:2.2.0' implementation 'com.google.android.gms:play-services-wearable:11.8.0' implementation 'com.android.support:percent:26.1.0' implementation 'com.android.support:support-v4:26.1.0' implementation 'com.android.support:recyclerview-v7:26.1.0' implementation 'com.android.support:wear:26.1.0' compileOnly 'com.google.android.wearable:wearable:2.2.0' }
I restart the project which makes a "cpp" folder under the "wear" module.
I create a
native-lib.cpp
file in the "cpp" folder. It looks like this:extern "C" JNIEXPORT jstring JNICALL Java_com_example_xorgaming_watchtestcpp_MainActivity_stringFromJNIWatch( JNIEnv *env, jobject /* this */) { std::string hello = "Hello from C++ WATCH!"; return env->NewStringUTF(hello.c_str()); }
In my java
onCreate()
function, I call:stringFromJNIWatch()
.Everything builds without error (green hammer)
When I run the project (as a wearable device) I get this error:
No implementation found for java.lang.String com.example.xorgaming.watchtestcpp.MainActivity.stringFromJNIWatch()
Any idea what I'm doing wrong? Does Android Wear support C++?