1

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.

0

1 Answer 1

3

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.