Platinum SDK 使用 NDK 编译
闾丘成礼
2023-12-01
1. 下载 sdk 文件;
http://sourceforge.net/projects/platinum/files/platinum/1.0.5.13/
2. ubuntu 安装编译辅助工具 scons
sudo apt-get install scons
3. 下载并解压 android ndk 文件;
在环境变量设置 ndk 路径:
export ANDROID_NDK_ROOT=/opt/android-ndk-r10e
export PATH=.:$ANDROID_NDK_ROOT:$PATH
4. 编译静态库libaxTLS.a:
scons target=arm-android-linux build_config=Release
下面的错误是因为默认的配置文件,使用 4.4.3 的toolchain,现在的新版本ndk没有这个toolchain 都是4.8,4.9了
修改配置文件:vim Build/Targets/arm-android-linux/Config.scons
将其中的设置从4.4.3改为4.8
下面添加一行: ANDROID_HOST_SYSTEM = 'linux-x86_64'
scons target=arm-android-linux build_config=Release
scons: Reading SConscript files ...
********** Configuring Build Target = arm-android-linux / Release ********
Building for Android:
ANDROID_HOST_SYSTEM = linux-x86
ANDROID_TOOLCHAIN = arm-linux-androideabi-4.4.3
ANDROID_PLATFORM = android-9
ANDROID_ARCH = arm
scons: done reading SConscript files.
scons: Building targets ...
arm-linux-androideabi-g++ -o Build/Targets/arm-android-linux/Neptune/Source/Core/Neptune.o -c -fno-exceptions -fno-rtti -Wall -D_REENTRANT -O3 -I/opt/android-ndk-r10e/sources/cxx-stl/system/include --sysroot /opt/android-ndk-r10e/platforms/android-9/arch-arm -msoft-float -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -D_REENTRANT -DNDEBUG -DNPT_CONFIG_ENABLE_LOGGING -DPLATINUM_UPNP_SPECS_STRICT -DANDROID -DNPT_CONFIG_HAVE_SYSTEM_LOG_CONFIG -DNPT_CONFIG_ENABLE_ZIP -DNPT_CONFIG_ENABLE_TLS -I/home/jwaoo/tools/PlatinumKit-1-0-5-13_0ab854/Neptune/Source/Core -I/home/jwaoo/tools/PlatinumKit-1-0-5-13_0ab854/Neptune/Source/Data/TLS -Igcc -I/home/jwaoo/tools/PlatinumKit-1-0-5-13_0ab854/Neptune/ThirdParty/zlib-1.2.3 -I/home/jwaoo/tools/PlatinumKit-1-0-5-13_0ab854/Neptune/ThirdParty/axTLS/crypto -I/home/jwaoo/tools/PlatinumKit-1-0-5-13_0ab854/Neptune/ThirdParty/axTLS/ssl -I/home/jwaoo/tools/PlatinumKit-1-0-5-13_0ab854/Neptune/ThirdParty/axTLS/config/Generic /home/jwaoo/tools/PlatinumKit-1-0-5-13_0ab854/Neptune/Source/Core/Neptune.cpp
sh: 1: arm-linux-androideabi-g++: not found
scons: *** [Build/Targets/arm-android-linux/Neptune/Source/Core/Neptune.o] Error 127
scons: building terminated because of errors.
编译成功会生成如下内容:
$ ls ~/tools/PlatinumKit-1-0-5-13_0ab854/Platinum/Build/Targets/arm-android-linux/Release/
FileMediaServerTest libPltMediaConnect.a MediaCrawler
FrameStreamer libPltMediaRenderer.a MediaRendererTest
HttpTest libPltMediaServer.a MicroMediaController
libaxTLS.a libZlib.a Source/
libNeptune.a LightSampleTest TextToHeader
libPlatinum.a MediaConnect TimeTest
5. 编译 jni 文件:
cd Platinum/Source/Platform/Android/module/platinum/jni
ndk-build NDK_DEBUG=0
生成如下结果:
[armeabi] Compile++ thumb: platinum-jni <= platinum-jni.cpp
[armeabi] StaticLibrary : libstdc++.a
[armeabi] SharedLibrary : libplatinum-jni.so
[armeabi] Install : libplatinum-jni.so => libs/armeabi/libplatinum-jni.so
[armeabi-v7a] Compile++ thumb: platinum-jni <= platinum-jni.cpp
[armeabi-v7a] StaticLibrary : libstdc++.a
[armeabi-v7a] SharedLibrary : libplatinum-jni.so
[armeabi-v7a] Install : libplatinum-jni.so => libs/armeabi-v7a/libplatinum-jni.so
6. 测试 jni 库:
将 Platinum\Source\Platform\Android 目录下的两个工程导入 Eclipse。
7. 可以在 android 设备上运行native 程序来进行测试:
在 Platinum/Source/Platform/Android/module/platinum/jni 目录下添加 test-platinum.cpp:
#include "Platinum.h"
#include <stdio.h>
class TutorialListener : public PLT_CtrlPointListener
{
public:
virtual NPT_Result OnDeviceAdded(PLT_DeviceDataReference& device)
{
printf("OnDeviceAdded\n");
return NPT_SUCCESS;
}
virtual NPT_Result OnDeviceRemoved(PLT_DeviceDataReference& device)
{
printf("OnDeviceRemoved\n");
return NPT_SUCCESS;
}
virtual NPT_Result OnActionResponse(NPT_Result res, PLT_ActionReference& action, void* userdata)
{
printf("OnActionResponse\n");
return NPT_SUCCESS;
}
virtual NPT_Result OnEventNotify(PLT_Service* service, NPT_List<PLT_StateVariable*>* vars)
{
printf("OnEventNotify\n");
return NPT_SUCCESS;
}
};
int main()
{
PLT_UPnP upnp;
PLT_CtrlPointReference ctrlpoint(new PLT_CtrlPoint);
TutorialListener listener;
ctrlpoint->AddListener(&listener);
upnp.AddCtrlPoint(ctrlpoint);
upnp.Start();
ctrlpoint->Discover();
printf("UPNP STARTED\n");
bool stop=false;
do {
int input = getchar();
if(input =='q' || input == 'Q') {
stop = true;
}else {
// do nothing
}
} while(!stop);
upnp.Stop();
printf("UPNP STOPPED\n");
return 0;
}
然后编辑 Android.mk 程序,添加:
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.cpp
LOCAL_LDLIBS += -llog
LOCAL_LDLIBS += -landroid -pie -fPIE
LOCAL_CFLAGS += -DNPT_CONFIG_ENABLE_LOGGING -pie -fPIE
LOCAL_STATIC_LIBRARIES := Platinum
LOCAL_STATIC_LIBRARIES += Neptune
LOCAL_STATIC_LIBRARIES += axTLS
include $(BUILD_EXECUTABLE)