AndroidStudio提供了创建项目时选择C++支持的模板,但是新建Module的时候并没有C++模板,

要如何配置Module的C++支持呢? 虽然Module没有提供C++模板,但是我们可以手动配置C++支持.

首先新建 Android Library

然后在 src/main/新建cpp文件夹,之后在cpp文件夹新建一个 main.cpp 的C/C++ Source File文件.

再新建一个CMakeLists.txt文件,复制下面的内容到CMakeLists.txt文件.

一个更简单的方法,先去建一个支持C++的项目,然后将cpp文件夹直接拷贝到src/main目录下.

# 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.4.1) # 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.
main #新建的C/C++ Source File文件的名称 # Sets the library as a shared library.
SHARED # Provides a relative path to your source file(s).
#main.cpp源文件
main.cpp ) # 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 ) # 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.
main # Links the target library to the log library
# included in the NDK.
${log-lib} )

去模块的 build.gradle中添加下面的配置

android{
defaultConfig{
...
...
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
}
android{
...
...
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
}

生成的aar可以拷贝到别的项目中使用(需要配置NDK,不然会报错)

Android Module配置C++支持的更多相关文章

  1. Android JDK配置使支持Gradle更新,Maven安装

    配置Maven 或执行Gradle更新等相关命令时出现以下错误时要重新配置JDK ERROR: JAVA_HOME is set to an invalid directory.JAVA_HOME = ...

  2. 用C++语言开发Android程序 配置开发环境

    转自:http://www.cnblogs.com/yaotong/p/3622430.html 用C++语言开发Android程序 配置开发环境   如果你是一个C++语言的死忠,你喜欢C++语言到 ...

  3. 图解IntelliJ IDEA 13版本对Android SQLite数据库的支持

    IntelliJ IDEA 13版本的重要构建之一是支持Android程序开发.当然对Android SQLite数据库的支持也就成为了Android开发者对IntelliJ IDEA 13版本的绝对 ...

  4. 【React Native开发】React Native For Android环境配置以及第一个实例(1)

    年9月15日也公布了ReactNative for Android,尽管Android版本号的项目公布比較迟,可是也没有阻挡了广大开发人员的热情.能够这样讲在2015年移动平台市场上有两个方向技术研究 ...

  5. 在android中配置 slf4j + log4j 日志记录框架

    需求: 在项目开发中,需要记录 操作日志 .起初自己写了个简单的日志记录文本写入到文本的方法,后来随着项目的膨胀,需要考虑更多的操作,开始考虑性能问题. 实现: 考虑使用 slf4j + log4j ...

  6. Mac 10.9x下安装配置phonegap3.0开发环境 (涉及android sdk配置)

    最近突然想弄一下phonegap,之前一直是听说,没亲自配置开发过.结果配置过程非常艰难啊.特别是android平台的配置,那叫一个麻烦,网上搜了半天都没找到非常好的资料.文章也都是抄来抄去,最烦的就 ...

  7. Android 4.4 KitKat 支持 u 盘功能

    Android U 盘功能实现和分析 u 盘功能实现结果: u 盘会当成 usb storage 在 Settings Storage 里面显示. 准备工作 内核需支持 usb host,需支持 FU ...

  8. Android零基础入门第13节:Android Studio配置优化,打造开发利器

    原文:Android零基础入门第13节:Android Studio配置优化,打造开发利器 是不是很多同学已经有烦恼出现了?电脑配置已经很高了,但是每次运行Android程序的时候就很卡,而且每次安装 ...

  9. OpenCV On Android环境配置最新&最全指南(Android Studio篇)

    本文是从本人简书上搬运而来,属本人原创,如有转载,请注明出处:http://www.jianshu.com/p/6e16c0429044 简介 本文是<OpenCV On Android环境配置 ...

随机推荐

  1. ArrayList分析1-循环、扩容、版本

    ArrayList分析1-循环.扩容.版本 转载请注明出处 https://www.cnblogs.com/funnyzpc/p/16407733.html 前段时间抽空看了下ArrayList的源码 ...

  2. PTA(BasicLevel)-1023 组个最小数

    一. 问题定义 给定数字 0-9 各若干个.你可以以任意顺序排列这些数字,但必须全部使用.目标是使得最后得到的数尽可能小(注意 0 不能做首位). 例如:给定两个 0,两个 1,三个 5,一个 8,我 ...

  3. List集合_介绍&常用方法和ArrayList集合

    List集合 我们掌握了Collection接口的使用后,再来看看Collection接口中的子类,他们都具备那些特性呢? 接下来,我们一起学习Collection中的常用几个子类(java.util ...

  4. springboot配置logback.xml

    由于springboot框架自带log4j,因此我们只需配置下logback文件,即可, 在main/resources根目录下,新建logback-spring.xml文件,copy下述代码: &l ...

  5. 在矩池云使用Disco Diffusion生成AI艺术图

    在 Disco Diffusion 官方说明的第一段,其对自身是这样定义: AI Image generating technique called CLIP-Guided Diffusion.DD ...

  6. 关于 Python 的 import

    好久以前就被 Python 的相对与绝对导入所困扰.去年粗浅探究后自以为完全理解,近来又因 sys.path[0] 和 os.getcwd() 的不一致而刷新了认知... Python 官方文档 5. ...

  7. Markdown扩展语法

    目录 Markdown 语法补充 一.快速生成 HTML 表格代码 在线表格编辑器--TablesGenerator 二. 插入视频.音频或GIF 1. 视频 2. 音频 方法一 方法二 方法三 3. ...

  8. SQLZOO练习7--Using NULL

    teacher表: id dept name phone mobile 101 1 Shrivell 2753 07986 555 1234 102 1 Throd 2754 07122 555 19 ...

  9. LAMP架构部署及配置

    httpd编译安装 1.关闭防火墙,将安装Apache所需软件包传到/opt目录下 systemctl stop firewalld systemctl disable firewalld seten ...

  10. Template -「矩阵 - 行列式」

    #include <cstdio> int Abs(int x) { return x < 0 ? -x : x; } int Max(int x, int y) { return ...