Android Studio配置总结

1. CMAKE

AS 2.3.1版本后使用Cmake来配置Native代码的编译,所以在这里总结下Cmake的常用配置:

添加引用路径:

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/include)
添加待编译模块:
 
 
add_library( # Sets the name of the library.
             ImageTargetsNative
             # Sets the library as a shared library.
             SHARED
             #SHARED output .so  STATIC output .a
             # Provides a relative path to your source file(s).
             src/main/cpp/ImageTargets.cpp
             src/main/cpp/SampleAppRenderer.cpp
             src/main/cpp/SampleUtils.cpp
             src/main/cpp/Texture.cpp
              )
添加已编译好的模块: 
 
 
 
add_library( vuforia SHARED IMPORTED )
set_target_properties(vuforia PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libVuforia.so)
添加系统待链接模块:
 
 
find_library( # Sets the name of the path variable.
              log-lib
              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

find_library( # Sets the name of the path variable.
              GLESv2-lib
              GLESv2)
链接输出模块:
 
 
target_link_libraries( # Specifies the target library.
                       ImageTargetsNative
                       vuforia
                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib}
                       ${GLESv2-lib}
                       )
添加编译参数和选择编译平台需要在build.grandle中进行配置:
 
 
externalNativeBuild {
    cmake {
        cppFlags "-Wno-write-strings","-Wno-psabi","-DUSE_OPENGL_ES_2_0","-std=c++11"
    }
}
ndk {
    // Specifies the ABI configurations of your native
    // libraries Gradle should build and package with your APK.
    abiFilters 'armeabi-v7a'
}

猜你喜欢

转载自blog.csdn.net/u011089570/article/details/72779047