gradle - Using Prebuilt library in Android Studio -


i'm making jni function in android generate file checksum using boringssl.

so built boringssl shared library use prebuilt library in android studio.

the build output this. enter image description here

i copied *.so file project src/main/jnilibs/lib , boringssl include folder src/main/jni

i referenced project , apply projects.

https://github.com/googlesamples/android-ndk/tree/master/hello-libs

my build.gradle file this. i'm using gradle-experimental:0.7.0( , window10, android studio 2.1.2 )

apply plugin: 'com.android.model.application'  model {     repositories {         libs(prebuiltlibraries) {             boringssl {                 headers.srcdir "src/main/jni/include/openssl"                  binaries.withtype(sharedlibrarybinary) {                     sharedlibraryfile = file("src/main/jnilibs/lib/libcrypto.so")                     sharedlibraryfile = file("src/main/jnilibs/lib/libssl.so")                 }             }         }     }     android {         compilesdkversion = 24         buildtoolsversion = '24.0.1'          defaultconfig {             applicationid = 'yein.a'             minsdkversion.apilevel = 19             targetsdkversion.apilevel = 24             versioncode = 1             versionname = '1.0'         }         ndk {             modulename = 'hello-libs'             ldlibs.addall(['android', 'log'])         }         sources {             main {                 jni {                     dependencies {                         library 'boringssl' linkage 'shared'                     }                 }                 jnilibs{                     source{                         srcdir "src/main/jnilibs/lib"                     }                 }             }         }         productflavors{             create("arm"){                 ndk.abifilters.add("armeabi-v7a")             }         }         buildtypes {             release {                 minifyenabled false                 proguardfiles.add(file('proguard-android.txt'))             }         }     } }  dependencies {     compile filetree(dir: 'libs', include: ['*.jar'])     compile 'com.android.support:appcompat-v7:24.1.1' } 

this project structure.

enter image description here

i think apply example projects, because not occurred gradle sync error.

and when use md5 function android studio auto complete function name this. enter image description here

but click run occurred error this... enter image description here

i searched lot project in google,github, , of course stackoverflow previous answers still not solve problem.

i tried change gradle version other gradle version occurred error in auto generated jni function except gradle-experimental:0.7.0.

could point me in right direction or solution?

thanks read question.

you can try call java api jni, there nice tutorial here, google recommends on site should call java api or can link libraries did.

if can't or don't want call java api can use crc32 instead of md5, crc32 uses libz library , library on ndk files. crc32 in c.

#include <zlib.h>  int checksumcrc32(char *text){     long n = crc32(0, (const void*)text, strlen(text));     printf("crc32 %d", n);     return n; } 

remember add ldlibs.addall(['z']) gradle file

in case need md5 , boringssl gradle.build file boringssl.

note: using 3 libraries compile on ubuntu, libssl.a libcrypto.a , libdecrepit.a

note2: i using com.android.tools.build:gradle-experimental:0.7.0-alpha4

apply plugin: 'com.android.model.application'  model {     repositories {         libs(prebuiltlibraries) {             libcrypto {                 headers.srcdir "./main/jni/include/openssl"                 binaries.withtype(staticlibrarybinary) {                     staticlibraryfile = file("src/main/jni/${targetplatform.getname()}/crypto/libcrypto.a")                 }             }             libssl {                 headers.srcdir "./main/jni/include/openssl"                 binaries.withtype(staticlibrarybinary) {                     staticlibraryfile = file("src/main/jni/${targetplatform.getname()}/ssl/libssl.a")                 }             }            libdecrepit {                 headers.srcdir "src/main/jni/include/openssl"                 binaries.withtype(staticlibrarybinary) {                     staticlibraryfile = file("src/main/jni/${targetplatform.getname()}/decrepit/libdecrepit.a")                 }             }         }     }     android {         compilesdkversion = 23         buildtoolsversion = "22.0.1"          defaultconfig {             applicationid = "net.app"             minsdkversion.apilevel = 9             targetsdkversion.apilevel = 23             versioncode = 1         }         ndk {             platformversion = 21             modulename = "modulename"             toolchain = "clang"             abifilters.addall([ 'armeabi-v7a'])             cflags.addall(["-fvisibility=hidden", "-fpic"])             ldlibs.addall(['log', 'z', 'android']) //libreria llog, lz y landroid          }          sources {             main {                 jni{                     dependencies {                          library "libcrypto" linkage "static"                          library "libssl" linkage "static"                          library "libdecrepit" linkage "static"                     }                 }             }         }     }     }     

i haven't used md5 have used sha256 using boringssl , works fine. can use checksum method. method sha256.

char *sha256(char *str){     unsigned char hash[sha256_digest_length];     char *output = (char *) malloc(sizeof(char)*((sha256_digest_length*2)+1));     if (output == null) {         return null;     }      sha256_ctx sha256;     sha256_init(&sha256);     sha256_update(&sha256, str, strlen(str));     sha256_final(hash, &sha256);     int i;     for(i = 0; < sha256_digest_length; i++){         sprintf(&output[i*2], "%02x", (unsigned int)hash[i]);     }     return output; } 

Comments