<?xml version="1.0" standalone="yes"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>清风的blog - Android</title><link>http://blog.careff.com/</link><description>优然探索 - </description><generator>RainbowSoft Studio Z-Blog 2.2 Prism Build 140101</generator><language>zh-CN</language><copyright>Copyright (C) 2008-2024 careff.com Inc.,All  Rights Reserved.                    雅虎统计      </copyright><pubDate>Sat, 13 Jun 2026 01:32:16 +0800</pubDate><item><title>CSipsimple如何添加视频通信功能</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/461.html</link><pubDate>Tue, 19 Jan 2016 09:50:12 +0800</pubDate><guid>http://blog.careff.com/post/461.html</guid><description><![CDATA[<p>&nbsp;<span style="font: 14px/24px 微软雅黑; color: rgb(34, 34, 34); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; float: none; display: inline !important; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">CSipsimple如何添加视频通信功能</span><br style="font: 14px/24px 微软雅黑; list-style: none; margin: 0px; padding: 0px; color: rgb(34, 34, 34); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;"/></p><p style="font: 14px/24px 微软雅黑; list-style: none; margin: 0px; padding: 0px; color: rgb(34, 34, 34); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">　　默认编译出来的CSipSimple是没有视频功能的，获取你去官网下载一个插件，而如果你搜素CSipSimple视频通信的话，你会看到一个CSipSimple(小X)的，我使用了一下，默认是可以视频通话的，我们如何实现在CSipSimple官网源码的基础上添加视频功能呢，在CSipsimple最新版本编译&nbsp;里面我们下载的文件中有一个名字叫做CSipSimpleVideoPlugin的文件夹，当我们make &nbsp; VideoLibs的时候会编译这个文件里的内容，会生成libpj_video_android.so 和libpj_vpx.so这个两个库，而CSipSimpleVideoPlugin就是官方提供的那个apk的项目，我们编译一下安装在手机上也可以实现视频，我们可以把CSipSimpleVideoPlugin里面的内容整合到CSipSimple项目里面步骤如下：</p><p style="font: 14px/24px 微软雅黑; list-style: none; margin: 0px; padding: 0px; color: rgb(34, 34, 34); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">　　1.把CSipSimpleVideoPlugin里面的源码和libs拷贝到CSipSimple项目里面</p><p style="font: 14px/24px 微软雅黑; list-style: none; margin: 0px; padding: 0px; color: rgb(34, 34, 34); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">　　2.把CSipSimpleVideoPlugin里面AndroidManifest.xml里面的内容拷贝到CSipSimple对应文件里面</p><p style="font: 14px/24px 微软雅黑; list-style: none; margin: 0px; padding: 0px; color: rgb(34, 34, 34); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">　　3.整合完毕后，我们运行一下程序，然后主界面按menu键选择设置，进入媒体选项，点击Media thread count，把里面的1修改为2，进入呼叫选项，这时里面会有一个Use Video的选项，然后你选中，如果我们没有1,2步骤，这个选项是没有的，这时再返回到主界面的拨打电话界面，就会出现摄像图片，显示界面如下：</p><p style="font: 14px/24px 微软雅黑; list-style: none; margin: 0px; padding: 0px; color: rgb(34, 34, 34); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">　　<img width="480" height="800" title="点击查看大图" style="list-style: none; margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; vertical-align: top; display: inline-block; max-width: 640px;" alt="480x800" src="http://blog.careff.com/zb_users/upload/2016/1/2016011935415461.jpg"/><br style="list-style: none; margin: 0px; padding: 0px;"/></p><p style="font: 14px/24px 微软雅黑; list-style: none; margin: 0px; padding: 0px; color: rgb(34, 34, 34); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">　　效果图如下：</p><p style="font: 14px/24px 微软雅黑; list-style: none; margin: 0px; padding: 0px; color: rgb(34, 34, 34); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">　　<img width="480" height="800" title="点击查看大图" style="list-style: none; margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; vertical-align: top; display: inline-block; max-width: 640px;" alt="480x800" src="http://blog.careff.com/zb_users/upload/2016/1/2016011935415929.jpg"/><br style="list-style: none; margin: 0px; padding: 0px;"/></p><p style="font: 14px/24px 微软雅黑; list-style: none; margin: 0px; padding: 0px; color: rgb(34, 34, 34); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">　　如果不想自己编译的，可以使用我编译好的apk，</p><p>&nbsp;</p>]]></description><category>Android</category><comments>http://blog.careff.com/post/461.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=461</wfw:commentRss></item><item><title>Android 学习笔记——利用JNI技术在Android中调用、调试C++代码</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/454.html</link><pubDate>Wed, 06 Jan 2016 13:49:00 +0800</pubDate><guid>http://blog.careff.com/post/454.html</guid><description><![CDATA[<p>&nbsp;</p><div class="blog_title" style="font: 14px/18px Helvetica, Tahoma, Arial, sans-serif; text-align: left; color: rgb(51, 51, 51); text-transform: none; text-indent: 0px; letter-spacing: normal; margin-bottom: 15px; word-spacing: 0px; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;"><h3 style="margin: 0px 0px 0.5em; padding: 10px 0px 0px; line-height: 1.5em; font-size: 16px;"><a style="color: rgb(16, 138, 198); text-decoration: none;" href="http://cherishlc.iteye.com/blog/1756762">Android 学习笔记——利用JNI技术在Android中调用、调试C++代码</a><span class="actions" style="font-style: italic;"></span></h3><ul class="blog_categories list-paddingleft-2" style="list-style-type: none;"><strong>博客分类：</strong><li><p>&nbsp;</p></li><span class="Apple-converted-space">&nbsp;</span><li><p><a style="color: rgb(16, 138, 198); text-decoration: none;" href="http://cherishlc.iteye.com/category/252746">JNI</a></p></li><li><p><span class="Apple-converted-space">&nbsp;</span><a style="color: rgb(16, 138, 198); text-decoration: none;" href="http://cherishlc.iteye.com/category/261666">Android</a></p></li></ul><div class="news_tag" style="margin: 10px 0px 5px; line-height: 20px; clear: both;"><a style="margin: 0px 5px 5px 0px; padding: 0px 10px; color: rgb(255, 255, 255); text-decoration: none; display: inline-block; background-color: rgb(170, 181, 195);" href="http://www.iteye.com/blogs/tag/android">android</a>&nbsp;</div></div><div class="blog_content" id="blog_content" style="font: 14px/1.8em Helvetica, Tahoma, Arial, sans-serif; text-align: left; color: rgb(51, 51, 51); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">在Android中调用C++其实就是在Java中调用C++代码，只是在windows下编译生成DLL，在Android中会生成Linux系统下的.so文件（好吧，其实我基本没用过Linux）。&nbsp;<br/>没写过JNI的可以看看我之前的博客（Windows下利用Visual Studio开发的过程）：<a style="color: rgb(16, 138, 198); text-decoration: none;" href="http://cherishlc.iteye.com/admin/blogs/1328136" target="_blank">http://cherishlc.iteye.com/admin/blogs/1328136</a>&nbsp;<br/><br/>以及自动生成工具swig的使用方法（数组的支持不好！其他挺方便）：<a style="color: rgb(16, 138, 198); text-decoration: none;" href="http://cherishlc.iteye.com/admin/blogs/1689224" target="_blank">http://cherishlc.iteye.com/admin/blogs/1689224</a>&nbsp;<br/><br/>另外推荐一篇非常不错的NDK博文，（配置忽略，主要是各种数据的传递，下代码看看吧）<a style="color: rgb(16, 138, 198); text-decoration: none;" href="http://vaero.blog.51cto.com/4350852/782787" target="_blank">http://vaero.blog.51cto.com/4350852/782787</a>&nbsp;<br/>扯远了，下面来看看真正在Android中的开发过程。&nbsp;<br/><br/><span style="font-size: 24px;"><span style="color: blue;">1、下载ADT及NDK</span></span>&nbsp;<br/><ul class=" list-paddingleft-2" style="margin: 0px 0px 1.5em; padding: 0px;"><li><p>下载ADT (Android Developer Tools) Bundle：<a style="color: rgb(16, 138, 198); text-decoration: none;" href="http://developer.android.com/sdk/index.html" target="_blank">http://developer.android.com/sdk/index.html</a></p></li><li><p>下载NDK<a style="color: rgb(16, 138, 198); text-decoration: none;" href="http://developer.android.com/tools/sdk/ndk/index.html" target="_blank">http://developer.android.com/tools/sdk/ndk/index.html</a></p></li></ul><br/>其中ADT中包含了Eclipse及google的开发套件，不用写C++的下载ADT就足够了。&nbsp;<br/>NDK则是包含了GCC的编译器，以及各个平台（arm，X86，MIPS）的相关头文件，交叉编译的一些平台相关文件等。&nbsp;<br/><br/><span style="font-size: 24px;"><span style="color: blue;">2、在ADT中配置NDK路径</span></span>&nbsp;<br/>解压NDK压缩包到任意路径，按下图在ADT中（也即ADT解压后的Eclipse文件下的Eclipse中）设置NDK的路径。&nbsp;<br/>设置方法如下图所示：&nbsp;<br/><img style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649776937.png"/>&nbsp;<br/><br/><span style="font-size: 24px;"><span style="color: blue;">3、创建含有本地代码的Android Project</span>&nbsp;<br/></span><br/>该过程分为以下两步：&nbsp;<br/><ul class=" list-paddingleft-2" style="margin: 0px 0px 1.5em; padding: 0px;"><li><p>创建普通的Android Application工程（注意最小支持的API版本要不小于14）</p></li><li><p>加入本地代码支持</p></li></ul><br/>具体过程如下图所示：&nbsp;<br/>创建工程：&nbsp;<br/><img style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649777221.png"/>&nbsp;<br/><br/>加入本地代码支持：&nbsp;<br/><img style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649777281.png"/>&nbsp;<br/><br/>完成情况：&nbsp;<br/><img width="700" height="192" title="点击查看原始大小图片" class="magplus" style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649777377.png"/><br/><br/>点击菜单栏Project-&gt;Build All命令进行编译。&nbsp;<br/><br/><br/><span style="font-size: 18px;"><span style="color: red;">注意：</span></span>如果之前最小支持的API版本要不小于14，将出现编译错误。“Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 7 in ./AndroidManifest.xml”&nbsp;<br/><br/><span style="font-size: 18px;">解决方法如下：</span>&nbsp;<br/>打开AndroidManifest.xml，切换到源文件视图，将minSdkVersion 改为14以上：&nbsp;<br/><img width="700" height="409" title="点击查看原始大小图片" class="magplus" style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649777421.png"/><br/><br/><span style="font-size: 24px;"><span style="color: blue;">4、编写Java端代码和C++端代码</span></span>&nbsp;<br/>Java端，注意不要继承自Android中的类，否则javah编译头文件时要指定android类路径。&nbsp;<br/><div class="dp-highlighter" style="padding: 1px; width: 679px; text-align: left; overflow: auto; font-family: Monaco, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 9px; -ms-word-break: break-all; -ms-word-wrap: break-word; background-color: transparent;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="font: bold 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; margin: 0px; padding: 3px; color: silver; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-left-style: solid; font-size-adjust: none; font-stretch: normal; background-color: rgb(248, 248, 248);">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="background-position: 0% 0%; margin: 0px 10px 0px 0px; padding: 1px; border: currentColor; border-image: none; width: 16px; height: 16px; color: rgb(16, 138, 198); text-indent: -2000px; font-size: 9px; text-decoration: none; display: inline-block; background-image: none; background-repeat: no-repeat; background-color: inherit;" href="http://blog.csdn.net/mirkerson/article/details/8901270"><img class="star" style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="收藏代码" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649778249.png"/></a></div></div><ol class="dp-j list-paddingleft-2" style="list-style-type: decimal;" start="1"><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">package</span>&nbsp;com.lc.testndk2;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;android.util.Log;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">public</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">class</span>&nbsp;NativeClass&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">//数组a中的每个元素都加上b，返回值为在C++中数据是否为a中数据拷贝得到的（按值拷贝还是传递指针）</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">public</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">static</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">native</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">boolean</span>&nbsp;jniArrayAdd(<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">int</span>[]&nbsp;a,&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">int</span>&nbsp;b);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;<span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">//&nbsp;在C++中创建Java中的int数组，其中元素为&nbsp;数组a中的对应元素乘以b</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">public</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">static</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">native</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">int</span>[]&nbsp;jnitArrayMul(<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">int</span>[]&nbsp;a,<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">int</span>&nbsp;b);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">static</span>&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i(<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;NativeClass&quot;</span>,<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;before&nbsp;load&nbsp;library&quot;</span>);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.loadLibrary(<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;TestNDK2&quot;</span>);<span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">//注意这里为自己指定的.so文件，无lib前缀，亦无后缀</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i(<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;NativeClass&quot;</span>,<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;after&nbsp;load&nbsp;library&quot;</span>);&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">}&nbsp;&nbsp;</span></p></li></ol></div><br/><br/>javah推荐两种方法：&nbsp;<br/><ul class=" list-paddingleft-2" style="margin: 0px 0px 1.5em; padding: 0px;"><li><p>使用我写的工具，含本地方法的类多时，一次编译完成：<a style="color: rgb(16, 138, 198); text-decoration: none;" href="http://cherishlc.iteye.com/blog/1326893" target="_blank">http://cherishlc.iteye.com/blog/1326893</a></p></li><li><p>在Eclipse中配置外部工具，配置方法参考自（同时也是讲Android中JNI配置方法的博客）：<a style="color: rgb(16, 138, 198); text-decoration: none;" href="http://www.cnblogs.com/yemeishu/archive/2012/12/24/NDK%E5%BC%80%E5%8F%91.html" target="_blank">http://www.cnblogs.com/yemeishu/archive/2012/12/24/NDK%E5%BC%80%E5%8F%91.html</a></p></li></ul><br/>在Eclipse中配置javah外部工具方法为：&nbsp;<br/><img style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649777581.png"/>&nbsp;<br/><img width="700" height="461" title="点击查看原始大小图片" class="magplus" style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649777625.png"/><br/>上图中最长的一行命令如下：&nbsp;<br/><div class="dp-highlighter" style="padding: 1px; width: 679px; text-align: left; overflow: auto; font-family: Monaco, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 9px; -ms-word-break: break-all; -ms-word-wrap: break-word; background-color: transparent;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="font: bold 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; margin: 0px; padding: 3px; color: silver; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-left-style: solid; font-size-adjust: none; font-stretch: normal; background-color: rgb(248, 248, 248);">Cmdineclipse代码&nbsp;&nbsp;<a title="收藏这段代码" style="background-position: 0% 0%; margin: 0px 10px 0px 0px; padding: 1px; border: currentColor; border-image: none; width: 16px; height: 16px; color: rgb(16, 138, 198); text-indent: -2000px; font-size: 9px; text-decoration: none; display: inline-block; background-image: none; background-repeat: no-repeat; background-color: inherit;" href="http://blog.csdn.net/mirkerson/article/details/8901270"><img class="star" style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="收藏代码" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649778249.png"/></a></div></div><ol class="dp-default list-paddingleft-2" style="list-style-type: decimal;" start="1"><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">-v&nbsp;-classpath&nbsp;<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;${project_loc}/bin/classes&quot;</span>&nbsp;-d&nbsp;<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;${project_loc}/jni&quot;</span>&nbsp;${java_type_name}&nbsp;&nbsp;</span></p></li></ol></div><br/>配置好之后：&nbsp;<br/><img style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649777737.png"/>&nbsp;<br/>点刚才配置好的javah工具，生成.h文件，然后：&nbsp;<br/><img style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649777781.png"/>&nbsp;<br/><br/><br/><span style="font-size: 18px;"><span style="color: blue;">Java端调用JNI方法的代码：</span></span>&nbsp;<br/>将MainActivity改为：&nbsp;<br/><div class="dp-highlighter" style="padding: 1px; width: 679px; text-align: left; overflow: auto; font-family: Monaco, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 9px; -ms-word-break: break-all; -ms-word-wrap: break-word; background-color: transparent;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="font: bold 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; margin: 0px; padding: 3px; color: silver; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-left-style: solid; font-size-adjust: none; font-stretch: normal; background-color: rgb(248, 248, 248);">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="background-position: 0% 0%; margin: 0px 10px 0px 0px; padding: 1px; border: currentColor; border-image: none; width: 16px; height: 16px; color: rgb(16, 138, 198); text-indent: -2000px; font-size: 9px; text-decoration: none; display: inline-block; background-image: none; background-repeat: no-repeat; background-color: inherit;" href="http://blog.csdn.net/mirkerson/article/details/8901270"><img class="star" style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="收藏代码" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649778249.png"/></a></div></div><ol class="dp-j list-paddingleft-2" style="list-style-type: decimal;" start="1"><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">package</span>&nbsp;com.lc.testndk2;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;java.util.Arrays;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;android.app.Activity;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;android.os.Bundle;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;android.widget.TextView;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">public</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">class</span>&nbsp;MainActivity&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">extends</span>&nbsp;Activity&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(100, 100, 100); background-color: inherit;">@Override</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">protected</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">void</span>&nbsp;onCreate(Bundle&nbsp;savedInstanceState)&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">super</span>.onCreate(savedInstanceState);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TextView&nbsp;&nbsp;tv&nbsp;=&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">new</span>&nbsp;TextView(<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">this</span>);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">int</span>[]&nbsp;array&nbsp;=&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">new</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">int</span>[]&nbsp;{&nbsp;<span class="number" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(192, 0, 0); background-color: inherit;">1</span>,&nbsp;<span class="number" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(192, 0, 0); background-color: inherit;">2</span>,&nbsp;&nbsp;<span class="number" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(192, 0, 0); background-color: inherit;">3</span>};&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;str&nbsp;=&nbsp;<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;数组，调用C++前&quot;</span>&nbsp;+&nbsp;Arrays.toString(array);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">boolean</span>&nbsp;isCopyOfArrayInCpp&nbsp;=&nbsp;NativeClass.jniArrayAdd(array,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="number" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(192, 0, 0); background-color: inherit;">1</span>);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str&nbsp;+=&nbsp;<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;\n在C++中为副本？&nbsp;&nbsp;&quot;</span>&nbsp;+&nbsp;isCopyOfArrayInCpp;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str&nbsp;+=&nbsp;<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;\n数组，调用C++后：&quot;</span>&nbsp;+&nbsp;Arrays.toString(array);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tv.setText(str);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setContentView(tv);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">}&nbsp;&nbsp;</span></p></li></ol></div><br/><br/><br/><span style="font-size: 18px;"><span style="color: blue;">编写C++代码：</span></span>&nbsp;<br/>打开刚才系统生成的TestNDK2.cpp，修改成如下样子：&nbsp;<br/><div class="dp-highlighter" style="padding: 1px; width: 679px; text-align: left; overflow: auto; font-family: Monaco, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 9px; -ms-word-break: break-all; -ms-word-wrap: break-word; background-color: transparent;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="font: bold 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; margin: 0px; padding: 3px; color: silver; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-left-style: solid; font-size-adjust: none; font-stretch: normal; background-color: rgb(248, 248, 248);">C++代码&nbsp;&nbsp;<a title="收藏这段代码" style="background-position: 0% 0%; margin: 0px 10px 0px 0px; padding: 1px; border: currentColor; border-image: none; width: 16px; height: 16px; color: rgb(16, 138, 198); text-indent: -2000px; font-size: 9px; text-decoration: none; display: inline-block; background-image: none; background-repeat: no-repeat; background-color: inherit;" href="http://blog.csdn.net/mirkerson/article/details/8901270"><img class="star" style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="收藏代码" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649778249.png"/></a></div></div><ol class="dp-cpp list-paddingleft-2" style="list-style-type: decimal;" start="1"><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: gray; background-color: inherit;">#include&nbsp;&lt;jni.h&gt;</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: gray; background-color: inherit;">#include&nbsp;&quot;com_lc_testndk2_NativeClass.h&quot;</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: gray; background-color: inherit;">#ifdef&nbsp;__cplusplus&nbsp;&nbsp;//最好有这个，否则被编译器改了函数名字找不到不要怪我</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">extern</span>&nbsp;<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;C&quot;</span>&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: gray; background-color: inherit;">#endif</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">/*</span>&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">&nbsp;*&nbsp;Class:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;com_lc_testndk2_NativeClass</span>&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">&nbsp;*&nbsp;Method:&nbsp;&nbsp;&nbsp;&nbsp;jinArrayAdd</span>&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">&nbsp;*&nbsp;Signature:&nbsp;([II)[I</span>&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">&nbsp;*/</span>JNIEXPORT&nbsp;jboolean&nbsp;JNICALL&nbsp;Java_com_lc_testndk2_NativeClass_jniArrayAdd(&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JNIEnv&nbsp;*&nbsp;env,&nbsp;jclass,&nbsp;jintArray&nbsp;array,&nbsp;jint&nbsp;b)&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;jsize&nbsp;size&nbsp;=&nbsp;env-&gt;GetArrayLength(array);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">//&nbsp;&nbsp;jintArray&nbsp;sum=env-&gt;NewIntArray(2);</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;jboolean&nbsp;isCopy;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;jint*&nbsp;pArray&nbsp;=&nbsp;(jint*)&nbsp;env-&gt;GetPrimitiveArrayCritical(array,&nbsp;&amp;isCopy);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">for</span>&nbsp;(<span class="datatypes" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(46, 139, 87); font-weight: bold; background-color: inherit;">int</span>&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;size;&nbsp;i++)&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pArray[i]&nbsp;+=&nbsp;b;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;env-&gt;ReleasePrimitiveArrayCritical(array,&nbsp;pArray,&nbsp;JNI_COMMIT);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">//env-&gt;ReleasePrimitiveArrayCritical(sum,pSum,JNI_COMMIT);</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">return</span>&nbsp;isCopy;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">}&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">/*</span>&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">&nbsp;*&nbsp;Class:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;com_lc_testndk2_NativeClass</span>&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">&nbsp;*&nbsp;Method:&nbsp;&nbsp;&nbsp;&nbsp;jnitArrayMul</span>&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">&nbsp;*&nbsp;Signature:&nbsp;([II)[I</span>&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">&nbsp;*/</span>JNIEXPORT&nbsp;jintArray&nbsp;JNICALL&nbsp;Java_com_lc_testndk2_NativeClass_jnitArrayMul(&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JNIEnv&nbsp;*&nbsp;env,&nbsp;jclass,&nbsp;jintArray&nbsp;array,&nbsp;jint&nbsp;b)&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;jsize&nbsp;size&nbsp;=&nbsp;env-&gt;GetArrayLength(array);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;jintArray&nbsp;product&nbsp;=&nbsp;env-&gt;NewIntArray(size);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;jint*&nbsp;pArray&nbsp;=&nbsp;(jint*)&nbsp;env-&gt;GetPrimitiveArrayCritical(array,&nbsp;0);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;jint*&nbsp;pProduct=(jint*)env-&gt;GetPrimitiveArrayCritical(product,0);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">//&nbsp;&nbsp;jintArray&nbsp;product&nbsp;=&nbsp;env-&gt;NewIntArray(size);&nbsp;//不能在这里创建！！因为上面的方法会使java进入critical&nbsp;region，&nbsp;在这里创建的话虚拟机直接崩溃</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">for</span>&nbsp;(<span class="datatypes" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(46, 139, 87); font-weight: bold; background-color: inherit;">int</span>&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;size;&nbsp;i++)&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pProduct[i]&nbsp;=pArray[i]*&nbsp;b;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;env-&gt;ReleasePrimitiveArrayCritical(array,&nbsp;pArray,&nbsp;JNI_COMMIT);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;env-&gt;ReleasePrimitiveArrayCritical(product,pProduct,JNI_COMMIT);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">return</span>&nbsp;product;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">}&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: gray; background-color: inherit;">#ifdef&nbsp;__cplusplus</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">}&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: gray; background-color: inherit;">#endif</span>&nbsp;&nbsp;</span></p></li></ol></div><br/><br/><span style="font-size: 24px;"><span style="color: blue;">5、配置生成的.so文件的目标平台</span></span>&nbsp;<br/>Java是跨平台的可是C++生成动态链接文件不是！！！同是Android，底层的CPU架构不同，动态链接文件也不同。。。好吧，这个我不知道原因。。。&nbsp;<br/>于是乎，还得为不同的CPU创建不同的动态链接库文件，好在一行命令搞定~所有的动态链接一起打包，管他是哪个CPU，统统适用，Happy啊。&nbsp;<br/>参考自：<a style="color: rgb(16, 138, 198); text-decoration: none;" href="http://bbs.csdn.net/topics/390158301" target="_blank">http://bbs.csdn.net/topics/390158301</a>&nbsp;<br/>过程如下：&nbsp;<br/><img style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649777909.png"/>&nbsp;<br/>再编译时会发现生成了对应以上四个平台的.so文件~~~&nbsp;<br/><img style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649777969.png"/>&nbsp;<br/><br/>一切搞定，可以运行了！！！运行结果如下：&nbsp;<br/><img style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649778017.png"/>&nbsp;<br/><br/><br/><span style="font-size: 24px;"><span style="color: blue;">6、Java与C++联合调试</span></span>&nbsp;<br/>参见：<a style="color: rgb(16, 138, 198); text-decoration: none;" href="http://blog.csdn.net/wjr2012/article/details/7993722" target="_blank">http://blog.csdn.net/wjr2012/article/details/7993722</a>&nbsp;<br/><br/><span style="font-size: 18px;"><span style="color: red;">注意：</span></span>&nbsp;<br/><ul class=" list-paddingleft-2" style="margin: 0px 0px 1.5em; padding: 0px;"><li><p>C++的调试器有几秒的延迟才能启动好，也就是程序运行了一会儿才可以开始调试，所以要调试的代码一定要是几秒钟后才能调试！！！</p></li><li><p>断点设置在C++中才有效。。。</p></li></ul><br/><br/>过程为：&nbsp;<br/>右键点击工程文件， 在properties -&gt; C/C++ Build中：&nbsp;<br/><img width="700" height="430" title="点击查看原始大小图片" class="magplus" style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649778065.png"/><br/>完了设置断点（只能在C++中）就可以启动调试了~~&nbsp;<br/><img width="700" height="528" title="点击查看原始大小图片" class="magplus" style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649778205.png"/><br/><br/><br/>好吧，，，调试怎么不灵光呢。。。再想想刚才的注意事项。。。好吧，早执行完了JNI代码了。。。&nbsp;<br/>于是乎，修改MainActivity代码如下：&nbsp;<br/><div class="dp-highlighter" style="padding: 1px; width: 679px; text-align: left; overflow: auto; font-family: Monaco, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 9px; -ms-word-break: break-all; -ms-word-wrap: break-word; background-color: transparent;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="font: bold 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; margin: 0px; padding: 3px; color: silver; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-left-style: solid; font-size-adjust: none; font-stretch: normal; background-color: rgb(248, 248, 248);">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="background-position: 0% 0%; margin: 0px 10px 0px 0px; padding: 1px; border: currentColor; border-image: none; width: 16px; height: 16px; color: rgb(16, 138, 198); text-indent: -2000px; font-size: 9px; text-decoration: none; display: inline-block; background-image: none; background-repeat: no-repeat; background-color: inherit;" href="http://blog.csdn.net/mirkerson/article/details/8901270"><img class="star" style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="收藏代码" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649778249.png"/></a></div></div><ol class="dp-j list-paddingleft-2" style="list-style-type: decimal;" start="1"><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">package</span>&nbsp;com.lc.testndk2;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;java.util.Arrays;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;java.util.Timer;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;java.util.TimerTask;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;android.annotation.SuppressLint;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;android.app.Activity;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;android.os.Bundle;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;android.os.Handler;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;android.os.Message;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;android.util.Log;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">import</span>&nbsp;android.widget.TextView;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">/**</span>&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">&nbsp;*&nbsp;@author&nbsp;LC</span>&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">&nbsp;*</span>&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">&nbsp;*完整的演示Android通过JNI调用C++代码的工程</span>&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; width: auto; color: rgb(0, 130, 0); background-color: inherit;">&nbsp;*/</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">public</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">class</span>&nbsp;MainActivity&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">extends</span>&nbsp;Activity&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;TextView&nbsp;tv&nbsp;=&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">null</span>;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">int</span>&nbsp;count&nbsp;=&nbsp;<span class="number" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(192, 0, 0); background-color: inherit;">0</span>;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;Timer&nbsp;timer;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(100, 100, 100); background-color: inherit;">@SuppressLint</span>(<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;HandlerLeak&quot;</span>)&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">class</span>&nbsp;MyHandler&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">extends</span>&nbsp;Handler{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(100, 100, 100); background-color: inherit;">@Override</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">public</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">void</span>&nbsp;handleMessage(Message&nbsp;msg)&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">if</span>&nbsp;(tv&nbsp;!=&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">null</span>)&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tv.setText(msg.getData().getString(<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;text&quot;</span>));&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">super</span>.handleMessage(msg);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;};&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;Handler&nbsp;handle=&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">new</span>&nbsp;MyHandler();&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">class</span>&nbsp;refreshTask&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">extends</span>&nbsp;TimerTask&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(100, 100, 100); background-color: inherit;">@Override</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">public</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">void</span>&nbsp;run()&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">try</span>&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count++;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i(<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;MainActivity&quot;</span>,&nbsp;<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;before&nbsp;call&nbsp;native&nbsp;code,count=&quot;</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;count);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">int</span>[]&nbsp;array&nbsp;=&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">new</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">int</span>[]&nbsp;{&nbsp;count,&nbsp;-count,&nbsp;<span class="number" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(192, 0, 0); background-color: inherit;">2</span>*count&nbsp;};&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;str&nbsp;=&nbsp;<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;第&quot;</span>&nbsp;+&nbsp;count&nbsp;+&nbsp;<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;次了\n&quot;</span>;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str&nbsp;+=&nbsp;<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;数组，调用C++前&quot;</span>&nbsp;+&nbsp;Arrays.toString(array);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">boolean</span>&nbsp;isCopyOfArrayInCpp&nbsp;=&nbsp;NativeClass.jniArrayAdd(array,<span class="number" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(192, 0, 0); background-color: inherit;">1</span>);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str&nbsp;+=&nbsp;<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;\n在C++中为副本？&nbsp;&nbsp;&quot;</span>&nbsp;+&nbsp;isCopyOfArrayInCpp;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str&nbsp;+=&nbsp;<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;\n数组，调用C++后：&quot;</span>&nbsp;+&nbsp;Arrays.toString(array)+<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;\n\n&quot;</span>;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str+=<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;测试在C++中创建数组：\n&quot;</span>;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str&nbsp;+=&nbsp;&nbsp;Arrays.toString(array)+<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;*&nbsp;2&nbsp;=&quot;</span>;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str+=Arrays.toString(NativeClass.jnitArrayMul(array,&nbsp;<span class="number" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(192, 0, 0); background-color: inherit;">2</span>))+<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;\n\n&quot;</span>;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Message&nbsp;msg=<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">new</span>&nbsp;Message();&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bundle&nbsp;b=<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">new</span>&nbsp;Bundle();&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b.putString(<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;text&quot;</span>,&nbsp;str);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg.setData(b);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;handle.sendMessage(msg);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i(<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;MainActivity&quot;</span>,&nbsp;<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;after&nbsp;call&nbsp;native&nbsp;code&quot;</span>);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">catch</span>&nbsp;(Exception&nbsp;e)&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i(MainActivity.<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">class</span>.getSimpleName(),&nbsp;e.toString());&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;};&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(100, 100, 100); background-color: inherit;">@Override</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">protected</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">void</span>&nbsp;onCreate(Bundle&nbsp;savedInstanceState)&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">super</span>.onCreate(savedInstanceState);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tv&nbsp;=&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">new</span>&nbsp;TextView(<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">this</span>);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tv.setText(<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;我是初始值&quot;</span>);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setContentView(tv);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(100, 100, 100); background-color: inherit;">@Override</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">protected</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">void</span>&nbsp;onPause()&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i(MainActivity.<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">class</span>.getSimpleName(),<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;onPuase()&quot;</span>);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timer.cancel();&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timer=<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">null</span>;&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">super</span>.onPause();&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(100, 100, 100); background-color: inherit;">@Override</span>&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">protected</span>&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">void</span>&nbsp;onResume()&nbsp;{&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i(MainActivity.<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">class</span>.getSimpleName(),<span class="string" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: blue; background-color: inherit;">&quot;onResume()&quot;</span>);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timer=<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">new</span>&nbsp;Timer();&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timer.scheduleAtFixedRate(<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">new</span>&nbsp;refreshTask(),&nbsp;<span class="number" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(192, 0, 0); background-color: inherit;">0</span>,&nbsp;<span class="number" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(192, 0, 0); background-color: inherit;">1000</span>);&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: rgb(127, 0, 85); font-weight: bold; background-color: inherit;">super</span>.onResume();&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></p></li><li><p><span style="margin: 0px; padding: 0px; border: currentColor; border-image: none; color: black; background-color: inherit;">}&nbsp;&nbsp;</span></p></li></ol></div><br/><br/>运行到断点的结果：&nbsp;<br/><img style="border: 0px currentColor; border-image: none; max-width: 100%;" alt="" src="http://blog.careff.com/zb_users/upload/2016/1/2016010649778281.png"/></div><div class="attachments" style="font: 14px/18px Helvetica, Tahoma, Arial, sans-serif; text-align: left; color: rgb(51, 51, 51); text-transform: none; text-indent: 0px; letter-spacing: normal; margin-top: 10px; word-spacing: 0px; border-top-color: rgb(153, 153, 153); border-top-width: 1px; border-top-style: solid; white-space: normal; widows: 1; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;"><ul class=" list-paddingleft-2" style="list-style-type: none;"><li><p><a style="color: rgb(16, 138, 198); text-decoration: none;" href="http://dl.iteye.com/topics/download/27818138-bc2c-35d9-870f-3f34739226ce">TestNDK2.rar</a>&nbsp;(710.1 KB)</p></li><li><p>下载次数: 10</p></li></ul></div><p>&nbsp;</p>]]></description><category>Android</category><comments>http://blog.careff.com/post/454.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=454</wfw:commentRss></item><item><title>5种常用的APK保护技术——保护应用、游戏APP不被破解</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/397.html</link><pubDate>Fri, 13 Jun 2014 10:36:10 +0800</pubDate><guid>http://blog.careff.com/post/397.html</guid><description><![CDATA[<p><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; white-space: normal; orphans: 2; float: none; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">由于Java字节码的抽象级别较高，因此Android的APK较容易被反编译，而国内对于网络产品保护不力。如果一款应用APK被破解，那么可能会被他人植入广告或者病毒以供他人盈利或窃取用户信息；如果一款游戏APK被破解，那么这款游戏可能会从收费版变成免费版，游戏的支付系统也形同虚设。不管是哪种情况，对于开发者来说，APK被破解绝对是一场噩梦，而自己手动设置各种加密不但耗时耗力，而且不一定能收到很好的效果。本文介绍几种常用的方法，用于保护Java字节码不被反编译。通常，这些方法不能够绝对防止程序被反编译，而是加大反编译的难度而已，因为这些方法都有自己的使用环境和弱点。</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; white-space: normal; orphans: 2; float: none; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">1．隔离Java程序</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; white-space: normal; orphans: 2; float: none; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">&nbsp; &nbsp; 最简单的方法就是让用户不能够访问到Java Class程序，这种方法是最根本的方法，具体实现有多种方式。例如，开发人员可以将关键的Java Class放在服务器端，客户端通过访问服务器的相关接口来获得服务，而不是直接访问Class文件。这样黑客就没有办法反编译Class文件。目前，通过接口提供服务的标准和协议也越来越多，例如 HTTP、Web Service、RPC等。但是有很多应用都不适合这种保护方式，例如对于单机运行的程序就无法隔离Java程序。</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; white-space: normal; orphans: 2; float: none; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">2．对Class文件进行加密 　　</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; white-space: normal; orphans: 2; float: none; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">&nbsp; &nbsp; 为了防止Class文件被直接反编译，许多开发人员将一些关键的Class文件进行加密，例如对注册码、序列号管理相关的类等。在使用这些被加密的类之前，程序首先需要对这些类进行解密，而后再将这些类装载到JVM当中。这些类的解密可以由硬件完成，也可以使用软件完成。 　　</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; white-space: normal; orphans: 2; float: none; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">&nbsp; &nbsp; 在实现时，开发人员往往通过自定义ClassLoader类来完成加密类的装载(注意由于安全性的原因，Applet不能够支持自定义的ClassLoader)。自定义的ClassLoader首先找到加密的类，而后进行解密，最后将解密后的类装载到JVM当中。在这种保护方式中，自定义的ClassLoader是非常关键的类。由于它本身不是被加密的，因此它可能成为黑客最先攻击的目标。如果相关的解密密钥和算法被攻克，那么被加密的类也很容易被解密。</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; white-space: normal; orphans: 2; float: none; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">3．转换成本地代码 　　</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; white-space: normal; orphans: 2; float: none; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">&nbsp; &nbsp; 将程序转换成本地代码也是一种防止反编译的有效方法。因为本地代码往往难以被反编译。开发人员可以选择将整个应用程序转换成本地代码，也可以选择关键模块转换。如果仅仅转换关键部分模块，Java程序在使用这些模块时，需要使用JNI技术进行调用。当然，在使用这种技术保护Java程序的同时，也牺牲了Java的跨平台特性。对于不同的平台，我们需要维护不同版本的本地代码，这将加重软件支持和维护的工作。不过对于一些关键的模块，有时这种方案往往是必要的。为了保证这些本地代码不被修改和替代，通常需要对这些代码进行数字签名。在使用这些本地代码之前，往往需要对这些本地代码进行认证，确保这些代码没有被黑客更改。如果签名检查通过，则调用相关JNI方法。</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; white-space: normal; orphans: 2; float: none; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">4．代码混淆</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; white-space: normal; orphans: 2; float: none; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">&nbsp; &nbsp; 代码混淆是对Class文件进行重新组织和处理，使得处理后的代码与处理前代码完成相同的功能(语义)。但是混淆后的代码很难被反编译，即反编译后得出的代码是非常难懂、晦涩的，因此反编译人员很难得出程序的真正语义。从理论上来说，黑客如果有足够的时间，被混淆的代码仍然可能被破解，甚至目前有些人正在研制反混淆的工具。但是从实际情况来看，由于混淆技术的多元化发展，混淆理论的成熟，经过混淆的Java代码还是能够很好地防止反编译。下面我们会详细介绍混淆技术，因为混淆是一种保护Java程序的重要技术。</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; white-space: normal; orphans: 2; float: none; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">5.在线加密</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; word-wrap: break-word; white-space: normal; orphans: 2; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; white-space: normal; orphans: 2; float: none; color: rgb(68,68,68); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">&nbsp; &nbsp; APK Protect（http://www.apkprotect.com/)是一个在线对APK程序进行加密的网站，可以支持Java和C+ +语言的保护，能达到反调试、反编译的效果，操作过程简单易用：仅需上传你的APK，选择加密项目，等待服务器加密（通常一两个小时左右）后即可下载加壳的APK，然后再签名上传到应用市场即可。经测试，通过APK Protect加密的APK变得非常难以破解，从而保护了APK。</span></p>]]></description><category>Android</category><comments>http://blog.careff.com/post/397.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=397</wfw:commentRss></item><item><title>Android项目中需要引用的权限</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/386.html</link><pubDate>Tue, 18 Feb 2014 15:04:00 +0800</pubDate><guid>http://blog.careff.com/post/386.html</guid><description><![CDATA[<p>&nbsp;&lt;uses-permission android:name=&quot;android.permission.SEND_SMS&quot; /&gt;</p><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.RESTART_PACKAGES&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.KILL_BACKGROUND_PROCESSES&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;com.android.launcher.permission.INSTALL_SHORTCUT&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;com.android.launcher.permission.UNINSTALL_SHORTCUT&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.READ_CONTACTS&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.WRITE_CONTACTS&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.CAMERA&quot; /&gt;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &lt;uses-feature android:name=&quot;android.hardware.camera&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-feature</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:name=&quot;android.hardware.camera.autofocus&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:required=&quot;false&quot; /&gt;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.GET_ACCOUNTS&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.USE_CREDENTIALS&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.MANAGE_ACCOUNTS&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.AUTHENTICATE_ACCOUNTS&quot; /&gt;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &lt;permission android:name=&quot;android.permission.BAIDU_LOCATION_SERVICE&quot; &gt;</div><div>&nbsp; &nbsp; &lt;/permission&gt;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.BAIDU_LOCATION_SERVICE&quot; &gt;</div><div>&nbsp; &nbsp; &lt;/uses-permission&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; &gt;</div><div>&nbsp; &nbsp; &lt;/uses-permission&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot; &gt;</div><div>&nbsp; &nbsp; &lt;/uses-permission&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; &gt;</div><div>&nbsp; &nbsp; &lt;/uses-permission&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.ACCESS_MOCK_LOCATION&quot; &gt;</div><div>&nbsp; &nbsp; &lt;/uses-permission&gt;</div><div>&nbsp; &nbsp; &lt;!-- &lt;uses-permission android:name=&quot;android.permission.WRITE_APN_SETTINGS&quot;&gt;&lt;/uses-permission&gt; --&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; &gt;</div><div>&nbsp; &nbsp; &lt;/uses-permission&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;com.android.launcher.permission.READ_SETTINGS&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.WAKE_LOCK&quot; &gt;</div><div>&nbsp; &nbsp; &lt;/uses-permission&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.CHANGE_WIFI_STATE&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.ACCESS_GPS&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.READ_CONTACTS&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.CALL_PHONE&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.READ_SMS&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.SEND_SMS&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;!-- SDK1.5需要android.permission.GET_TASKS权限判断本程序是否为当前运行的应用? --&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.GET_TASKS&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.CAMERA&quot; &gt;</div><div>&nbsp; &nbsp; &lt;/uses-permission&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.RECORD_AUDIO&quot; &gt;</div><div>&nbsp; &nbsp; &lt;/uses-permission&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; &gt;</div><div>&nbsp; &nbsp; &lt;/uses-permission&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.RECEIVE_BOOT_COMPLETED&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.BROADCAST_STICKY&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.WRITE_SETTINGS&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;!-- 来电消音 --&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.PROCESS_OUTGOING_CALLS&quot; &gt;</div><div>&nbsp; &nbsp; &lt;/uses-permission&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot; /&gt;</div><div>&nbsp; &nbsp; &lt;uses-permission android:name=&quot;android.permission.MODIFY_AUDIO_SETTINGS&quot; /&gt;</div>]]></description><category>Android</category><comments>http://blog.careff.com/post/386.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=386</wfw:commentRss></item><item><title>百度地图Android调用的时候需要在配置清单里面加服务才可以定位</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/385.html</link><pubDate>Tue, 18 Feb 2014 15:03:25 +0800</pubDate><guid>http://blog.careff.com/post/385.html</guid><description><![CDATA[<p>&nbsp; &lt;service</p><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:name=&quot;com.baidu.location.f&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:enabled=&quot;true&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:process=&quot;:remote&quot; &gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/service&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div>]]></description><category>Android</category><comments>http://blog.careff.com/post/385.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=385</wfw:commentRss></item><item><title>Android第一个产品完成</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/374.html</link><pubDate>Wed, 03 Jul 2013 09:22:30 +0800</pubDate><guid>http://blog.careff.com/post/374.html</guid><description><![CDATA[<p>&nbsp;Android第一个产品完成</p>]]></description><category>Android</category><comments>http://blog.careff.com/post/374.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=374</wfw:commentRss></item><item><title>ndroid3.0版本以上出现android.os.NetworkOnMainThreadException异常与处理方式 </title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/371.html</link><pubDate>Sat, 27 Apr 2013 17:30:29 +0800</pubDate><guid>http://blog.careff.com/post/371.html</guid><description><![CDATA[<p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: rgb(74, 0, 0); font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 14px; background-color: rgb(239, 245, 221);">以前用2.2 访问WebService没有问题，到3.0上访问出现android.os.NetworkOnMainThreadException</p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: rgb(74, 0, 0); font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 14px; background-color: rgb(239, 245, 221);">找了资料经过实践，解决方法如下：&nbsp;</p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: rgb(74, 0, 0); font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 14px; background-color: rgb(239, 245, 221);">StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .detectDiskReads().detectDiskWrites().detectNetwork() // 这里或者用&nbsp;.detectAll()&nbsp;方法<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .penaltyLog().build());&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .detectLeakedSqlLiteObjects().detectLeakedClosableObjects()&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .penaltyLog().penaltyDeath().build());<br />注：1.在2.3版本以后加入了StrictMode类，而在3.0在网络上能感觉到有更加严格的限制，更多的查询API上的StrictMode ;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.使用的时候只需要在你项目运行的入口Activity的OnCreate中放入这段代码，那么整个项目程序都有用。不需要每个Activity里面加入。</p><p style="line-height: 25px; margin: 0px 0px 10px; padding: 0px; color: rgb(74, 0, 0); font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 14px; background-color: rgb(239, 245, 221);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.StrictMode类一般是用来调试的，在程序运行中会打印很多消息，那是告诉你你的项目程序需要改进的地方。在Android项目中，最好的是让界面与后台装载程序分开来。总之，如果你的程序代码非常符合Android规范要求，那么你完全可以不使用上面的代码...</p>]]></description><category>Android</category><comments>http://blog.careff.com/post/371.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=371</wfw:commentRss></item><item><title>android-x86-4.0-RC2-eeepc.iso</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/370.html</link><pubDate>Thu, 25 Apr 2013 15:08:48 +0800</pubDate><guid>http://blog.careff.com/post/370.html</guid><description><![CDATA[<p>&nbsp;android-x86-4.0-RC2-eeepc.iso</p>]]></description><category>Android</category><comments>http://blog.careff.com/post/370.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=370</wfw:commentRss></item><item><title>用Android-X86和VirtualBox打造高性能Android开发环境</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/369.html</link><pubDate>Thu, 25 Apr 2013 12:55:40 +0800</pubDate><guid>http://blog.careff.com/post/369.html</guid><description><![CDATA[<p>&nbsp;</p><h2 style="margin: 0px; padding: 0px; font-size: 18px; line-height: 30px; color: rgb(68, 68, 68); font-family: 'Microsoft YaHei', 微软雅黑, Lucida, Verdana, 'Hiragino Sans GB', STHeiti, 'WenQuanYi Micro Hei', SimSun, sans-serif;">用Android-X86和VirtualBox打造高性能Android开发环境</h2><p class="date" style="margin: 0px; padding: 0px 0px 15px; line-height: 20px; color: rgb(63, 63, 63); font-family: 'Microsoft YaHei', 微软雅黑, Lucida, Verdana, 'Hiragino Sans GB', STHeiti, 'WenQuanYi Micro Hei', SimSun, sans-serif;">作者：<a href="http://be-evil.org/author/1" title="a Geeker，网络控，技术控，数码控，喜欢研究各类计算机软件应用，程序开发技术,不折腾会死星人。&lt;br /&gt;联系我:colt.hawkins[at]gmail.com colt.hawkins@gmail.com" style="color: rgb(63, 63, 63); text-decoration: none; outline: none;">朦朧中的罪惡</a>&nbsp;发布于：2011-8-25 23:58 Thursday 分类：<a href="http://be-evil.org/sort/android--development" style="color: rgb(63, 63, 63); text-decoration: none; outline: none;">Android</a></p><div class="post-desc" style="margin: 0px; padding: 0px; min-height: 100px; color: rgb(68, 68, 68); font-family: 'Microsoft YaHei', 微软雅黑, Lucida, Verdana, 'Hiragino Sans GB', STHeiti, 'WenQuanYi Micro Hei', SimSun, sans-serif; font-size: 14px; line-height: 21px;"><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">不知道有多少Android开发着对Android虚拟机的那悲剧的性能有意见，反正我的看法是:那速度实在是太坑爹了！</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">为什么Android虚拟机比iOS和WP7的虚拟机要慢很多呢？原因如下：</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">1. Android 模拟器模拟的是 ARM 的体系结构(arm-eabi)，而 iOS 和 WP7 的模拟器的目标体系结构都是 x86 的，另外 iOS 的模拟器中运行的 App 也是编译为 x86 的。这样一来 Android 模拟器需要做一些额外的二进制翻译工作。<br />2. Android 模拟器用的是 QEMU 的全系统模式(full system)，也就说它模拟时需要启动整个 GUEST 系统，初始化各种模拟设备。相反的，iOS 和 WP7 的模拟器只是 user-mode 的模拟。<br />3. 在 Android 模拟器之中还需要跑一个 Dalvik VM，用以执行 Android 应用的 bytecodes。</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">综上所述,慢的一个主要原因就是虚拟机不是跑在x86上而是模拟的ARM,有没有办法弄个x86的Android呢？</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">答案是当然有&mdash;&mdash;&mdash;开源项目<a target="_blank" href="http://www.android-x86.org/" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;">Android-x86</a>,这个牛B的开源项目将Android移植到了x86平台，系统运行的时候不再需要模拟成ARM，这样就能直接将Android装在PC或虚拟机上流畅的运行了。<br />万事俱备，只欠东风了，下面我就来讲一下我使用Android-X86和VirtualBox打造手机开发模拟器的整个流程</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px; font-weight: bold;">1.下载Android-x86系统镜像文件</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">首先到<a target="_blank" href="http://www.android-x86.org/download" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;">http://www.android-x86.org/download</a>下载android-x86-2.2-generic.iso，镜像文件大约85MB</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px; font-weight: bold;">2.在VirtualBox上创建虚拟机</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">操作系统选择Linux，版本选择Linux 2.6</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/0472e0e8aaff6f5147d66cd22701576220110821112204.png" id="ematt:376" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-0472e0e8aaff6f5147d66cd22701576220110821112204.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">内存建议为512MB</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/d487fee7cfa004fe4e32b2a78afb4dea20110821112300.png" id="ematt:377" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-d487fee7cfa004fe4e32b2a78afb4dea20110821112300.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">硬盘默认8GB即可，因为是开发用，8GB绰绰有余了</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">虚拟机创建好之后，还需要修改一些配置</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">首先是调整网卡，连接方式建议选择bridged adapter这样虚拟机在局域网中有独立IP可以方便访问，然后控制芯片要选择为PCnet-PCI II,否则Android-x86无法识别网卡</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/e36ddfc62e79410164dccc1f20e90c2020110821112712.png" id="ematt:378" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-e36ddfc62e79410164dccc1f20e90c2020110821112712.png" title="点击查看原图" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">如果你想有声音的话需要在声音设置面板将控制芯片设置为soundblaser 16</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/8906e388b7777c97b9f65bd8174910b920110821112903.png" id="ematt:379" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/8906e388b7777c97b9f65bd8174910b920110821112903.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">把虚拟机的光驱设置为我们刚才下载的Android-x86 iso之后，启动虚拟机</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/71a4b03b5aff0c0c4dd015b518fe453b20110821113051.png" id="ematt:380" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/71a4b03b5aff0c0c4dd015b518fe453b20110821113051.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;">思想之地</a>原创文章，谢绝转载</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><span style="font-weight: bold;">3.安装Android-x86到虚拟机</span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">虚拟机启动后，你可以看到下面的画面</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/1d48fe1ff92365e01195973549c01a9a20110821113249.png" id="ematt:381" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-1d48fe1ff92365e01195973549c01a9a20110821113249.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">&nbsp;</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">第一和第二的项目是让你不用安装体验高、中DPI的Android-x86,有兴趣的话可以先运行体验一下x86的速度</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">我们要安装Android到硬盘，选择最后一项后回车<br />Installation - Install Android-x86 to harddisk</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">接下来我们会进入安装界面，界面效果如下</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/f6c57ed61955aeed05d88bedbf5d9da320110821113630.png" id="ematt:382" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-f6c57ed61955aeed05d88bedbf5d9da320110821113630.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">我们选择Create/Modify partitions来创建分区</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">首先我们选择new来创建新分区</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/1e37d03623b71b3723266bf9bcbd9ea920110821114238.png" id="ematt:383" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-1e37d03623b71b3723266bf9bcbd9ea920110821114238.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">选择Primary创建主分区</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/5fa62c94b058ac936c8f7b0183b747fd20110821114239.png" id="ematt:384" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-5fa62c94b058ac936c8f7b0183b747fd20110821114239.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">分区大小采用默认大小即可</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/5489ae89fbfda297455c5093aa9dc6f720110821114239.png" id="ematt:385" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-5489ae89fbfda297455c5093aa9dc6f720110821114239.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">然后我们设定该分区可以引导(选中Bootable后回车)，这是分区的flag会显示boot，然后我们再选择write将修改写入到硬盘(选择write之后还需要输入yes来确认)</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/4fd76a5d2ca20748ee9505de33e888f320110821114239.png" id="ematt:386" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-4fd76a5d2ca20748ee9505de33e888f320110821114239.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><br />分区完毕后再选择quit即可退出，退出后，我们就能看到刚才分配的新分区被识别出来了</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/74e66bd531867bc7b0c80372f08acc1c20110821114528.png" id="ematt:387" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-74e66bd531867bc7b0c80372f08acc1c20110821114528.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">按下回车选择该分区，这时会询问采用什么分区格式格式化分区，建议选择ext3</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/212d388711ad83cdcfc2a588453de62d20110821114651.png" id="ematt:388" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-212d388711ad83cdcfc2a588453de62d20110821114651.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">选择好格式后系统会再跟你确认一遍，输入yes安装就会开始了</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">安装中途会询问你是否安装Grub,这里一定要选择YES,因为我们后需要Grub来自定义启动Android</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/f0a276fb144160562ea4fa09447e511220110821114917.png" id="ematt:389" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-f0a276fb144160562ea4fa09447e511220110821114917.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">&nbsp;</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">安装Grub的时候会询问你是否将/system目录安装为读写模式(设为读写可以更方便的debug，但是会占用更多的空间和安装时间)，选择yes</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">&nbsp;</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/a4ad941f0ca2861e6e2a834a26ccd2a720110821115100.png" id="ematt:390" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-a4ad941f0ca2861e6e2a834a26ccd2a720110821115100.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">回车后安装就会开始了</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/67ed57f02287e4aa89d7afa19c01f60a20110821115220.png" id="ematt:391" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-67ed57f02287e4aa89d7afa19c01f60a20110821115220.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">安装结束后，会弹出一个菜单</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">&nbsp;</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">三个选项分别是</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">运行Android<br />创建一个虚拟SD卡<br />重启</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/f23ab9b6824405bbc928a4bb5046db2d20110821115418.png" id="ematt:392" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-f23ab9b6824405bbc928a4bb5046db2d20110821115418.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">因为我们开发肯定会用到SD卡，所以在此我们创建一个虚拟SD卡</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">创建时会询问SD卡的大小，根据你的需要设定即可，我在此设定的是128MB</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/3bfa4043716823c89436acdf3cf8eb4820110821115652.png" id="ematt:393" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-3bfa4043716823c89436acdf3cf8eb4820110821115652.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">回车后安装程序就会开始初始化sd卡了</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">格式完毕后，会提示重启，此时退出虚拟机光驱中的系统盘后重启，重启后就能进入Android系统了</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><span style="color: rgb(229, 51, 51);">注意使用在Android系统中使用鼠标的时候需要设置Virtual Box禁止自动鼠标独占，否则鼠标在Android中无法正常使用</span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/ba40b1c7ba7b1b12ea0f2e1c8e589e5920110821120440.png" id="ematt:394" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/ba40b1c7ba7b1b12ea0f2e1c8e589e5920110821120440.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">Android-x86运行截图：</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/1bc567d25f6c32829b29861a664a6d7620110821120440.png" id="ematt:395" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-1bc567d25f6c32829b29861a664a6d7620110821120440.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;">思想之地</a>原创文章，谢绝转载</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px; font-weight: bold;"><span style="font-size: 16px;">4.自定义虚拟机分辨率</span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">我们在开发时肯定需要测试不同的分辨率，那么如何自定义Android虚拟机的分辨率呢？</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">首先我们需要从Virtual Box的设定入手</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">打开cmd,进入Virtual Box的下你创建的虚拟机的目录，我创建的虚拟机叫Android-x86，我的账户是Administrator，在我Windows XP上的路径是</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">C:\Documents and Settings\Administrator\VirtualBox VMs\Android-x86</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><span style="color: rgb(229, 51, 51);">注意：</span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><span style="color: rgb(229, 51, 51);">1.在不同操作系统下路径会有一些不同，请根据操作系统的实际情况寻找，原则上都是在</span><span style="color: rgb(229, 51, 51);">你当前用户的个人文件夹里</span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><span style="color: rgb(229, 51, 51);">2.</span><span style="color: rgb(229, 51, 51);">Android-x86是我创建的虚拟机的名称，如果你的和我的不同，请修改为你创建的虚拟机的名称</span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">在这里我们需要使用VirtualBox提供的命令行工具来给你的虚拟机添加一个自定义分辨率，例如我想添加一个现在流行的手机屏幕分辨率 480x800,那么我们输入的命令如下</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><span style="color: rgb(0, 102, 0);"><span style="font-weight: bold;">&quot;C:\Program Files\Oracle\VirtualBox\VBoxManage.exe&quot;</span>&nbsp;setextradata &quot;</span><span style="color: rgb(0, 102, 0); font-weight: bold;">Android-x86</span><span style="color: rgb(0, 102, 0);">&quot; &quot;CustomVideoMode1&quot; &quot;<span style="font-weight: bold;">480x800x16</span>&quot;</span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">上面的命令中，加粗的部分是要根据你自己电脑上的情况进行修改的，相关解释如下：</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><span style="color: rgb(0, 102, 0); font-weight: bold;">&quot;C:\Program Files\Oracle\VirtualBox\VBoxManage.exe&quot;</span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">是Virtual Box命令行工具VBoxManage.exe的完整路径，请根据你电脑上安装的VirtualBox的实际路径修改</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><span style="color: rgb(229, 51, 51);">注意：如果路径中含有空格请使用双引号将整个路径包起来</span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><span style="color: rgb(0, 102, 0); font-weight: bold;">Android-x86</span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">这个是虚拟机的名称</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><span style="color: rgb(0, 102, 0);"><span style="font-weight: bold;">480x800x16</span></span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">这个是自定义的分辨率，请根据自己的需要修改，后面的16指的是16位颜色，请勿修改</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">如果你想增加更多的分辨率，请修改参数后多次运行该命令即可</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/08552fc17ae2684665d0df058b2fe41420110822001004.png" id="ematt:396" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-08552fc17ae2684665d0df058b2fe41420110822001004.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">修改完毕之后，启动虚拟机，在Android的启动画面选中选项后按两次e键编辑内核启动参数，增加一个参数 vga=ask,具体流程如下<br />启动画面按e键</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/6f642b67693d3c7c3dcecb43200871a520110822001822.png" id="ematt:397" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-6f642b67693d3c7c3dcecb43200871a520110822001822.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">进入新画面后再按一次e键</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/26f1afd021893ef8bbb67a02d9057f4520110822001822.png" id="ematt:399" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-26f1afd021893ef8bbb67a02d9057f4520110822001822.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">这时进入内核参数编辑状态，增加参数&nbsp; vga=ask</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/01ec630d241b1f252404035d82be95bb20110822001822.png" id="ematt:398" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-01ec630d241b1f252404035d82be95bb20110822001822.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">编辑完毕后按回车保存修改结果，这时会回到上一个页面，此时按下b键启动</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">此时系统会提示你按回车进入分辨率选择界面，我们按回车继续</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/13b42dd4e03bb60ab1f662f004e5340820110822002356.png" id="ematt:400" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-13b42dd4e03bb60ab1f662f004e5340820110822002356.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">进入页面之后，你可以看到所有系统支持的分辨率，这时请寻找你刚才设定的分辨率，在下图中，可以找到在先前设定的 480x800的分辨率，注意其前面的16进制代码360，如果想以该分辨率启动虚拟机，我们就输入360再回车即可</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/de875c27689da7e3679df563b829fb0520110822002356.png" id="ematt:401" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-de875c27689da7e3679df563b829fb0520110822002356.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">回车后Android就会按照你设定的分辨率来启动了，下图是以480x800分辨率启动的Android-x86虚拟机截图</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/dcb589d2f2acdb4c59c01819789da63520110822002928.png" id="ematt:402" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-dcb589d2f2acdb4c59c01819789da63520110822002928.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><span style="color: rgb(229, 51, 51);">注意：</span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><span style="color: rgb(229, 51, 51);">如果你需要系统采用你指定的分辨率启动，需要在每次Android虚拟机启动的时候</span><span style="color: rgb(229, 51, 51);">执行上面步骤的操作来修改内核参数启动Android</span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">如果你想Android在启动的时候就默认进入分辨率选择画面或者默认采用你指定的分辨率启动虚拟机，那么可以参考以下步骤</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">1. 进入android虚拟机后按alt+F1进入命令行</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">2. 输入mkdir /data/fs</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">3. 挂载硬盘，使用下列命令</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">mount -t 硬盘格式 /dev/block/硬盘名称 /data/fs</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">硬盘格式为你虚拟机硬盘的格式，我这里是ext3 硬盘名称则是你虚拟机的</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">硬盘名称我这默认是sda1,表示第一个sata硬盘, linx下具体的硬盘命名规则请自行Google之</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">mount -t ext3 /dev/block/sda1 /data/fs</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">将硬盘挂在到 /data/fs文件夹上</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">4. vi /data/fs/grub/menu.list 编辑启动菜单列表 (vi这个命令行编辑器怎么用请自行Google之)</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">5. 和刚才启动时一样，在第一个kernel那一行的末尾增加 vga=ask 后保存<br />6. 重启虚拟机，这时候你就会发现每次Android启动的时候就会询问分辨率了</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;">思想之地</a>原创文章，谢绝转载</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px; font-weight: bold;"><span style="font-size: 16px;">5.使用eclipse ADT在虚拟机上远程调试开发</span></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">&nbsp;</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">现在虚拟机已经配置完成，下面来讲解如何使用eclipse来在上面运行和调试Android应用程序</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">在前面设定虚拟机的时候我把虚拟机的网卡设置成了bridged adapter，这样虚拟机在局域网中相当于一台独立电脑，你可以给它设置一个ip或者讲其网卡设置为dhcp状态来自动获取ip，我下面只讲解一下在dhcp状态下如何查看android虚拟机ip的方法：</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">进入android虚拟机，按alt+F1进入命令，输入<b>netcfg</b>命令来查看网络状态，参考界面如下</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/7c4304f0dbef88224333bc5f2820b4f820110822004040.png" id="ematt:403" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-7c4304f0dbef88224333bc5f2820b4f820110822004040.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">其中eth0就是当前的网卡，后面的ip地址就是通过dhcp获得的ip地址</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">弄清楚之后再按alt+F7返回图形界面</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">此时我们打开eclipse,进入android开发插件的设定界面,选择ddms,勾选 Use ado host, 并在ADT host value 一栏填写虚拟机的ip地址,具体界面请参看下图</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/de1cb884850b078c5991e5b49388535720110822004406.png" id="ematt:404" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-de1cb884850b078c5991e5b49388535720110822004406.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">选择ok保存后，在ddms界面的device菜单上选择重启adb服务，重启后，就能看到ddms连接上虚拟机了<br /><a target="_blank" href="http://be-evil.org/content/uploadfile/201108/f98029c2d292d8d65de15c13a601e1d420110822004632.png" id="ematt:405" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;"><img src="http://be-evil.org/content/uploadfile/201108/thum-f98029c2d292d8d65de15c13a601e1d420110822004632.png" alt="点击查看原图" border="0" style="border: 0px; vertical-align: middle;" /></a></p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">接下来就能和平常一样在虚拟上运行和测试你的Android程序了,enjoy~</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;"><a target="_blank" href="http://be-evil.org/" style="color: rgb(59, 89, 152); text-decoration: none; outline: none;">思想之地</a>原创文章，谢绝转载</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">最后总结一下这个环境的优缺点：</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">优点：<br />1.高速,相比Android SDK的虚拟机,无论是启动还是运行,本虚拟机要快上很多很多,让你可以流畅的运行测试你的Android应用,当然,也能舒服的在电脑上体验到Android系统:)<br />2.可以模拟平板电脑的环境</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">缺点：</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">1.硬件支持还是悲剧,像打电话,短信,重力感应,GPS摄像头什么的你还是得去弄台真机器调试（不过这些东西本来就不是模拟器能做的）</p><p style="margin: 0px; padding: 0px 0px 15px; line-height: 20px;">另外补充一下虚拟机中主页、返回、关机、菜单对应的键盘按键<br />Home键 -&gt; Win键<br />返回键 -&gt; ESC键<br />挂机键 -&gt; alt+F4<br />菜单键 -&gt; 键盘菜单键,一般在右边win键和ctrl键中间</p></div>]]></description><category>Android</category><comments>http://blog.careff.com/post/369.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=369</wfw:commentRss></item><item><title>Android上中下三行布局</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/368.html</link><pubDate>Wed, 24 Apr 2013 17:07:54 +0800</pubDate><guid>http://blog.careff.com/post/368.html</guid><description><![CDATA[<p>&nbsp;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</p><div>&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</div><div>&nbsp; &nbsp; xmlns:app=&quot;http://schemas.android.com/apk/res/com.lc&quot;</div><div>&nbsp; &nbsp; android:layout_width=&quot;fill_parent&quot;</div><div>&nbsp; &nbsp; android:layout_height=&quot;fill_parent&quot;</div><div>&nbsp; &nbsp; android:background=&quot;#EDEDED&quot;</div><div>&nbsp; &nbsp; android:orientation=&quot;vertical&quot; &gt;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &lt;com.lc.basic.widget.LcNav</div><div>&nbsp; &nbsp; &nbsp; &nbsp; xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; xmlns:app=&quot;http://schemas.android.com/apk/res/com.lc.product&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:id=&quot;@+id/contacts_navview&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width=&quot;fill_parent&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height=&quot;54dp&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:layout_alignParentTop=&quot;true&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:background=&quot;@drawable/navtopbg&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:padding=&quot;6dp&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; app:leftButtonText=&quot;设置&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; app:leftButtonVisible=&quot;false&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; app:rightButtonText=&quot;&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; app:rightButtonVisible=&quot;false&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; app:titleText=&quot;联系人列表&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; app:titleVisible=&quot;true&quot; /&gt;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &lt;com.lc.basic.widget.LcListView</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:id=&quot;@+id/list_contacts1&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width=&quot;fill_parent&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height=&quot;wrap_content&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:layout_above=&quot;@+id/contacts_layoutname&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:layout_below=&quot;@+id/contacts_navview&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:layout_margin=&quot;0dp&quot; /&gt;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &lt;LinearLayout</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:id=&quot;@+id/contacts_layoutname&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width=&quot;fill_parent&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height=&quot;wrap_content&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:layout_alignParentBottom=&quot;true&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:layout_span=&quot;2&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:orientation=&quot;horizontal&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; android:padding=&quot;6dp&quot; &gt;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;LinearLayout</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width=&quot;fill_parent&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height=&quot;fill_parent&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_weight=&quot;1&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:paddingRight=&quot;4dip&quot; &gt;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Button</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id=&quot;@+id/contacts_selectall&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width=&quot;fill_parent&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height=&quot;36dip&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_weight=&quot;1&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:background=&quot;@drawable/v_selector_btn_quit&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:text=&quot;全选&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textColor=&quot;@color/white&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textSize=&quot;18dip&quot; &gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/Button&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/LinearLayout&gt;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;LinearLayout</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width=&quot;fill_parent&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height=&quot;fill_parent&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_weight=&quot;1&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:paddingLeft=&quot;4dip&quot; &gt;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Button</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id=&quot;@+id/contacts_submit&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width=&quot;fill_parent&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height=&quot;36dip&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_weight=&quot;1&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:background=&quot;@drawable/v_selector_btn_login&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:text=&quot;确认&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textColor=&quot;@color/white&quot;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textSize=&quot;18dip&quot; &gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/Button&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/LinearLayout&gt;</div><div>&nbsp; &nbsp; &lt;/LinearLayout&gt;</div><div>&nbsp;</div><div>&lt;/RelativeLayout&gt;</div>]]></description><category>Android</category><comments>http://blog.careff.com/post/368.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=368</wfw:commentRss></item></channel></rss>
