简体   繁体   中英

How to compile the .so files under dependencies into the .aar package?

I'm developing certain sdk to provider some features for other android apps. One library project of my sdk project dependencies has some .so lib files. When assembling my sdk project to aar package with gradle, I found that the .so files are not included. How to assemble .so lib files into aar package?

Here is the build.gradle of the sdk project:

apply plugin: 'com.android.library'

android {
    signingConfigs {
        debug {
            keyAlias 'debug.keystore'
            keyPassword 'ssdebug'
            storeFile file('release-tools/debug.keystore')
            storePassword 'ssdebug'
        }
        release {
            keyAlias 'release.keystore'
            keyPassword 'dddd'
            storeFile file('../seedstore/release.keystore')
            storePassword 'dddd'
        }
    }
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 22
        signingConfig signingConfigs.release
    }

    sourceSets {
        main {
            jniLibs.srcDir file('jni/')
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),      'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            signingConfig signingConfigs.debug
            }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile project(':alisdk')
    compile project(':jdsdk')
}

I just did exactly same thing after thousand times trying, finally go through. -

  1. I used android studio to create a android library module.
  2. in this module, create the xxx.java interface file with the package name exactly matching the jni interface.
  3. /moduleName/src/main/ create a folder "jniLibs"
  4. copy all the *.so file with their platform-name into .../jniLibs it will look like: -/jniLibs/ ->/armeabi/->libxxx.so ->/x86/->libxxx.so ...
  5. No need to change build scrips, build the library module
  6. the .arr file should be at /moduleName/build/outputs/xxx.aar
  7. use extractor tool to unzip final xxx.aar, the *.so files should be under .aar/jni/

//notes: I had tried to add *.so file into a xxx.jar, add it under module's libs , add its compile dependence. The .aar had packaged it into libs. However, when the user use this .aar, there is link error for the native function call.

Another easier solution, add the following statements under module build.gradle:

buildTypes {
    debug {
        ndk {
            abiFilters 'armeabi'
        }
    }
    release {
        ndk {
           abiFilters 'armeabi'
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM