I want to use OpenCL in Android Studio,
I grabbed libOpenCL.so from my android device device and put it in jniLibs/[ABI]/
I put header files to jni/CL/
EDIT :
I switched to gradle-experimental:0.6.0-alpha7 and it bought some other problems, I replaced the first part with this:
repositories {
libs(PrebuiltLibraries) {
OpenCL {
headers.srcDir "src/main/jni/CL"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("src/main/jniLibs/${targetPlatform.getName()}/libOpenCL.so")
}
}
}
}
android.sources {
main {
jni {
dependencies {
library "OpenCL" linkage "shared"
}
}
}
}
Now it gives these errors:
C:\Users\Umut\Desktop\HelloJNI\app\src\main\jniLibs\arm64-v8a\libOpenCL.so: error adding symbols: File in wrong format
Error:error: ld returned 1 exit status
Error:Execution failed for task ':app:linkHello-jniArm64-v8aDebugAllSharedLibrary'. A build operation failed. Linker failed while linking libhello-jni.so.
What does "file in wrong format" can even mean? I took the library directly from my android phone.
Can, anybody please help me on what I have done wrong or what should I do to fix this problem?
As I am new to android development and gradle, please apologize me if I have misunderstood something.
.
PREVIOUS ATTEMPT WITH GRADLE EXPERIMENTAL 0.4.0
When using gradle-experimental:0.4.0 and I put this to my build.gradle file:
android.sources {
main {
jniLibs {
dependencies {
library file("src/main/jniLibs/armeabi-v7a/libOpenCL.so") abi "armeabi-v7a"
library file("src/main/jniLibs/armeabi/libOpenCL.so") abi "armeabi"
library file("src/main/jniLibs/x86/libOpenCL.so") abi "x86"
}
}
}
}
Here is my ndk block in build.gradle:
android.ndk {
moduleName = "openCLJni"
cppFlags.addAll(["-I${file("src/main/jniLibs/")}".toString()])
ldLibs.addAll(["android", "log"])
stl = "stlport_static"
}
I try to make a very simple function call from my openCLJni.c :
jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
jobject thiz )
{
cl_uint ret_num_platforms;
cl_platform_id platform_id = NULL;
cl_int ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
return (*env)->NewStringUTF(env, "Hello from JNI");
}
Yet it gives me this error:
Error:(65) undefined reference to `clGetPlatformIDs'
and
Error:Execution failed for task ':app:linkArm64-v8aDebugAllHello-jniSharedLibrary'.
A build operation failed. Linker failed while linking libhello-jni.so. See the complete log at: file:///C:/Users/Umut/Desktop/OpenCLTest2/app/build/tmp/linkArm64-v8aDebugAllHello-jniSharedLibrary/output.txt
ldLibs.addAll(["android", "log"])whereandroidrefers tolibandroid.soandlogrefers toliblog.sofor your#include <android/log.h>stuff. You have already setup the include paths for headers, but didn't tell the linker anything aboutclGetPlatformIDs- Gábor BuellaldLibs.addAll(["android", "log", "OpenCL"])it gives me this error:C:/Users/MYNAME/AppData/Local/Android/sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9/../../../../aarch64-linux-android/bin/ld.exe: cannot find -lOpenCL- Umut Ulutas