- 使用合适的NDK
编译会报错解决方法
建议用D:\Tools\SDK\ndk\22.1.7171670\sources\third_party\shaderc>
这个 D:\Tools\SDK\ndk\23.1.7779620\sources\third_party\shaderc 版本编译不过
......\ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk APP_ABI=all APP_PLATFORM=android-30 APP_STL=c++_static -j8 clean libshaderc_combined
或者
......\ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk ^ APP_STL:=c++_shared APP_ABI=all libshaderc_combined
......\ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk APP_STL:=c++_static APP_ABI=all libshaderc_combined
- androidstudio配置:
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.bn.Sample7_1"
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
abiFilters 'arm64-v8a', 'armeabi-v7a'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
// ndkVersion '23.1.7779620'
ndkVersion '22.1.7171670'
}
cmake 配置:
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fexceptions -Wall -D VK_USE_PLATFORM_ANDROID_KHR")
include_directories(${ANDROID_NDK}/sources/android/native_app_glue)
include_directories(${ANDROID_NDK}/sources/third_party/shaderc/include)
include_directories(src/main/cpp/)
add_library(shaderc_lib STATIC IMPORTED)
set_target_properties(shaderc_lib PROPERTIES IMPORTED_LOCATION
${ANDROID_NDK}/sources/third_party/shaderc/libs/${ANDROID_STL}/${ANDROID_ABI}/libshaderc.a)
add_library(
bn-vulkan-lib
SHARED
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c
)
target_link_libraries(
bn-vulkan-lib
GLESv3
android
log
shaderc_lib)
- 按照三角形教程编写代码
init_vulkan_instance();
enumerate_vulkan_phy_devices
create_vulkan_devices();
create_vulkan_CommandBuffer(
init_queue();
create_vulkan_swapChain();
create_vulkan_DepthBuffer();
create_render_pass();
create_frame_buffer();
createDrawableObject();
initPipeline();
createFence();
initPresentInfo();
initMatrix();
drawObject();
destroyPipeline();
destroyDrawableObject();
destroy_frame_buffer();
destroy_render_pass();
destroy_vulkan_DepthBuffer()
destroy_vulkan_swapChain();
destroy_vulkan_CommandBuffer
destroy_vulkan_devices();
destroy_vulkan_instance();