Using Androidstudio for NDK development simple configuration

Source: Internet
Author: User
Tags custom name

1. Preparatory work

Before we actually write the code, we need to do some preparatory work first:

    1. Download NDK Development Kit:Android official download page
    2. Configuring System Environment Variables

After downloading the NDK development package, unzip directly to any directory, then need to configure the system environment variables, the reason is to configure the environment variables, to facilitate the use of the command ndk-build script for NDK compilation. The configuration reference is as follows:

    • Windows System Configuration
      • Environment variable PATH added: D:\ProgramFile\android-ndk-r11c-windows-x86_64;

    • MacOS System Configuration
      • Open the terminal under the Mac system and enter:
        >touch. Bash_profile
        >open-e. Bash_profile
        This will bring up a ". Bash_profile" file.

      • Export android_home=/users/edwin/library/android/sdk/
        Export Path=${path}:${android_home}ndk-bundle

2. Project configuration

We have to do some extra work before using Androidstudio , we need to add the path to build the NDK in the project root local.properties :ndk.dir=/ USERS/LIANGQI/ANDROID-NDK

  • create android.mk
    • Android.mk file is used to specify the configuration information compiled by the source code, such as the working directory, the name of the compiled module, the files involved in compiling, and so on, as follows:

        
      1. local_path: Sets the working directory, and My-dir returns the directory where the Android.mk file is located.
      2. Clear--vars: Clears almost all variables starting with Local--path (excluding Local_path).
      3. local_module: Used to set the name of the module.
      4. local_src_files: Used to specify a C + + source file name that participates in module compilation.
      5. Build_shared_library: The role is to specify the generated static library or shared library module list that the shared library relies on at run time.
  • Create Application.mk
    •   

      This file is used to configure the compiler platform related content, our most commonly used estimate is only the App_abi field, which is used to specify which CPU architectures we need to base the. So file, of course you can configure multiple platforms:

      App_abi: = Armeabi armeabi-v7a x86 MIPS

  • using the Gradle script
    •   

      Of course, the machine does things we try to get the machine to do, so, next I intend to use Build.gradle to add some configuration, so that Gradle automatically help me to complete the compilation work, this is simply cool crooked!

      With Gradle, you no longer have to manually add android.mk and application.mk files, everything can be done in the Build.gradle file, where we directly post the NDK-related configuration in Build.gradle:

      Android {    compilesdkversion    buildtoolsversion "23.0.3"    defaultconfig {        ApplicationID " Com.edwin.xxxx "        minsdkversion        targetsdkversion        versioncode 1        versionname"        1.0 "ndk{            //generated so name            //log Printing            Abifilters "Armeabi", "armeabi-v7a", "x86"    //outputs specify so libraries under three ABI architectures. Currently dispensable.         }        .....................         .....................        .....................    }}  

3. Add something Addroid call C code (for example)

Dry! Dry! Dry!

Monitoring app is uninstalled, unfortunately this method can be used after API19, hey!

The principle of this piece of code you need to know the fork Bomb (fork bomb)

    1. In the field of computer, it is a service blocking attack using the system call fork (or other equivalent method);
    2. Unlike viruses and worms, a fork bomb is not contagious, and a fork bomb can cause a system with a process/program limit to start a new phase of work, and a system that does not limit the number of processes to stop responding;
    3. The self-replicating program, represented by fork bombs, is sometimes referred to as wabbit.

#include <jni.h>#include<stdio.h>#include<unistd.h>#include<android/log.h>#defineLog_tag "Edwin"#defineLOGD (...) __android_log_print (Android_log_error, Log_tag, __va_args__)JniexportvoidJnicall/** * Monitor software is uninstalled * 1. Pop-up Browser, * 2. or delete SD card data. This directory app uninstall system does not automatically delete the/storage/sdcard/custom name folder/**/Java_com_edwin_uninstallapp_mainactivity_uninstalllistener (jnienv*env, jobject instance) {    intCode =Fork (); if(Code >0) {        //Parent ProcessLOGD ("parent-->code=%d\n", code); } Else if(Code = =0) {        //Child ProcessLOGD ("children-->code=%d\n", code); intStop =1;  while(stop) {//determine if the application directory exists every 1 secondsSleep1); FILE*file = fopen ("/data/data/com.edwin.uninstallapp","R"); if(File = =NULL) {LOGD ("uninstall-->code=%d\n", code); //TODO launch browser survey via Linux command ... Delete files, etc. operationsEXECLP ("am","am","Start"," -A","Android.intent.action.VIEW","- D",                       "http://wuhaoyou.com/wp/", NULL); Stop=0;            }        }    } Else {        //otherLOGD ("error-->code=%d\n", code); }}

Using Androidstudio for NDK development simple configuration

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.