Issue
I have a problem with some code that has been written for Android NDK 10d. It's not my code, but I'd like to fork and recompile this project. But I run into problems with the current NDK (19c). I have seen the code snippet in other projects as well, but I couldn't find a proper way to update this section. Maybe someone here has an idea or could explain what the problem is exactly?
Code:
JNIEXPORT jint JNICALL Java_jackpal_androidterm_TermExec_createSubprocessInternal(JNIEnv *env, jclass clazz,
jstring cmd, jobjectArray args, jobjectArray envVars, jint masterFd)
{
const jchar* str = cmd ? env->GetStringCritical(cmd, 0) : 0;
String8 cmd_8;
if (str) {
cmd_8.set(str, env->GetStringLength(cmd));
env->ReleaseStringCritical(cmd, str);
}
...
int ptm = create_subprocess(env, cmd_8.string(), argv, envp, masterFd);
return ptm;
}
I get the following error (referring to cmd_8.set(str, env->GetStringLength(cmd));
):
process.cpp:210:19: error: cannot initialize a parameter of type 'const char16_t *' with an lvalue of type 'const jchar *' (aka 'const unsigned short *')
cmd_8.set(str, env->GetStringLength(cmd));
^~~
So I guess parameter types changed with newer versions of NDK? Do I need a type conversion somewhere? I guess there are just updated functions/calls to this in newer versions, but I couldn't find any documentation (also didn't know what to look for).
Any ideas?
Solution
The compiler in r19 is less forgiving than the one from r10. The parameter types did not change, but the recent clang requires that you add explicit cast:
cmd_8.set((const char16_t*)str, env->GetStringLength(cmd));
This said, your project may have a worse problem, as explained @Richard Critten. If it relies upon libutils and other Android private libraries, it will not work on Android Marshmallow and higher.
Answered By - Alex Cohn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.