Featured Post

Android NDK with build.gradle example


Android.mk
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := su
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_STATIC_LIBRARIES := sqlite3 libcutils libc
LOCAL_C_INCLUDES := $(LOCAL_PATH)/sqlite3
LOCAL_SRC_FILES := super/su.c super/activity.c super/db.c super/utils.c super/daemon.c super/pts.c
include $(BUILD_EXECUTABLE)


include $(CLEAR_VARS)

LOCAL_MODULE := reboot
LOCAL_LDFLAGS := -llog
LOCAL_STATIC_LIBRARIES := sqlite3
LOCAL_C_INCLUDES := $(LOCAL_PATH)/sqlite3
LOCAL_SRC_FILES := reboot/reboot.c
include $(BUILD_EXECUTABLE)


include $(CLEAR_VARS)

LOCAL_MODULE := sqlite3
LOCAL_SRC_FILES := sqlite3/sqlite3.c
LOCAL_CFLAGS := -DSQLITE_OMIT_LOAD_EXTENSION
include $(BUILD_STATIC_LIBRARY)



build.gradle
--------------
import org.apache.tools.ant.taskdefs.condition.Os
import com.android.build.gradle.internal.api.ApplicationVariantImpl 

 apply plugin: 'com.android.application'




    android {
        compileSdkVersion 23
        buildToolsVersion  "23.0.1"

        defaultConfig.with {
            applicationId "com.iamsafe"
            minSdkVersion 15
            targetSdkVersion 23





        }
     buildTypes {
            debug {
                minifyEnabled = false
                useProguard = true
                proguardFiles.add(file('proguard-rules.txt'))


            }
        }



    }





dependencies {
    compile 'com.android.support:support-v4:23.0.1'
    compile files('libs/asmack-android-8-0.8.10.jar')
    compile files('libs/commons-io-2.0.1.jar')
    compile files('libs/httpclient-osgi-4.2.1-sources.jar')
    compile files('libs/httpcore-4.3.2.jar')
    compile files('libs/httpmime-4.1.2.jar')
}


buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.android.tools.build:gradle-experimental:0.7.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}



   project.ext.versionCodes = ['armeabi':1, 'armeabi-v7a':2, 'arm64-v8a':3, 'mips':5, 'mips64':6, 'x86':8, 'x86_64':9] //versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-*
    
    // call regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec) {
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
 
            commandLine 'ndk-build.cmd', '-C', file('./').absolutePath
        } else {
            commandLine 'ndk-build', '-C', file('$buildFile.parent.name').absolutePath
        }
    }
    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }

Application.mk
--------------------
APP_ABI := x86 armeabi mips
APP_PIE = true


hello-jni.c
------------

//
// Created by vpilaka on 6/22/2016.
//

#include "hello-jni.h"

#include
#include

jstring
Java_com_example_android_camera2video_CameraActivity_getJniString(JNIEnv* env, jobject thiz){
    return (*env)->NewStringUTF(env, "Hello from JNI from Venkata Sitaram!");
}


Note: make sure that you activity.java class that should be in the same package as com.example.android.camera2video 

public class CameraActivity extends Activity{

public native String getJniString();
  
   public void onCreate(Bundle savendnInstance){

  //to do your code goes here 
}

}

Comments

Popular posts from this blog

[Inside AdSense] Understanding your eCPM (effective cost per thousand impress...