﻿{"id":1311,"date":"2015-05-22T10:29:41","date_gmt":"2015-05-22T02:29:41","guid":{"rendered":"http:\/\/nick.txtcc.com\/?p=1311"},"modified":"2015-05-22T10:29:41","modified_gmt":"2015-05-22T02:29:41","slug":"openssl%e7%a7%bb%e6%a4%8d%e5%88%b0android","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/android-ios\/1311","title":{"rendered":"Openssl\u79fb\u690d\u5230Android"},"content":{"rendered":"<p>Openssl\u79fb\u690d\u5230Android\u90fd\u662f\u4f7f\u7528\u522b\u4eba\u63d0\u597d\uff08\u4eceAndroid\u6e90\u7801\uff09\u7684Openssl\u4ee3\u7801\uff0c\u65b9\u6cd5\u7b80\u5355\u4f46\u8fc7\u7a0b\u4e0d\u90a3\u4e48\u987a\u5229\uff0c\u56e0\u4e3aOpenssl\u7248\u672c\u53d8\u52a8\u592a\u9891\u7e41\u4e86\uff0c\u518d\u52a0\u4e0aNDK\u4e00\u5806BUG\uff0c\u6781\u4e0d\u613f\u610f\u53bb\u8c03\u8bd5\u539f\u59cb\u914d\u7f6e\uff0c\u5355\u5355Openssl\u7684\u6a21\u5757\u7f16\u8bd1\u524d\u540e\u5c31\u7b49\u4e86\u4e24\u4e2a\u6708\u76f4\u5230Google\u63a8\u51faNDK\u65b0\u7248\u672cR8C\u624d\u7f16\u8bd1\u901a\u8fc7\u3002\u56e0\u4e3a\u539f\u751f\u7a0b\u5e8f\u5e94\u7528\u5230\u5f88\u591aOpenssl\u7b7e\u540d\u3001\u9a8c\u8bc1\u7b97\u6cd5\u51fd\u6570\uff0c\u5c31\u8fdeOpenssl\u7684\u7248\u672c\u5347\u7ea7\u4e00\u4e0b\u5f80\u5f80\u90fd\u8981\u4fee\u6539\u4e00\u4e9b\u4ee3\u7801\u624d\u80fd\u901a\u8fc7\u3002<\/p>\n<h2>\u4e00\u3001\u4e0b\u8f7dOpenssl\u6700\u65b0\u7248\u672c<\/h2>\n<p>\u53ef\u9009\u7684Openssl Android\u7248\u672c\u4e0b\u8f7d\u5730\u5740\uff1a<\/p>\n<p>Openssl 1.0.0a\uff1a<\/p>\n<p><a href=\"https:\/\/github.com\/guardianproject\/openssl-android\" target=\"_blank\"><a href=\"https:\/\/github.com\/guardianproject\/openssl-android\">https:\/\/github.com\/guardianproject\/openssl-android<\/a><\/a><\/p>\n<p>Openssl 1.0.1c\uff1a<\/p>\n<p><a href=\"https:\/\/github.com\/aluvalasuman\/OpenSSL1.0.1cForAndroid\" target=\"_blank\"><a href=\"https:\/\/github.com\/aluvalasuman\/OpenSSL1.0.1cForAndroid\">https:\/\/github.com\/aluvalasuman\/OpenSSL1.0.1cForAndroid<\/a><\/a><\/p>\n<p>\u672c\u6587\u5c06\u8981\u4f7f\u7528\u7684Openssl\u7248\u672c\u4e3a1.0.1c\uff0c\u524d\u4e001.0.0a\u7248\u672c\u672a\u9a8c\u8bc1\u901a\u8fc7\uff08NDKr8b\uff09\uff0c\u7f16\u8bd1\u65f6\u4f1a\u51fa\u73b0\u4e0b\u6587\u7684\u7f16\u8bd1\u9519\u8bef\u3002\u6240\u4ee5\u6539\u7528\u8f83\u65b0\u7248\u672c\uff0c\u76ee\u524d\u5df2\u77e51.0.1c\u5728NDK r8b\u4e0a\u7f16\u8bd1\u4f1a\u6709\u5f88\u591a\u95ee\u9898\uff0c\u4e0d\u662fOpenssl\u5de5\u7a0b\u6709\u517c\u5bb9BUG\u5c31\u662fNDK\u7248\u672c\u6709BUG\uff0c\u53cd\u6b63\u4e0d\u662f\u90a3\u4e48\u5bb9\u6613\u8c03\u8bd5\u901a\u8fc7\u3002<\/p>\n<h2>\u4e8c\u3001\u7f16\u8bd1\u8fc7\u7a0b<\/h2>\n<p>\u672c\u6587\u7f16\u8bd1\u4f7f\u7528\u6700\u65b0\u7684NDK r8c\uff08Ubuntu 12.04\uff09\uff0c\u4e0b\u8f7dOpenssl android\u5de5\u7a0b\u540e\u89e3\u538b\uff0c\u53ef\u4ee5\u770b\u5230\u5b8c\u6574\u7684NDK\u5de5\u7a0b\uff0c\u7b80\u5355\u7684\u7f16\u8bd1\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n<ol>\n    <li>\u8fdb\u5165\u89e3\u538b\u76ee\u5f55\uff0c\u6267\u884c:<\/li>\n    <li>$NDK_HOME\/ndk-build clean<\/li>\n    <li>$NDK_HOME\/ndk-build<\/li>\n    <li>\u7f16\u8bd1\u7ed3\u679c\u5728obj\u76ee\u5f55\u4e0b\uff08libcrypto-static.a\u548clibssl-static.a\u6216\u662flibcrypto.so\u548clibssl.so\uff09<\/li>\n    <li>\u628a\u7ed3\u679c\u62f7\u8d1d\u51fa\u6765\u653e\u5230\u81ea\u5df1\u7684Android\u5de5\u7a0bHelloworld\u5bf9\u5e94\u76ee\u5f55\u4e0b\u8fdb\u884c\u8c03\u7528\u5373\u53ef\u3002<\/li>\n<\/ol>\n<p>\u4e0a\u8ff0\u6b65\u9aa44\u7f16\u8bd1\u51faOpenssl\u7684\u94fe\u63a5\u5e93\uff0c\u4e00\u822c\u62f7\u8d1d\u5230ndk_r8c\\platforms\\android-10\\arch-arm\\usr\\lib\u76ee\u5f55\u4e0b\uff08\u4ec5\u4e3a\u793a\u4f8b\uff09\uff0c\u7136\u540e\u628aopenssl\u6839\u4e0b\u7684include\u76ee\u5f55\u90fd\u62f7\u8d1d\u51fa\u53bb\u5c31\u662f\u7f16\u8bd1\u5934\u6587\u4ef6\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u6784\u5efa\u81ea\u5df1\u7684helloworld\u5de5\u7a0b\u4e86\uff0c\u5728helloworld\u7684Android.mk\u4e2d\u589e\u52a0\u7c7b\u4f3c\u5982\u4e0b\u8c03\u7528\uff1a<\/p>\n<p>LOCAL_LDLIBS := -L$(SYSROOT)\/lib\/ -llog -lcrypto -lssl<\/p>\n<h2>\u4e09\u3001\u5e38\u89c1\u9519\u8bef<\/h2>\n<p>\u4ee5\u4e0b\u7f16\u8bd1\u9519\u8bef\uff0c\u6709\u7684\u57281.0.0a\u7248\u672c\u4e2d\u9047\u5230\uff0c\u6709\u7684\u662f\u5728NDK r8b\u73af\u5883\u4e0b\u9047\u5230\uff0c\u6b64\u95f4\u6d89\u53ca\u5230OpenSSL\u7248\u672c\u95ee\u9898\u3001GCC\u7248\u672c\u95ee\u9898\u3001NDK\u7248\u672cBUG\u95ee\u9898\uff0c\u7b49\u7b49\u90fd\u6df7\u5230\u4e00\u8d77\u603b\u7ed3\u65b9\u4fbf\u5bf9\u5e94\u5904\u7406\u3002<\/p>\n<h3>1\u3001undefined reference to `zError&#8217;<\/h3>\n<p>openssl \u5e93\u65f6\u9519\u8bef\u5982\u4e0b\uff1a<\/p>\n<pre class=\"mycode\">SharedLibrary  : libssl.so\nExecutable     : openssl\n\/root\/android-ndk-r8b\/toolchains\/arm-linux-androideabi-4.6\/prebuilt\/linux-x86\/bin\/..\/lib\/gcc\/arm-linux-androideabi\/4.6.x-google\/..\/..\/..\/..\/arm-linux-androideabi\/bin\/ld: warning: libz.so, needed by .\/obj\/local\/armeabi\/libcrypto.so, not found (try using -rpath or -rpath-link)\n\n.\/obj\/local\/armeabi\/libcrypto.so: undefined reference to `zError'\n.\/obj\/local\/armeabi\/libcrypto.so: undefined reference to `inflateEnd'\n.\/obj\/local\/armeabi\/libcrypto.so: undefined reference to `deflate'\n.\/obj\/local\/armeabi\/libcrypto.so: undefined reference to `deflateInit_'\n.\/obj\/local\/armeabi\/libcrypto.so: undefined reference to `inflate'\n.\/obj\/local\/armeabi\/libcrypto.so: undefined reference to `deflateEnd'\n.\/obj\/local\/armeabi\/libcrypto.so: undefined reference to `inflateInit_'\ncollect2: ld returned 1 exit status<\/pre>\n<p>\u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n<p>1\u3001$NDK_HOME\/ndk-build NDK_TOOLCHAIN_VERSION=4.4.3\n\u6216\n$NDK_HOME\/ndk-build NDK_TOOLCHAIN=arm-linux-androideabi-4.4.3<\/p>\n<p>\u8be5\u65b9\u6cd5\u53c2\u8003\u6765\u81ea\uff1aandroid-ndk-r8b\/doc\/NDK-BUILD.html \u8bf4\u660e\uff0cndk-build\u53ef\u4ee5\u643a\u5e26 NDK_XXX\u8fd9\u6837\u7684\u53c2\u6570\uff0c\u6765\u6307\u5b9a\u7f16\u8bd1\u73af\u5883\u7248\u672c\u4fe1\u606f\u3002\u5177\u4f53\u53c2\u6570\u6709\u54ea\u4e9b\uff1f\u76ee\u524d\u53ef\u4ee5\u901a\u8fc7android-ndk-r8b\/build\/core\/init.mk\u91cc\u67e5\u8be2\u5230\u4e00\u4e9bNDK_\u5f00\u5934\u7684\u53c2\u6570\u3002<\/p>\n<p>2\u3001\u5728openssl\u7684jni\u76ee\u5f55\u4e0b\u7684Application.mk\u4e2d\u589e\u52a0\uff1a<\/p>\n<p>APP_PLATFORM := android-8<\/p>\n<p>3\u3001\u5728openssl\u6839\u4e0b\u7684android-config.mk\u4e2d\u589e\u52a0\uff1a<\/p>\n<p>APP_ABI := armeabi armeabi-v7a<\/p>\n<p>\u8be5\u53c2\u8003\u6765\u6e90android-ndk-r8b\/docs\/APPLICATION-MK.html<\/p>\n<h3>2\u3001Unknown EABI object attribute 44<\/h3>\n<pre class=\"mycode\">SharedLibrary  : libssl.so\n\/root\/android-ndk-r8b\/toolchains\/arm-linux-androideabi-4.4.3\/prebuilt\/linux-x86\/bin\/..\/lib\/gcc\/arm-linux-androideabi\/4.4.3\/..\/..\/..\/..\/arm-linux-androideabi\/bin\/ld: Warning: \/root\/android-ndk-r8b\/platforms\/android-8\/arch-arm\/usr\/lib\/crtend_so.o: Unknown EABI object attribute 44\nExecutable     : openssl\n\/root\/android-ndk-r8b\/toolchains\/arm-linux-androideabi-4.4.3\/prebuilt\/linux-x86\/bin\/..\/lib\/gcc\/arm-linux-androideabi\/4.4.3\/..\/..\/..\/..\/arm-linux-androideabi\/bin\/ld: Warning: \/root\/android-ndk-r8b\/platforms\/android-8\/arch-arm\/usr\/lib\/crtend_android.o: Unknown EABI object attribute 44\nInstall        : openssl => \/root\/aluvalassuman\/libs\/armeabi\/openssl\nInstall        : libssl.so => \/root\/aluvalassuman\/libs\/armeabi\/libssl.so\nCompile thumb  : ssltest <= ssltest.c\nExecutable     : ssltest\n\/root\/android-ndk-r8b\/toolchains\/arm-linux-androideabi-4.4.3\/prebuilt\/linux-x86\/bin\/..\/lib\/gcc\/arm-linux-androideabi\/4.4.3\/..\/..\/..\/..\/arm-linux-androideabi\/bin\/ld: Warning: \/root\/android-ndk-r8b\/platforms\/android-8\/arch-arm\/usr\/lib\/crtend_android.o: Unknown EABI object attribute 44\nInstall        : ssltest => \/root\/aluvalassuman\/libs\/armeabi\/ssltest<\/pre>\n<p>\u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n<p>4.4.3\u4f3c\u4e4e\u8ddf\u94fe\u63a5\u5e93\u7684\u7f16\u8bd1\u73af\u5883\u53ef\u80fd\u5bf9\u4e0d\u4e0a\uff0844\u51b2\u7a81\uff09\uff0c\u7f51\u4e0a\u6709\u8bf4\u6539\u62104.6\u5c31\u6ca1\u95ee\u9898\u4e86\uff0c\u4e0d\u4f1a\u51fa\u73b0\u8be5\u63d0\u793a\uff0c\u4f46\u662f4.6\u652f\u6301STL\u6709BUG\u554a\uff1f<\/p>\n<p>crypto\/Android.mk \u5927\u7ea6535\u884c\uff0c\u6dfb\u52a0\uff1a<\/p>\n<p>LOCAL_EXPORT_LDLIBS := -lz<\/p>\n<p>\u6ce8\u610f\u6709\u6ca1\u6dfb\u52a0\u4ee5\u4e0b\u4e24\u4e2a\u9759\u6001\u5e93\uff0c\u5927\u7ea6576\u884c\uff0c\u6dfb\u52a0(\u6682\u65f6\u4e0d\u7528)\uff1a<\/p>\n<p>LOCAL_LDLIBS := -lz \u2013ldl<\/p>\n<h3>3\u3001build\/gmsl\/__gmsl:512: *** non-numeric second<\/h3>\n<p>Complile Openssl:<\/p>\n<p>Error:\nbuild\/gmsl\/__gmsl:512: *** non-numeric second\nChanges:<\/p>\n<p>I changed the file\u00a0 __gmsl, the second wordlist argument(line 512),\nand it&#8217;s running my jni example without errors:<\/p>\n<p>int_encode = $(__gmsl_tr1)$(wordlist 1, $1,$(__gmsl_input_int))<\/p>\n<p>to:<\/p>\n<p>int_encode = $(__gmsl_tr1)$(wordlist 1,$(words $1),$\n(__gmsl_input_int))<\/p>\n<p><strong>\u53c2\u8003\u8d44\u6599\uff08\u4e0b\u8ff0\u53ef\u80fd\u6709\u5730\u5740\u88ab\u5899\u4e86\uff09\uff1a<\/strong><\/p>\n<p><a href=\"http:\/\/www.uml.org.cn\/mobiledev\/201108101.asp\" target=\"_blank\"><a href=\"http:\/\/www.uml.org.cn\/mobiledev\/201108101.asp\">http:\/\/www.uml.org.cn\/mobiledev\/201108101.asp<\/a><\/a><\/p>\n<p><a href=\"http:\/\/blog.csdn.net\/someonea\/article\/details\/6312213\" target=\"_blank\"><a href=\"http:\/\/blog.csdn.net\/someonea\/article\/details\/6312213\">http:\/\/blog.csdn.net\/someonea\/article\/details\/6312213<\/a><\/a><\/p>\n<p><a href=\"http:\/\/ssuman185.blogspot.sg\/p\/steps-for-porting-openssl-for-android.html\" target=\"_blank\"><a href=\"http:\/\/ssuman185.blogspot.sg\/p\/steps-for-porting-openssl-for-android.html\">http:\/\/ssuman185.blogspot.sg\/p\/steps-for-porting-openssl-for-android.html<\/a><\/a><\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/11856688\/openssl-build-issue-with-android-ndk-r8\" target=\"_blank\"><a href=\"http:\/\/stackoverflow.com\/questions\/11856688\/openssl-build-issue-with-android-ndk-r8\">http:\/\/stackoverflow.com\/questions\/11856688\/openssl-build-issue-with-android-ndk-r8<\/a><\/a><\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/11929773\/compiling-the-latest-openssl-for-android\" target=\"_blank\"><a href=\"http:\/\/stackoverflow.com\/questions\/11929773\/compiling-the-latest-openssl-for-android\">http:\/\/stackoverflow.com\/questions\/11929773\/compiling-the-latest-openssl-for-android<\/a><\/a><\/p>\n<p><a href=\"https:\/\/groups.google.com\/forum\/?fromgroups=#!topic\/android-ndk\/b4DSxE1NAS0\" target=\"_blank\"><a href=\"https:\/\/groups.google.com\/forum\/?fromgroups=#!topic\/android-ndk\/b4DSxE1NAS0\">https:\/\/groups.google.com\/forum\/?fromgroups=#!topic\/android-ndk\/b4DSxE1NAS0<\/a><\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Openssl\u79fb\u690d\u5230Android\u90fd\u662f\u4f7f\u7528\u522b\u4eba\u63d0\u597d\uff08\u4eceAndroid\u6e90\u7801\uff09\u7684Openssl\u4ee3\u7801\uff0c\u65b9\u6cd5\u7b80\u5355\u4f46\u8fc7\u7a0b\u4e0d\u90a3\u4e48\u987a\u5229\uff0c\u56e0\u4e3aOpenssl\u7248\u672c\u53d8\u52a8\u592a\u9891\u7e41\u4e86\uff0c\u518d\u52a0\u4e0aNDK\u4e00\u5806BUG\uff0c\u6781\u4e0d\u613f\u610f\u53bb\u8c03\u8bd5\u539f\u59cb&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[380],"tags":[391,411,410,384],"class_list":["post-1311","post","type-post","status-publish","format-standard","hentry","category-android-ios","tag-android","tag-jni","tag-ndk","tag-openssl"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=1311"}],"version-history":[{"count":1,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1311\/revisions"}],"predecessor-version":[{"id":1312,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1311\/revisions\/1312"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=1311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=1311"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=1311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}