Visual C++ 跨平台 android:包括预构建的共享库 [英] visual c++ cross platform android: Include prebuilt shared library
问题描述
我正在使用适用于 Android 的 Visual C++ 跨平台工具,如下所述:https://msdn.microsoft.com/en-us/library/dn707591.aspx
I'm using the Visual C++ Cross Platform Tools for Android as described here: https://msdn.microsoft.com/en-us/library/dn707591.aspx
到目前为止一切正常(我可以在手机上构建和运行文件 -> 新项目 -> 跨平台 -> Android 下的模板).但是,我不知道如何以 *.so 文件的形式将我的应用链接到预构建的共享库.
Everything works fine so far (I can build and run on my phone the templates under File -> New Project -> Cross Platform -> Android). However, I can't find out how to link my app to a prebuilt shared library in the form of an *.so file.
到目前为止,我尝试了以下步骤:
So far, I tried the following steps:
第一步
为了测试 Visual Studio 链接到预构建共享库的能力,我创建了一个小型共享库,如下所示:
To test the ability of Visual Studio to link to a prebuilt shared library, I created a small shared library as follows:
SharedLibrary.cpp:
SharedLibrary.cpp:
#include "SharedLibrary.h"
const char * SharedLibrary::GetString()
{
return "Hello from Shared Library";
}
void SharedLibrary()
{
}
SharedLibrary::SharedLibrary()
{
}
SharedLibrary::~SharedLibrary()
{
}
SharedLibrary.h:
SharedLibrary.h:
#pragma once
class SharedLibrary
{
public:
const char * GetString();
SharedLibrary();
~SharedLibrary();
};
Android.mk:
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := SharedLibrary
LOCAL_SRC_FILES := SharedLibrary.cpp
include $(BUILD_SHARED_LIBRARY)
第 2 步
然后我使用命令 ndk-build 编译了这个共享库,它给了我一个文件 libSharedLibrary.so
I then compiled this shared library using the command ndk-build, which gives me a file libSharedLibrary.so
步骤 3
然后我创建了一个 Visual Studio 项目:文件 -> 新建 -> 项目 -> 跨平台 -> Android -> 基本应用程序(Android、Ant).该项目编译并运行良好.
I then created a Visual Studio project: File -> New -> Project -> Cross Platform -> Android -> Basic Application (Android, Ant). This project compiles and runs fine.
步骤 4
下一步是我卡住的地方:我需要以某种方式将 libSharedLibrary.so 文件链接到 Visual Studio 项目.我在 Visual Studio 项目的项目选项中找不到任何允许我执行此操作的内容.
The next step is where I am stuck: I need to somehow link the libSharedLibrary.so file to the Visual Studio project. I couldn't find anything in the project options of the Visual Studio project which allows me to do this.
所以,这是我的问题:我必须如何设置我的 Visual C++ 跨平台 Android 项目才能将共享对象 (*.so) 链接到它?
So, here is my question: How do I have to setup my Visual C++ cross platform Android project in order to link a shared object (*.so) to it?
这是我的第一篇 stackoverflow 帖子,如果我在帖子中做错了什么,请随时纠正我.
This is my first stackoverflow post, so feel free to correct me, if I did anything wrong in my post.
推荐答案
在投入了大量愚蠢的时间之后,我找到了解决方案(感谢 Microsoft 没有在任何地方记录此功能......):
After investing a stupidly large amount of time, I found the solution (thanks Microsoft for not documenting this functionality anywhere...):
- 打开 Visual Studio 解决方案
- 转到 Android 打包项目
- 右键单击项目,然后选择添加"->新建文件夹"
- 将新文件夹命名为libs"(此命名是强制性的!)
- 为每个目标处理器架构创建一个子文件夹(例如armeabi-v7a")
- 将相应的 *.so 文件拖放到这些子文件夹中
在编译项目时,'libs' 文件夹及其内容会被复制到编译后的 *.apk 文件中.
When compiling the project, the 'libs' folder and its content get copied into the compiled *.apk file.
希望这对某人有所帮助!
Hope this helped out somebody!
这篇关于Visual C++ 跨平台 android:包括预构建的共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!