android studio + vcpkg使用总结

目录

  • 参考链接
  • android studio使用经验
    • vcpkg生成android不同平台的库
    • 设置vcpkg和android工具链路径
    • build.gradle中指定要生成的abi


参考链接

  • Vcpkg and Android
  • bash脚本

android studio使用经验

vcpkg生成android不同平台的库

  • 生成android triplets
    上述链接中配置生成的是动态链接库,vcpkg中默认的是static库,可根据需要使用

设置vcpkg和android工具链路径

在CMakeLists.txt中project()之前添加如下设置,相应路径根据实际情况填写

set(VCPKG_ROOT "F:/Dev/vcpkg")
set(ANDROID_NDK_HOME "D:/ProgramFiles/Android/AndroidSDK/Sdk/ndk/21.4.7075529")
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake")
if(ANDROID_ABI STREQUAL "x86")
    set(VCPKG_TARGET_TRIPLET "x86-android")
elseif(ANDROID_ABI STREQUAL "x86_64")
    set(VCPKG_TARGET_TRIPLET "x64-android")
elseif(ANDROID_ABI STREQUAL "armeabi-v7a")
    set(VCPKG_TARGET_TRIPLET "arm-android")
elseif(ANDROID_ABI STREQUAL "arm64-v8a")
    set(VCPKG_TARGET_TRIPLET "arm64-android")
endif()

build.gradle中指定要生成的abi

配置示例

plugins {
    id 'com.android.application'
}

android {
    signingConfigs {
        release {
        }
    }
    compileSdk 32

    defaultConfig {
        applicationId "com.example.nativeops"
        minSdk 24
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags ''
            }
        }

        ndk {
            // Specifies the ABI configurations of your native
            // libraries Gradle should build and package with your app.
            abiFilters 'x86', 'arm64-v8a', 'armeabi-v7a', 'x86_64'
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    externalNativeBuild {
        cmake {
            path file('src/main/cpp/CMakeLists.txt')
            version '3.18.1'
        }
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

你可能感兴趣的:(C++,工程配置,android,studio,android,gradle)