visual c++ cross platform android: Include prebuilt shared library

人走茶凉 提交于 2020-01-24 19:35:47

问题


I'm using the Visual C++ Cross Platform Tools for Android as described here: https://msdn.microsoft.com/en-us/library/dn707591.aspx

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:

Step 1

To test the ability of Visual Studio to link to a prebuilt shared library, I created a small shared library as follows:

SharedLibrary.cpp:

#include "SharedLibrary.h"

const char * SharedLibrary::GetString()
{
    return "Hello from Shared Library";
}

void SharedLibrary()
{
}

SharedLibrary::SharedLibrary()
{
}

SharedLibrary::~SharedLibrary()
{
}

SharedLibrary.h:

#pragma once

class SharedLibrary
{
public:
    const char * GetString();
    SharedLibrary();
    ~SharedLibrary();
};

Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := SharedLibrary
LOCAL_SRC_FILES := SharedLibrary.cpp
include $(BUILD_SHARED_LIBRARY)

Step 2

I then compiled this shared library using the command ndk-build, which gives me a file libSharedLibrary.so

Step 3

I then created a Visual Studio project: File -> New -> Project -> Cross Platform -> Android -> Basic Application (Android, Ant). This project compiles and runs fine.

Step 4

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.

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?

This is my first stackoverflow post, so feel free to correct me, if I did anything wrong in my post.


回答1:


After investing a stupidly large amount of time, I found the solution (thanks Microsoft for not documenting this functionality anywhere...):

  • Open the Visual Studio solution
  • Go to the Android Packaging Project
  • Right-click on the project, then choose 'Add' -> 'New Folder'
  • Name the new folder 'libs' (this naming is mandatory!)
  • Create a subfolder for each targeted processor architecture (for example 'armeabi-v7a')
  • Drag and drop the respective *.so file into these subfolders

When compiling the project, the 'libs' folder and its content get copied into the compiled *.apk file.

Hope this helped out somebody!



来源:https://stackoverflow.com/questions/40307291/visual-c-cross-platform-android-include-prebuilt-shared-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!