找回密码
 立即注册
代码youcodeNDK | android开发 2022-10-29 45 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
一、什么是NDK?为什么要用它?比较简单的说,NDK是一套交叉编译工具,它可以帮你把你用C或C++书写的代码,编译为。so(相似与win下的。dll)格式的文件,使你可以在你的Android程序当顶用Java语言(JNI)调用这些代码当你想在Java中调用你的C、C++代码时你就可以用它(废话?),那么什么时候你可能考虑使用C、C++代码呢?比如说,你原来用C、C++写过一个游戏程序,里边有你很多的封装好的游戏业务逻辑、算法等代码,你现在想把这个游戏移植到Android上去,如何办?莫非这些业务逻辑、算法要全面用Java重写一遍嘛?现在有了NDK,不用了,你可以直接编译移植这代码了,所以说如果你有代码复用需求的时候,你就可以用它。再举一个比如,比如说你现在用Android手机的摄像头收集图片信息,收集后的图片你使用Java书写了一个压缩算法进行压缩操作,这个算法十分的耗时,消耗CPU,作用很不理想。这时你就可以测试采纳C来书写这个压缩算法,这时你就可能发现,改用C代码履行后,效率提高了几倍乃至十几倍。当你的客户对程序的性能、速度要求比较高的时候,你也可以考虑用C、C++代码编写部分代码,以满足客户要求。所以说如果没有NDK编译的话,你的这些代码在Android上是跑不起来的。二、看起来似乎不错,我现已想试试了,我要如何做?什么是cygwin?为什么要用它?因为NDK编译代码时有必要要用到make和gcc,所以你得先弄个linux环境,如果你只有windows又不想安装linux环境如何呢?这时候,cygwin上场了,cygwin是一个在windows平台上运行的unix模拟环境,它用于学习unix/linux操作环境,或许从unix到windows的使用程序移植,十分有效。通过它,你就可以在不安装linux的状况下使用NDK来编译C、C++代码了。本资料共包括以下附件:
配置NDK集成开发环境全过程第一版.doc
.....

(1、 What is NDK? Why use it? To put it simply, NDK is a cross compilation tool that can help you compile code written in C or C  into. The so (similar to the. dll under win) format file allows you to call these codes in the Java language (JNI) when you want to call your C and C  code in Java, When are you likely to consider using C and C  code? For example, you used to write a game program in C and C  , which contains a lot of your encapsulated game business logic, algorithm and other code. Now you want to transplant this game to Android, how do you do? Is it possible that these business logic and algorithms should be completely rewritten in Java? Now that NDK is available, you can directly compile and transplant the code. So if you have code reuse requirements, you can use it. Take another example. For example, you now use the camera of your Android phone to collect image information. For the collected images, you use Java to write a compression algorithm for compression. This algorithm is very time-consuming, consumes CPU, and does not work well. At this time, you can test and adopt C to write the compression algorithm. Then you may find that the efficiency is improved several times or even more than ten times after using C code to perform. When your customers have high requirements for program performance and speed, you can also consider using C, C  code to write some code to meet customer requirements. So without NDK compilation, your code can't run on Android. 2、 It looks good. I want to try now. How do I do it? What is cygwin? Why use it? Because it is necessary to use make and gcc when NDK compiles code, you need to get a Linux environment first. What if you only have Windows and don't want to install a Linux environment? At this time, cygwin came on the stage. Cygwin is a unix simulation environment running on the Windows platform. It is used to learn the unix/linux operating environment. Perhaps the migration of user programs from unix to Windows is very effective. With it, you can use NDK to compile C and C  code without installing Linux. This document includes the following annexes:
Configuring the NDK Integrated Development Environment Version 1. doc
.....)

[下载]20504570879.rar




上一篇:悬浮歌词(迷你歌词)
下一篇:android开发中log实例