To compile Curl library for android, follow this post
Here is the simple Android Example using Curl Library.
Source Code:https://github.com/JohnnyIqbal/AndroidCurlEx
#!/bin/bash NDK=<yourpath>/android-ndk-r9d SYSROOT=$NDK/platforms/android-19/arch-arm/ CFLAGS="-fno-exceptions -Wno-multichar -mthumb -mthumb-interwork -nostdlib -lc -ldl -lm " LDFLAGS="-Wl,--fix-cortex-a8" export AR="$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-ar" export LD="$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-ld" export CC="$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc --sysroot=$SYSROOT" ./configure \ --host=arm-linux-androideabi \ --prefix=/<your output folder path where include,lib and bin will folder copy >/curllib/ \ --exec-prefix=/<your output folder path where include,lib and bin will folder copy >/curllib/ make clean make make install
sudo chmod +x 777 build_android.sh
./build_android.sh
cd bin/classes
and generate header files of NativeLib.java using this command javah -jni com.iqbal.ndkhello.ndk.NativeLib
3. Copy NativeLib.h file in jni folder (Create if not exist in project root) javah -jni -o ../../jni/NativeLib.h com.iqbal.ndkhello.ndk.NativeLib
Method Signature eg:
JNIEXPORT jstring JNICALL Java_com_iqbal_ndkhello_ndk_NativeLib_getHello2
this is the declared method in header files and change to method defination #include"NativeLib.h"
JNIEXPORT jstring JNICALL Java_com_iqbal_ndkhello_ndk_NativeLib_getHello (JNIEnv *env, jclass clz){ return (*env)->NewStringUTF(env,"Hello World2"); }
#include"src/main.h"
JNIEXPORT jint JNICALL Java_com_iqbal_ndkhello2_ndk_NativeLib_getAdd(
JNIEnv *env, jclass clz, jint a, jint b) {
int c=add(a,b); //this function declared in main.h and defiened in main.c
return c;
}
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:=hello2
LOCAL_SRC_FILES:=NativeLib.c src/main.c
include $(BUILD_SHARED_LIBRARY)
APP_PLATFORM:=android-8
android-8 is my minsdkversion so be sure about this change according to minsdkversion in AndroidManifest.xml ndk-build
Things after Kotlin Android Extensions(KTX) I remembered in MVVM when I have to declare ViewModel, I initialize View Model like this. p...