Git Product home page Git Product logo

usecmakebuildlib's Introduction

使用Cmake构建.a静态库和.so动态库

Demo中子模块说明:

  • libcode: 以源码的形式将SDK依赖到cpp中使用
  • libsosimple: 构建hello简单的.so动态库,且将.so和所需头文件导出到 project/export/libsohello 目录中
  • libsojsoncpp: 构建jsoncpp的.so动态库,且将.so和所需头文件导出到 project/export/libsojsoncpp 目录中
  • libasimple: 构建一个hello简单的.a静态库,且将.a和所需头文件导出到 project/export/libahello 目录中
  • libajsoncpp: 构建jsoncpp的.a静态库,且将.a和所需头文件导出到 project/export/libajsoncpp 目录中

注:

  1. export 是编译 任何一个模块 自己在当前项目目录下自动生成的;
  2. app/src/main/cpp/CmakeLists.txt 中的注释是关于链接so动态库、a静态库、链接头文件到native;
  3. libasimple/build.gradle 中需要设置一下 targets 名称,最好和 libasimple/src/main/cpp/hello/CmakeLists.txt 中的名字一样 如下:
    android {
    ...
        defaultConfig {
            ...
            externalNativeBuild {
                cmake {
                ...
                    targets "hello"
                ...
                }
            }
            ...
        }
    ...
    }
    
  4. libasimple/src/main/cpp/CmakeLists.txt 中的注释是关于 编译前期目录配置 和 链接 子目录;
  5. libasimple/src/main/cpp/hello/CmakeLists.txt 中的注释是关于 库名字、库类型、库导出路径、头文件导出;
  6. libsosimple/src/main/cpp/hello/CmakeLists.txt 中的注释是关于 so动态库如何导出,相比 第5条 只改了一个参数;
  7. libajsoncpp/src/main/cpp/jsoncpp/CmakeLists.txt 中的注释是关于 相比 第5条 多了一个 按文件夹导出的命令;
  8. app/build.gradle 中最重要的注释是关于集成so动态库时的注意事项,配置如下:
    android {
    ...
        sourceSets {
            main {
                jniLibs.srcDirs = ['../export/libsohello/lib', '../export/libsojsoncpp/lib']
            }
        }
    ...
    }
    

OTHER

提一个问题:

env->GetStringUTFChars(string, NULL);
env->ReleaseStringUTFChars(string, const char*);

这两个必须成对出现吗? 说出理由。

usecmakebuildlib's People

Contributors

lilinxiong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

usecmakebuildlib's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.