使用本机代码构建Android库时出现问题

Har*_*ish 5 android android-ndk android-library android-studio android-gradle-plugin

我正在尝试使用本机代码构建一个Android库项目.根据http://tools.android.com/tech-docs/new-build-system/gradle-experimental下的"已知限制"部分, 支持混合库项目.但我似乎没有看到本机文件生成在库aar文件的libs文件夹下.

这是我的项目设置的样子

  1. http://tools.android.com/tech-docs/new-build-system/gradle-experimental中的后续步骤,以获得ndk支持
  2. 添加了一个库模块,静态加载本机so文件并通过某些方法公开功能
  3. 添加了另一个使用本机模块的模块.设置模块依赖项以包括库项目.

当我运行这个应用程序时,我得到一个UnsatisfiedLinkError,我预计,因为我看到没有原生的文件在aar文件中生成.

这就是我的库build.gradle文件的样子

apply plugin: 'com.android.model.library'

model {
     android {
         compileSdkVersion = 23
         buildToolsVersion = "23.0.1"
     }
     android.ndk {
         moduleName = "native"
         cppFlags = ['-std=c++11']
         stl = "gnustl_shared"
     }
}
Run Code Online (Sandbox Code Playgroud)

这就是我的app模块的build.gradle的样子

apply plugin: 'com.android.model.application'
model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.1"
    }
}
dependencies {
    compile project(':mylibrary')
}
Run Code Online (Sandbox Code Playgroud)

Ned*_*dko 1

这是gradle实验0.2.0和0.2.1中常见的问题。有同样的问题,升级到0.3.0-alpha4并且它有效(只需在项目的 build.gradle 中替换0.2.0为)。0.3.0-alpha4要升级,您将需要 Gradle 2.6(右键单击模块/打开模块设置/选择项目子菜单/将Gradle 版本字段设置为 2.6)。请注意,我使用的是 Android Studio 1.4 RC3。