Showing posts with label ndk. Show all posts
Showing posts with label ndk. Show all posts

Monday, 22 December 2014

How to use Curl Library in Android


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

How to compile Curl Library for Android in Linux


1. Download the source code of curl library http://curl.haxx.se/download.html

2.Create a file build_andorid.sh and copy below content and save file into Curl folder.

 #!/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  

3.Change build_android.sh mode to executable mode,Open terminal and head(i,e. cd)  to curl directory and run below code.

 sudo chmod +x 777 build_android.sh  
 ./build_android.sh  

4. If you want to download compiled curl library  for android click below link
https://github.com/JohnnyIqbal/Curl_For_Android_Compiled

5. Android Example of Curl Library https://github.com/JohnnyIqbal/AndroidCurlEx

Tuesday, 16 December 2014

How to port C library to Android as a static library.

Hi,

How to port C library to Android as a static library.

We build the  C library as a static library(*.a) and build a shared library using static library. because Android packaged only shared library in apk.
SourceCode Link:https://github.com/JohnnyIqbal/PortStaticEx.git

How to port C library to Android as a shared library(.so)

Hi,

How to port C library to Android as a shared library(.so).

We build C library as a shared library for android because android packaged only shared library in apk.

SourceCode Link:https://github.com/JohnnyIqbal/PortSharedEx.git

Thursday, 17 April 2014

NDKHello2 Tutorial

Hi,
This is my Second NDKHello2 Demo project for newbies

SourceCode Link:https://github.com/JohnnyIqbal/NDKHello2
Please add appcompat library to run this project

In this demo I added a folder src in jni folder and tried to compile.

I followed this process to make this project.

1. Create NativeLib.java file

2. Open terminal and head to project directory
  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)
or you can use this command
 javah -jni -o ../../jni/NativeLib.h com.iqbal.ndkhello.ndk.NativeLib  

4. Create NativeLib.c file and copy method signature in NativeLib.c
and don't foreget to include NativeLib.h


 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"); }  

Note:NewStringUTF sometimes this function shows error means red line to suppress this error please update your CDT.

5. Add new folder in jni called src add some c files and header files as I did main.c and main.h

6. Call main.h function in NativeLib.c by including main.h header files.
 #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;  
 }  

7.Now create Android.mk file and write these lines to build
 LOCAL_PATH:=$(call my-dir)  
 include $(CLEAR_VARS)   
 LOCAL_MODULE:=hello2   
 LOCAL_SRC_FILES:=NativeLib.c src/main.c  
 include $(BUILD_SHARED_LIBRARY)  

8.Create Application.mk to suppress the Warnning or error android-19 is larger than minsdkversion 8 and write this lines
 APP_PLATFORM:=android-8  
android-8 is my minsdkversion so be sure about this change according to minsdkversion in AndroidManifest.xml


9.Open terminal head to project root and fire this command
 ndk-build  

10. Now run your Android NDKHello Project.


Things after Kotlin Android Extensions

Things after Kotlin Android Extensions(KTX) I remembered in MVVM when I have to declare ViewModel, I initialize View Model like this. p...