1. 程式人生 > >Android Studio配置總結

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'
}