macOS Mojave (10.14.3) Android Studio 3.3.1 导入并构建Vuh项目

栏目: IOS · Android · 发布时间: 5年前

内容简介:以前在修改之后的几个关键文件如下:注意:

以前在 Android Studio 3.2.1上vuh库使用的例子 中实现了一个使用 vuh 库的例子。 那个例子中的 vuh 库是我们编译好 libvuh.so 之后直接引用的,我们下面实现通过直接编译代码实现整合。

修改之后的几个关键文件如下:

注意:  VUH_ROOT_DIR 这个变量中指定了 vuh 库代码的位置

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
 
# Sets the minimum version of CMake required to build the native library.
 
cmake_minimum_required(VERSION 3.8)
 
# for Vulkan
SET(Vulkan_INCLUDE_DIR ${ANDROID_NDK}/sources/third_party/vulkan/src/include/)
SET(Vulkan_LIBRARIES ${ANDROID_NDK}/platforms/${ANDROID_PLATFORM}/arch-${ANDROID_ARCH_NAME}/usr/lib)
if(X86_64)
    SET(Vulkan_LIBRARIES ${Vulkan_LIBRARIES}64)
endif()
SET(Vulkan_LIBRARIES ${Vulkan_LIBRARIES}/libvulkan.so)
add_library(vulkan SHARED IMPORTED)
set_target_properties(vulkan PROPERTIES IMPORTED_LOCATION ${Vulkan_LIBRARIES})
 
# for vuh
add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR=1 -DVULKAN_HPP_TYPESAFE_CONVERSION=1)
SET(VUH_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../vuh/)
SET(VUH_BUILD_TESTS OFF)
SET(VUH_BUILD_DOCS OFF)
SET(VUH_BUILD_EXAMPLES OFF)
 
add_subdirectory(${VUH_ROOT_DIR}src/ ${CMAKE_CURRENT_SOURCE_DIR}/build/)
 
# for example
SET(Vuh_INCLUDE_PATH ${VUH_ROOT_DIR}src/include)
include_directories(${Vulkan_INCLUDE_DIR})
include_directories(${Vuh_INCLUDE_PATH})
 
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
 
add_library( # Sets the name of the library.
        native-lib
 
        # Sets the library as a shared library.
        SHARED
 
        # Provides a relative path to your source file(s).
        src/main/cpp/native-lib.cpp)
 
 
add_dependencies(native-lib vuh)
 
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
 
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
 
        android)
 
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
 
target_link_libraries( # Specifies the target library.
        native-lib
 
        vulkan
 
        vuh
 
        ${log-lib})

注意:由于 vuh 库需要 CMake 3.8 。因此,我们需要手工指定 CMake 版本为 3.10.2

如下:

apply plugin: 'com.android.application'
 
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.mobibrw.vuhandroid"
        minSdkVersion 24
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                version "3.10.2"
                cppFlags "-std=c++14 -v -g"
                abiFilters "armeabi-v7a"
            }
        }
    }
 
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            version "3.10.2"
            path "CMakeLists.txt"
        }
    }
}
 
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

如果出现如下错误:

CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
-- Configuring incomplete, errors occurred!

则执行如下操作:

$ brew install ninja

如果出现如下错误:

* What went wrong:
Execution failed for task ':app:transformNativeLibsWithMergeJniLibsForDebug'.
> More than one file was found with OS independent path 'lib/armeabi-v7a/libvuh.so'

则删除代码中的 jniLibs/armeabi-v7a/libvuh.so 即可解决问题。

参考链接


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

代码大全

代码大全

迈克康奈尔 / 电子工业出版社 / 2006-12 / 148.00元

《代码大全(第2版)(英文版)》由电子工业出版社出版。一起来看看 《代码大全》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试