Problems building Android Library with native code

Refresh

November 2018

Views

1.5k time

5

I am trying to build an Android library project with native code. Per the "Known limitations" section under http://tools.android.com/tech-docs/new-build-system/gradle-experimental hybrid library projects are supported. But I don't seem to see the native so files being generated under the libs folder of the library aar file.

Here is how my project setup looks like

  1. Followed steps in http://tools.android.com/tech-docs/new-build-system/gradle-experimental for ndk support
  2. Added a library modules that statically loads the native so file and exposes capabilities via some methods
  3. Added another module that uses the native module. Set the module dependencies to include the library project.

When I run this app I get an UnsatisfiedLinkError, which I expected as I see no native so files being generated in the aar file.

This is how my library build.gradle file looks like

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"
     }
}

This is how my app module's build.gradle looks like

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

1 answers

1

Это общая проблема в Gradle экспериментальной 0.2.0 и 0.2.1. Если бы та же самая проблема, модернизированный до 0.3.0-альфа - 4 , и она работала (просто заменить 0.2.0с 0.3.0-alpha4в build.gradle вашего проекта). Для обновления вам потребуется Gradle 2.6 (щелкните правой кнопкой мыши на установок / Open МОДУЛЬ / выберите Project / набор подменю Gradle версии поле 2.6). Обратите внимание , что я использую Android Studio 1.4 RC3.