Issue
I have my c++ file I putted it in jni folder with application.mk ,android.mk and putted everything in build.gradle and in the class with native stringtoJNI and static {} i guess i putted everything and still I have issues when I tried helloJNI sample it worked but on my app there is problem i searched alot and saw similar issues and tried almost everything and still i get error.
ndktest.c
jstring Java_com_example_mike_lol8_WallService(JNIEnv *env, jobject obj) {
jstring str = "http://555.555.555.555";
return (*env)->NewStringUTF(env, str); }
Application.mk
APP_ABI := all
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ndktest
LOCAL_SRC_FILES := ndktest.c
include $(BUILD_SHARED_LIBRARY)
build.gradle
ndk {
moduleName "ndktest"
}
sourceSets.main {
jni.srcDirs "src/main/jni"
jniLibs.srcDir "src/main/jniLibs"
}
}
WallService.class
public class WallService extends Service {
public static native String stringFromJNI();
private static String BASEURL = stringFromJNI();
static {
System.loadLibrary("ndktest");
}
So in so examples StringJNI reading the file but i got error in the logcat but this is my code StringJNI it's red can't connect with my file(can't see it) so maybe someone can help me
Solution
Found the solution (maybe people benefit from it ) thanks all for the help
public class WallService extends Service {
public native String stringFromJNI();
static {
System.loadLibrary("native-lib");
}
scr/main/cpp or(jni)/native-lib.c
#include <jni.h>
#include <string>
extern "C"
jstring
Java_com_example_mike_lol10_WallService_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "http://130.193.127.250";
return env->NewStringUTF(hello.c_str());
}
build.gradle
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.mike.lol10"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
or u can check the support c++ when your creating new project under the name . It create Cmakelist too.
Answered By - user7074940
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.