Android Studio + NDK - import existing C ++

How can I include in the compilation and in the project file tree some .hand .cppfiles located outside the project directory ?

In Visual Studio and a C ++ project, you just use "Add an existing item", select your files and voilà, it just works in ten seconds. Shouldn't Android development make life easier for developers?: /

I’ve been looking for how to do this for many hours. None of the answers I found address this.

I can’t believe that among all the people who used Android Studio with the NDK, none of them used C ++ code outside the folder jni...

Do you know how to do this? Thanks.

+5
source share
2 answers

Here is what I did. First install the latest version of Android Studio 1.4 released today (but I was working on the first preview 1.3 with ndk support). To have NDK support, you need to switch to Gradle 2.5 (Project Structure -> Project -> Gradle Version). Use the experimental gradle -plugin (in main build.gradle "classpath" com.android.tools.build: gradle-experimental: 0.2.0 '").

apps build.gradle , : http://tools.android.com/tech-docs/new-build-system/gradle-experimental

lib dynamic lib. , , lib . make .

, {}

android.ndk {
    moduleName = "NativeLib"

    // toolchain = "clang" <- tried using it, but failed
    // toolchainVersion = "3.5"

    stl = "gnustl_static" // you can switch stl lib this way

    ldLibs += "log"
    cppFlags += "-g"
    cppFlags += "-std=c++11" // use c++11
    cppFlags += "-Wall"
    cppFlags += "-I${file("../../../common/include")}".toString() // include folder
}

android.sources {
    main {
        jni {
            source {
                srcDirs = ['src/main/jni', '../../../common']
            }
        }
    }
}

, - .

+4

, . c++ . cmakelists.txt, cmake. "" . , .so , , . jni , jni. -, , ?

0

Source: https://habr.com/ru/post/1608324/


All Articles