1

Previously I had two Android Studio projects. One is using some shared library placed in /src/main/jniLibs (lets call that project bmf). The second project is my actual library which is using that other project (bmf) as an .aar.

If some application is now using the library I had to add the project with the shared library (bmf) as well because the .so files were not packed. Because I want to merge the two projects to one library project I have imported the bmf project as a module. Now if I assemble the library, the .so file of the module is not included. How can I fix that?

My app-module build script looks like:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 15
    buildToolsVersion "26.0.2"

    lintOptions {
        abortOnError false
    }

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 15
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:18.0.0'

    implementation project(':pbJavaBmf')
}

My bmf-module build script looks like:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 15
    buildToolsVersion "26.0.2"

    lintOptions {
        abortOnError false
    }

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 15
    }

    externalNativeBuild {
        ndkBuild {
            path "src/main/jni/Android.mk"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    task buildNative(type: Exec, description: 'Pack .so with module') {
        def ndkDir = android.ndkDirectory
        commandLine "$ndkDir/ndk-build.cmd",
                '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
                '-j', Runtime.runtime.availableProcessors(),
                'V=1',
                'NDK_DEBUG=1',
                'NDK_LIBS_OUT=../jniLibs'
    }

}

dependencies {
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:support-v4:18.0.0'
}
dan
  • 149
  • 1
  • 12
  • Is `jniLibs` folder being created? Where? Because it seems `buildNative` is creating it outside of bmf-module folder. Probably should be something like that: `'NDK_LIBS_OUT=./jniLibs'` – ahasbini Jan 20 '18 at 19:51
  • Correction: `'NDK_LIBS_OUT=src/main/jniLibs'` – ahasbini Jan 20 '18 at 19:55
  • Yes, the jniLibs Folder is created in `\src\main\jniLibs` of the module (pb). But if I assemble the aar, they are not in the jni folder of the aar. However if I put my jniLibs folder in the app module they get packed with the aar. But that seems like cheating to me, because they belong to the module (pb). – dan Jan 21 '18 at 15:58
  • Totally agree with u. To be honest I'm not sure about ndk-build but im using cmake and am not facing this issue. Even it does not need to compile and place the binaries in jniLibs, they're automatically packaged in the aar from the jni folder directly. In case u'd like to checkout an example, here's one of my answers: https://stackoverflow.com/a/43886764 and I could help u with migrating to cmake if you could post more of the module like the Android.mk and the structure of the native code. – ahasbini Jan 21 '18 at 16:05
  • 1
    I've decided to merge the two projects without using modules as I've no further time for this problem and now everything works. Thank you for your help! @ahasbini – dan Jan 24 '18 at 16:16

0 Answers0