Android-NDK______1.环境搭建

  1. export ANDROID_SDK=”<path to your Android SDK directory>”
           export ANDROID_NDK=”<path to your Android NDK directory>”
    
           export PATH=”$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-
           tools:$ANDROID_NDK”
    
    
    
    
    
    //Test
  1. Open a command-line prompt (or Cygwin prompt on Windows)

  2. Go to hello-jnisample directory inside the Android NDK. All the following stepshave to performed from this directory:

           $ cd $ANDROID_NDK/samples/hello-jni
    
  3. Create Ant build file and all related configuration files automatically usingandroidcommand (android.baton Windows). These files describe how to compile andpackage an Android application:

    //生成ant自动打包

           android update project –p .
    
    // 如果想制订编译的target
    android update project -p . --target android-8
    
  4. Buildlibhello-jninative library withndk-build, which is a wrapper Bashscript around Make. Commandndk-buildsets up the compilation toolchain fornative C/C++ code and calls automatically GCC version featured with the NDK.

    $ ndk-build 

    1. Make sure your Android development device or emulator is connected and running.

    2. Compile, package, and install the final HelloJni APK (an Android applicationpackage). All these steps can be performed in one command, thanks to Ant buildautomation tool. Among other things, Ant runs javacto compile Java code, AAPTto package the application with its resources, and finally ADB to deploy it on thedevelopment device. Following is only a partial extract of the output:

      最新的使用

      ant debug install

      //$ ant install 

      1. Launch a shell session using adb(oradb.exeon Windows). ADB shell is similar toshells that can be found on the Linux systems:

        $ adb shell

      2. From this shell, launch HelloJni application on your device or emulator. To do so, useam, the Android Activity Manager. Commandamallows to start Android activities,services or sending intents (that is, inter-activity messages) from command line.Command parameters come from the Android manifest:

               # am start -a android.intent.action.MAIN -n com.example.hellojni/
               com.example.hellojni.HelloJni
        
        
        
        启动Activity
      3. Finally, look at your development device. HelloJni appears on the screen! 

         就看到了结果




page57image12136 page57image12296 page57image12456

$ ndk-build

page57image13544

你可能感兴趣的:(NDK)