Android studio ndk的配置(待续)


使用gradle

gradle集成了一部分编译native代码的语法,可以使用gradle自动编译打包,调试很方便

Known Limitations

  • There’s no support for NDK-only modules. The only supported project types are hybrid app projects and hybrid Library Projects.
  • Consumed Library project don’t impact compilation of jni code in the consuming project (ie the AAR so files are simply packaged in the APK)
  • No support for creating and depending on static libraries
  • No support for using a NDK modules like cpu_features
  • No support for integrating external build systems.

以下参考

目录结构

.
├── app.iml
├── build.gradle
├── proguard-rules.pro
└── src
    ├── androidTest
    │   └── java
    │       └── net
    │           └── crystax
    │               └── examples
    │                   └── testboost
    │                       └── ApplicationTest.java
    └── main
        ├── AndroidManifest.xml
        ├── java
        │   └── net
        │       └── crystax
        │           └── examples
        │               └── testboost
        │                   └── MainActivity.java
        ├── jni
        │   ├── Android.mk
        │   ├── Application.mk
        │   ├── gps.cpp
        │   ├── gps.hpp
        │   └── test.cpp
        └── res
            .......

创建jni目录

手动创建也是可以的。 Gradle插件(Android Studio用来编译工程)忽略jni文件夹的Application.mk 和 Android.mk文件. 相反它会在运行时生成它自己的Android.mk,使用构建脚本中的设置. 实际上, 在Android Studio中构建功能齐全的NDK应用程序的唯一方式是完全禁用它有限的NDK支持, 手动调用$NDK/ndk-build命令.

local.properties

指定ndk的安装目录

sdk.dir=/opt/android/android-sdk-mac
ndk.dir=/opt/android/crystax-ndk-10.1.0

build.gradle

defaultConfig {
        ...
        ndk {
            moduleName "my-module-name"
            cFlags "-std=c++11 -fexceptions"
            ldLibs "log"
            stl "gnustl_shared"
            abiFilter "armeabi-v7a"
        }
    }
}

使用android.mk编译好之后,打包进apk

传送


Copyright © FengGuangtu 2017