简体   繁体   English

在Android NDK中使用“sp”

[英]Use “sp” in Android NDK

I'm trying to intercept some native library-calls via LD_PRELOAD. 我试图通过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++. 这对于用C编写的简单库来说效果很好,但是现在我尝试更进一步,并用C ++编写的AOSP覆盖一些更复杂的类方法。

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;
    }    
}

In my Application.mk, I got the following piece of code: 在我的Application.mk中,我得到了以下代码:

APP_STL := gnustl_static

and inside the Android.mk this one: 在Android.mk里面这个:

LOCAL_STATIC_LIBRARIES += libstlport_static

Sadly, the error I get is the following: 可悲的是,我得到的错误如下:

jni/libhook/ld_preload.cpp:88:1: error: 'sp' does not name a type jni / libhook / ld_preload.cpp:88:1:错误:'sp'没有命名类型

Anyone an idea how to use sp<..> here? 任何人都知道如何在这里使用sp <..>? I assume it's not Android-specific but a standard C++-thing - I'm totally new at C++, just started "today" :) 我认为它不是特定于Android的,而是标准的C ++ - 事情 - 我是C ++的新手,刚开始“今天”:)

I know this may be bad practice, so I'm welcome for any other idea. 我知道这可能是不好的做法,所以我欢迎任何其他想法。

sp<> is Android-specific. sp<>是特定于Android的。 sp<> is Strong Pointer, wp<> is Weak Pointer; sp<>是强指针, wp<>是弱指针; they came into being as part of the Binder IPC implementation. 它们是Binder IPC实施的一部分。

The place to start looking for the implementation is the framework RefBase.h , which is a bit twisty for a C++ newcomer. 开始寻找实现的地方是框架RefBase.h ,这对于C ++新手来说有点曲折。 None of what you're fiddling with is part of the public API defined by the NDK, which means it's subject to change between releases, so be aware that what you're trying to do may not work across devices or software updates. 您正在摆弄的任何内容都不是NDK定义的公共API的一部分,这意味着它可能会在不同版本之间发生变化,因此请注意,您尝试执行的操作可能无法跨设备或软件更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM