Use "sp" in Android NDK

Mar*_* L. 6 c++ android-ndk

I'm trying to intercept some native library-calls via LD_PRELOAD.

This is working fine for simple libraries written in C, but now I try to go further and override some more complex class-methods from the AOSP written in C++.

Here's my example:

#include <rs/cpp/util/RefBase.h>

namespace android {
    sp<MediaCodec> MediaCodec::CreateByType(const sp<ALooper> &looper, const char *mime, bool encoder) {
        // TODO this will be implemented by me
        return NULL;
    }    
}
Run Code Online (Sandbox Code Playgroud)

In my Application.mk, I got the following piece of code:

APP_STL := gnustl_static
Run Code Online (Sandbox Code Playgroud)

and inside the Android.mk this one:

LOCAL_STATIC_LIBRARIES += libstlport_static
Run Code Online (Sandbox Code Playgroud)

Sadly, the error I get is the following:

jni/libhook/ld_preload.cpp:88:1: error: 'sp' does not name a type

Anyone an idea how to use sp<..> here? I assume it's not Android-specific but a standard C++-thing - I'm totally new at C++, just started "today" :)

I know this may be bad practice, so I'm welcome for any other idea.

fad*_*den 10

sp<>是特定于Android的. sp<>是强指针,wp<>是弱指针; 它们是Binder IPC实施的一部分.

开始寻找实现的地方是框架RefBase.h,这对于C++新手来说有点曲折.您正在摆弄的任何内容都不是NDK定义的公共API的一部分,这意味着它可能会在不同版本之间发生变化,因此请注意,您尝试执行的操作可能无法跨设备或软件更新.