Clean up inline code and typos
Source Link
david.schreiber
  • 3.9k
  • 2
  • 29
  • 46

Some important rules:

  1. you should use ndk-buildndk-build instead directly arm-linux-androideabi-gccarm-linux-androideabi-gcc

  2. in Android.mkAndroid.mk of library type next options: LOCAL_LDFLAGS += -Wl,--export-dynamicLOCAL_LDFLAGS += -Wl,--export-dynamic

  3. if dlerror()dlerror() returns error it doesn't mean that dlsym()dlsym() failed. Check if dlsym() realledlsym() really returns nullNULL. Because it may return a valid address but dlerror()dlerror() may return error "Symbol not found" at the same time %)) I had this stupid mistake!!! See code.

  4. You do not need call System.LoadLibrary(your_lib.so)System.LoadLibrary(your_lib.so). Only dlopen(your_lib.so)dlopen("your_lib.so") from native code with RTLD_NOWRTLD_NOW or RTLD_LAZYRTLD_LAZY no matter!

  5. Be sure that your_lib.soyour_lib.so is sutiatedsituated in /data/data/app_name/libs/data/data/app_name/libs

    func = (int (*)(int, int)) dlsym( dl_handle, "calculate" ); error = (char *) dlerror(); if (error != NULL) { //replace it with if ((func == NULL)&& (error != NULL)) __android_log_print(ANDROID_LOG_INFO,"nativeCode",error); return -3; }

    func = (int (*)(int, int)) dlsym( dl_handle, "calculate" );
    error = (char *) dlerror();
    if (error != NULL) { //replace it with if ((func == NULL)&& (error != NULL))
      __android_log_print(ANDROID_LOG_INFO,"nativeCode",error);
      return -3; 
    }
    

That's all :)

Some important rules:

  1. you should use ndk-build instead directly arm-linux-androideabi-gcc

  2. in Android.mk of library type next options: LOCAL_LDFLAGS += -Wl,--export-dynamic

  3. if dlerror() returns error it doesn't mean that dlsym() failed. Check if dlsym() realle returns null. Because it may return a valid address but dlerror() may return error "Symbol not found" at the same time %)) I had this stupid mistake!!! See code.

  4. You do not need call System.LoadLibrary(your_lib.so). Only dlopen(your_lib.so) from native code with RTLD_NOW or RTLD_LAZY no matter!

  5. Be sure that your_lib.so is sutiated in /data/data/app_name/libs

    func = (int (*)(int, int)) dlsym( dl_handle, "calculate" ); error = (char *) dlerror(); if (error != NULL) { //replace it with if ((func == NULL)&& (error != NULL)) __android_log_print(ANDROID_LOG_INFO,"nativeCode",error); return -3; }

That's all :)

Some important rules:

  1. you should use ndk-build instead directly arm-linux-androideabi-gcc

  2. in Android.mk of library type next options: LOCAL_LDFLAGS += -Wl,--export-dynamic

  3. if dlerror() returns error it doesn't mean that dlsym() failed. Check if dlsym() really returns NULL. Because it may return a valid address but dlerror() may return error "Symbol not found" at the same time %)) I had this stupid mistake!!! See code.

  4. You do not need call System.LoadLibrary(your_lib.so). Only dlopen("your_lib.so") from native code with RTLD_NOW or RTLD_LAZY no matter!

  5. Be sure that your_lib.so is situated in /data/data/app_name/libs

    func = (int (*)(int, int)) dlsym( dl_handle, "calculate" );
    error = (char *) dlerror();
    if (error != NULL) { //replace it with if ((func == NULL)&& (error != NULL))
      __android_log_print(ANDROID_LOG_INFO,"nativeCode",error);
      return -3; 
    }
    

That's all :)

added 23 characters in body
Source Link
Myosotis
  • 288
  • 4
  • 15

Some important rules:

  1. you should use ndk-build instead directly arm-linux-androideabi-gcc

  2. in Android.mk of library type next options: LOCAL_LDFLAGS += -Wl,--export-dynamicLOCAL_LDFLAGS += -Wl,--export-dynamic

  3. if dlerror() returns error it doesn't mean that dlsym() failed. Check if dlsym() realle returns null. Because it may returnsreturn a valid address but dlerror() returnsmay return error "Symbol not found)found" at the same time %)) I had this stupid mistake!!! See code.

  4. You do not need call System.LoadLibrary(your_lib.so). Only dlopen(your_lib.so) from native code with RTLD_NOW or RTLD_LAZY no matter!

  5. Be sure that your_lib.so is sutiated in /data/data/app_name/libs

    func = (int (*)(int, int)) dlsym( dl_handle, "calculate" ); error = (char *) dlerror(); if if (error != NULL) { //replace it with if ((func == NULL)&& (error{ != NULL))//replace it with if ((func == NULL)&& (error != NULL)) __android_log_print(ANDROID_LOG_INFO,"nativeCode",error); return -3; }

  6. You do not need call System.LoadLibrary(your_lib.so). Only dlopen(your_lib.so) from native code with RTLD_NOW or RTLD_LAZY no matter!

  7. Be sure that your_lib.so is sutiated in /data/data/<app_name>/libs

That's all :)

Some rules:

  1. you should use ndk-build instead directly arm-linux-androideabi-gcc

  2. in Android.mk of library type next options: LOCAL_LDFLAGS += -Wl,--export-dynamic

  3. if dlerror() returns error it doesn't mean that dlsym() failed. Check if dlsym() realle returns null. Because it may returns a valid address but dlerror() returns error "Symbol not found) %)) I had this stupid mistake!!! See code.

    func = (int (*)(int, int)) dlsym( dl_handle, "calculate" ); error = (char *) dlerror(); if (error != NULL) { //replace it with if ((func == NULL)&& (error != NULL)) __android_log_print(ANDROID_LOG_INFO,"nativeCode",error); return -3; }

  4. You do not need call System.LoadLibrary(your_lib.so). Only dlopen(your_lib.so) from native code with RTLD_NOW or RTLD_LAZY no matter!

  5. Be sure that your_lib.so is sutiated in /data/data/<app_name>/libs

That's all :)

Some important rules:

  1. you should use ndk-build instead directly arm-linux-androideabi-gcc

  2. in Android.mk of library type next options: LOCAL_LDFLAGS += -Wl,--export-dynamic

  3. if dlerror() returns error it doesn't mean that dlsym() failed. Check if dlsym() realle returns null. Because it may return a valid address but dlerror() may return error "Symbol not found" at the same time %)) I had this stupid mistake!!! See code.

  4. You do not need call System.LoadLibrary(your_lib.so). Only dlopen(your_lib.so) from native code with RTLD_NOW or RTLD_LAZY no matter!

  5. Be sure that your_lib.so is sutiated in /data/data/app_name/libs

    func = (int (*)(int, int)) dlsym( dl_handle, "calculate" ); error = (char *) dlerror(); if (error != NULL) { //replace it with if ((func == NULL)&& (error != NULL)) __android_log_print(ANDROID_LOG_INFO,"nativeCode",error); return -3; }

That's all :)

Source Link
Myosotis
  • 288
  • 4
  • 15

Some rules:

  1. you should use ndk-build instead directly arm-linux-androideabi-gcc

  2. in Android.mk of library type next options: LOCAL_LDFLAGS += -Wl,--export-dynamic

  3. if dlerror() returns error it doesn't mean that dlsym() failed. Check if dlsym() realle returns null. Because it may returns a valid address but dlerror() returns error "Symbol not found) %)) I had this stupid mistake!!! See code.

    func = (int (*)(int, int)) dlsym( dl_handle, "calculate" ); error = (char *) dlerror(); if (error != NULL) { //replace it with if ((func == NULL)&& (error != NULL)) __android_log_print(ANDROID_LOG_INFO,"nativeCode",error); return -3; }

  4. You do not need call System.LoadLibrary(your_lib.so). Only dlopen(your_lib.so) from native code with RTLD_NOW or RTLD_LAZY no matter!

  5. Be sure that your_lib.so is sutiated in /data/data/<app_name>/libs

That's all :)