Cipher.so: Can not Add Cipher.so to my project

About this issue

Most upvoted comments

Okay, now the header files are generated, thanks.

But if I run the app, the “cipher-lib.so” file not found :

java.lang.UnsatisfiedLinkError: dlopen failed: library "libcipher-lib.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
        at java.lang.System.loadLibrary(System.java:1664)
        at net.idik.lib.cipher.so.CipherCore.<clinit>(CipherCore.java:9)
        at net.idik.lib.cipher.so.CipherCore.get(CipherCore.java:18)

the line where the error occurs is: System.loadLibrary("cipher-lib");

For all with the same Problem, the following part blocked that the libcipher-lib.so was packed into the .apk file:

tasks.whenTaskAdded { task ->
        // something specific
}

I replaced it with:

afterEvaluate {
    android.productFlavors.all {
        flavor ->
    }
}

So it is working now. Thank you for all your help so far @AdeelTariq!

@CaptainSilva I found a solution to execute ‘generateCipherSo’ automatically. Just add this inside the build.gradle for your individual flavors (if you have different keys for different flavors):

afterEvaluate {
    android.productFlavors.all {
        flavor ->
            tasks."extractDeepLinksFalvor1Debug".finalizedBy(generateFlavor1DebugCipherSoHeader)
            tasks."extractDeepLinksFalvor2Debug".finalizedBy(generateFlavor2DebugCipherSoHeader)
            ...
    }
}

So the ‘extern-keys.h’ will be procuced just before task ‘buildCMakeDebug’ , where it’s needed.

If you do not have different keys you can use the ‘configureCMakeDebug’ task:

afterEvaluate {
    android.productFlavors.all {
        flavor ->
            tasks."configureCMakeDebug".finalizedBy(generateSomeFlavorDebugCipherSoHeader)
            ...
    }
}

Hope it helps.

Jitpack builds are failing and this repository is not the only one effected. Maybe @linisme can fix the problem but they are not maintaining the repo anymore. So the workaround for now is to add a jar of the library to your project. Easiest is to find the cached jar file of the library on your system. Obviously if you never used the library before you won’t have a cached version. In that case you can build the jar file on your own.

To get the cached file, find the gradle cache directory on your system and go to ~/.gradle/caches/modules-2/files-2.1/com.github.MEiDIK or ~/.gradle/caches/modules-2/files-2.1/com.github.linisme

In there you’ll find the cached jar. Copy it to your project. Mine is inside the app/libs folder.

Next add this one line to your top level gradle file:

buildscript {
    repositories {
        …
        flatDir dirs: "app/libs"    // <-- Relative path to where the jar file is
    }
    dependencies {
        …
    }
}

Your project should compile now. Also the gradle directory may be in a different location. Or your project may be structured differently. So adjust accordingly.