Android NDK 安裝 運行

來源:互聯網
上載者:User

 

1.安裝NDK  到這裡:http://developer.android.com/sdk/ndk/index.html 下載NDK. 解壓之。

To install the NDK, follow these steps:

  1. From the table at the top of this page, select the NDK package that is appropriate for your development computer and download the package.
  2. Uncompress the NDK download package using tools available on your computer. When uncompressed, the NDK files are contained in a directory called android-ndk-<version>. You can rename the NDK directory if necessary and you can move it to any
    location on your computer. This documentation refers to the NDK directory as <ndk>.

You are now ready to start working with the NDK.

 

 

2.  Windows下需要安裝cygwin  的make組件,ndk-build是在cygwin下啟動並執行。

Getting Started with the NDK

Once you've installed the NDK successfully, take a few minutes to read the documentation included in the NDK. You can find the documentation in the <ndk>/docs/directory. In particular, please read the OVERVIEW.HTML document completely, so that
you understand the intent of the NDK and how to use it.

If you used a previous version of the NDK, take a moment to review the list of NDK changes in the CHANGES.HTML document.

Here's the general outline of how you work with the NDK tools:

  1. Place your native sources under <project>/jni/...
  2. Create <project>/jni/Android.mk to describe your native sources to the NDK build system
  3. Optional: Create <project>/jni/Application.mk.
  4. Build your native code by running the 'ndk-build' script from your project's directory. It is located in the top-level NDK directory:
    cd <project><ndk>/ndk-build

    The build tools copy the stripped, shared libraries needed by your application to the proper location in the application's project directory.

  5. Finally, compile your application using the SDK tools in the usual way. The SDK build tools will package the shared libraries in the application's deployable .apk file.

For complete information on all of the steps listed above, please see the documentation included with the NDK package.

 

 

3.產生build.xml

On the command line:

  1. Change to the <ndk-root>/samples/hello-jni directory.
  2. Run the following command to generate a build.xml file:
    android update project -p . -s
    Dos命令運行結果:
    F:/Android_Tools/NDK/android-ndk-r5c/samples/hello-jni>android update project -p . -sUpdated local.propertiesAdded file F:/Android_Tools/NDK/android-ndk-r5c/samples/hello-jni/build.xmlAdded file F:/Android_Tools/NDK/android-ndk-r5c/samples/hello-jni/proguard.cfg Updated local.propertiesAdded file F:/Android_Tools/NDK/android-ndk-r5c/samples/hello-jni/tests/build.xmlAdded file F:/Android_Tools/NDK/android-ndk-r5c/samples/hello-jni/tests/proguard.cfg

 

4.Compile the native code using the ndk-build command.

cd <ndk-root>/samples/hello-jni<ndk_root>/ndk-build

Cygwin運行結果:

5. 這一步可以在eclipse中clean一下,重建apk.

 

Build and install the application as you would a normal Android application. If you are using Eclipse, run the application to build and install it on a device. If you are using Ant, run the following commands from the project directory:

 

ant debugadb install bin/HelloJni-debug.apk

log:
06-21 02:45:49.380: INFO/ActivityManager(58): Start proc com.example.hellojni for activity com.example.hellojni/.HelloJni: pid=334 uid=10038 gids={1015}06-21 02:45:49.662: INFO/jdwp(334): Ignoring second debugger -- accepting and dropping06-21 02:45:50.482: DEBUG/dalvikvm(334): Trying to load lib /data/data/com.example.hellojni/lib/libhello-jni.so 0x44edea6006-21 02:45:50.500: DEBUG/dalvikvm(334): Added shared lib /data/data/com.example.hellojni/lib/libhello-jni.so 0x44edea6006-21 02:45:50.500: DEBUG/dalvikvm(334): No JNI_OnLoad found in /data/data/com.example.hellojni/lib/libhello-jni.so 0x44edea60, skipping init06-21 02:45:51.282: INFO/ActivityManager(58): Displayed activity com.example.hellojni/.HelloJni: 2011 ms (total 1089367 ms)

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.