Simple configuration for NDK development using AndroidStudio, androidstudiondk

Source: Internet
Author: User

Simple configuration for NDK development using AndroidStudio, androidstudiondk
1. Preparations

Before writing the code, we need to make some preparations:

After downloading the NDK Development Kit, decompress the package to any directory and configure the system environment variables. The environment variables must be configured to facilitate ndk compilation using the NDK-build script. The configuration is as follows:

  • Windows System Configuration
    • Append the environment variable PATH: D: \ ProgramFile \ android-ndk-r11c-windows-x86_64;

  • MacOS System Configuration
    • Open the terminal in the mac system and enter:
      > Touch. bash_profile
      > Open-e. bash_profile
      This will pop up a ". bash_profile" file.

    • Export ANDROID_HOME =/Users/edwin/Library/Android/sdk/
      Export PATH =$ {PATH }:$ {ANDROID_HOME} ndk-bundle

2. project configuration

Before using AndroidStudio for development, we need to add the NDK compiling path: ndk. dir =/Users/liangqi/android-ndk in local. properties under the root directory of the project.

  • Create Android. mk
    •   

      The Android. mk file is used to specify the configuration information for source code compilation, such as the working directory, the name of the compilation module, and the file to be compiled. The general content is as follows:

      LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := hello_jniLOCAL_SRC_FILES := hello_jni.cinclude $(BUILD_SHARED_LIBRARY)
  • Create Application. mk
    •   

      This file is used to configure compilation platform-related content. Our most common estimation is the APP_ABI field, which specifies the. so file based on which CPU architecture we need. Of course, you can configure multiple platforms:

      APP_ABI := armeabi armeabi-v7a x86 mips

       

  • Use gradle script
    •   

      Of course, we should try our best to let the machine do what the machine does. Therefore, I plan to use build next. gradle to add some configuration, so that Gradle can automatically help me complete the compilation work, this is just a cool!

      When using gradle, you no longer need to manually add Android. mk and Application. mk file, everything is in build. this can be done in the gradle file. Here we paste the build directly. configuration related to ndk in gradle:

       

      Android {compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig {applicationId "com. edwin. xxxx "minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName" 1.0 "ndk {moduleName" forkApp "// generated so name ldLibs" log "// Log print abiFilters" armeabi ", "armeabi-v7a", "x86" // outputs so libraries under the specified three abi architectures. Currently, it is optional. }....................................... ........................}}

 

3. Add some Addroid to call C code (for example)

Dry goods! Dry goods! Dry goods!

Check whether the APP is uninstalled. Unfortunately, this method can be used after API19!

For the principle of this code, you need to know about the fork bomb (fork bomb)

 

# Include <jni. h> # include <stdio. h> # include <unistd. h> # include <android/log. h> # define LOG_TAG "Edwin" # define LOGD (...) _ android_log_print (ANDROID_LOG_ERROR, LOG_TAG, _ VA_ARGS _) JNIEXPORT void JNICALL/*** whether the listening software is uninstalled * 1. the browser is displayed. * 2. or delete the SD card data. the APP uninstall system will not automatically delete/storage/sdcard/custom name Folder/**/Java_com_edwin_uninstallapp_MainActivity_uninstallListener (JNIEnv * env, jobject instance) {int code = fork (); if (code> 0) {// The parent process LOGD ("parent --> code = % d \ n", code);} else if (code = 0) {// sub-process LOGD ("children --> code = % d \ n", code); int stop = 1; while (stop) {// judge whether the application directory has sleep (1) Every second; FILE * file = fopen ("/data/com. edwin. uninstallapp "," r "); if (file = NULL) {LOGD (" uninstall --> code = % d \ n ", code ); // TODO starts the browser questionnaire survey using Linux commands... execlp ("am", "am", "start", "-a", "android. intent. action. VIEW ","-d "," http://wuhaoyou.com/wp/ ", NULL); stop = 0 ;}}} else {// other LOGD ("error --> code = % d \ n", code );}}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.