Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems building Android Library with native code

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')
}
like image 648
Harkish Avatar asked Nov 10 '22 04:11

Harkish


1 Answers

This is a common problem in gradle experimental 0.2.0 and 0.2.1. Had the same problem, upgraded to 0.3.0-alpha4 and it worked (just replace 0.2.0 with 0.3.0-alpha4 in your project's build.gradle). To upgrade you will need Gradle 2.6 (right click on a module/Open Module Settings/ select the Project submenu/ set Gradle version field to 2.6). Note that I am using Android Studio 1.4 RC3.

like image 196
Nedko Avatar answered Nov 14 '22 21:11

Nedko