{"id":5706,"date":"2017-09-07T11:43:06","date_gmt":"2017-09-07T02:43:06","guid":{"rendered":"https:\/\/www.vincentina.net\/?p=5706"},"modified":"2021-12-22T22:49:25","modified_gmt":"2021-12-22T13:49:25","slug":"android%e3%81%ae%e9%96%8b%e7%99%ba%e3%81%a7c%e3%81%ae%e3%82%b3%e3%83%bc%e3%83%89%e3%82%92%e4%bd%bf%e3%81%86%e3%81%ab%e3%81%af","status":"publish","type":"post","link":"https:\/\/www.vincentina.net\/?p=5706","title":{"rendered":"Android\u306e\u958b\u767a\u3067C++\u306e\u30b3\u30fc\u30c9\u3092\u4f7f\u3046\u306b\u306f"},"content":{"rendered":"<p>C\/C++\u3092\u4f7f\u3046\u65b9\u6cd5\u3067\u3059\u304c\u3001ndk-build(\u53e4\u3044)\u3092\u4f7f\u3046\u65b9\u6cd5\u3068CMake(\u65b0\u3057\u3044)\u3092\u4f7f\u3046\u65b9\u6cd5\u304c\u3042\u308b\u3088\u3046\u3067\u3001\u4eca\u56de\u306fCMake\u3092\u4f7f\u3046\u65b9\u6cd5\u3067\u3059\u3002\u3053\u308c\u3089\u306e\u5177\u4f53\u7684\u306a\u4ed5\u7d44\u307f\u306f\u5206\u304b\u308a\u307e\u305b\u3093\u304c\u3001\u3053\u308c\u3092\u3064\u304b\u3063\u3066\u898f\u5247\u306b\u6cbf\u3063\u3066\u9032\u3081\u3066\u3044\u3051\u3070\u3046\u307e\u304f\u30d3\u30eb\u30c9\u3057\u3066\u304f\u308c\u308b\u3088\u3046\u3067\u3059\u3002\u4fbf\u5229\u306a\u3082\u3093\u3060\u3002<\/p>\n<p>Android\u3067\u30b0\u30b0\u3063\u3066\u3044\u308b\u3068\u3001\u30cd\u30a4\u30c6\u30a3\u30d6\u30b3\u30fc\u30c9\u3068\u304b\u3044\u3046\u8a00\u8449\u3092\u3088\u304f\u76ee\u306b\u3059\u308b\u3053\u3068\u304c\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002C\/C++\u304c\u305d\u308c\u306b\u3042\u305f\u308b\u305d\u3046\u3067\u3059\u3002\u4f7f\u3044\u65b9\u3067\u3059\u304c\u3001Android Studio\u306eSDK\u30c4\u30fc\u30eb\u3067LLDB\u3001CMake\u3001NDK\u3068\u3044\u30463\u500b\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u6a2a\u7740\u306a\u4eba\u306f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u4f5c\u6210\u306e\u3068\u304d\u306b\u3053\u306e\u90e8\u5206<br \/>\n<a href=\"https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/Screen-Shot-2017-09-07-at-10.43.40.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/Screen-Shot-2017-09-07-at-10.43.40.png\" alt=\"\" width=\"858\" height=\"336\" class=\"alignnone size-full wp-image-5707\" srcset=\"https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/Screen-Shot-2017-09-07-at-10.43.40.png 858w, https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/Screen-Shot-2017-09-07-at-10.43.40-300x117.png 300w, https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/Screen-Shot-2017-09-07-at-10.43.40-768x301.png 768w, https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/Screen-Shot-2017-09-07-at-10.43.40-624x244.png 624w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><br \/>\nInclude C++ Suport\u306b\u30c1\u30a7\u30c3\u30af\u3092\u5165\u308c\u3066\u4f5c\u696d\u3092\u9032\u3081\u3066\u884c\u304f\u3068\u3001\u3007\u3007\u304c\u306a\u3044\u304b\u3089\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u306a\u3088\uff01<br \/>\n\u3063\u3066\u51fa\u3066\u6765\u308b\u306e\u3067\u3001\u305d\u308c\u3067\u5165\u308c\u3066\u9032\u3081\u3066\u3082\u5927\u4e08\u592b\u3067\u3059\u3002<\/p>\n<p>\u3055\u3066\u3001MinimumSDK\u3068\u304b\u3069\u3046\u3057\u3088\u304b\u306a\u30fc\u3068\u304b\u60a9\u3080\u3068\u3053\u3067\u3059\u304c\u3001\u30c6\u30b9\u30c8\u306a\u306e\u3067\u305d\u308c\u306f\u7f6e\u3044\u3066\u304a\u3044\u3066\u30c9\u30f3\u30c9\u30f3\u9032\u3081\u3066\u884c\u304f\u3068\u3001\u666e\u6bb5\u898b\u306a\u3044\u30d5\u30a1\u30a4\u30eb\u304c\u5c11\u3057\u5897\u3048\u3066\u3044\u308b\u305e\u3068\u3002<\/p>\n<p><a href=\"https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/Screen-Shot-2017-09-06-at-20.33.01.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/Screen-Shot-2017-09-06-at-20.33.01.png\" alt=\"\" width=\"422\" height=\"500\" class=\"alignnone size-full wp-image-5709\" srcset=\"https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/Screen-Shot-2017-09-06-at-20.33.01.png 422w, https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/Screen-Shot-2017-09-06-at-20.33.01-253x300.png 253w\" sizes=\"auto, (max-width: 422px) 85vw, 422px\" \/><\/a><br \/>\ncpp\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306bnative-lib.cpp\u3001External Build Files\u306bCmakeLists.txt \u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b\u306d\u3002<\/p>\n<p>C\/C++\u3092\u4f7f\u3046\u65b9\u6cd5\u3067\u3059\u304c\u3001ndk-build(\u53e4\u3044)\u3092\u4f7f\u3046\u65b9\u6cd5\u3068CMake(\u65b0\u3057\u3044)\u3092\u4f7f\u3046\u65b9\u6cd5\u304c\u3042\u308b\u3088\u3046\u3067\u3001\u4eca\u56de\u306fCMake\u3092\u4f7f\u3046\u65b9\u6cd5\u3067\u3059\u3002<br \/>\n\u3053\u308c\u3089\u306e\u5177\u4f53\u7684\u306a\u4ed5\u7d44\u307f\u306f\u5206\u304b\u308a\u307e\u305b\u3093\u304c\u3001\u3053\u308c\u3092\u3064\u304b\u3063\u3066\u898f\u5247\u306b\u6cbf\u3063\u3066\u9032\u3081\u3066\u3044\u3051\u3070\u3046\u307e\u304f\u30d3\u30eb\u30c9\u3057\u3066\u304f\u308c\u308b\u3088\u3046\u3067\u3059\u3002<br \/>\n\u4fbf\u5229\u306a\u3082\u3093\u3060\u3002<br \/>\n\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u304c\u51fa\u6765\u4e0a\u304c\u3063\u3066\u4f55\u3082\u624b\u3092\u52a0\u3048\u305a\u306b\u30d3\u30eb\u30c9\u3057\u3066\u307f\u3066\u307f\u308b\u3068\u3001native-lib.cpp\u306b\u3042\u308bString\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u6587\u5b57\u5217\u304c\u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u306b\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u3044\u3064\u3082\u306eJava\u306eMainActivity\u3092\u898b\u308b\u3068<\/p>\n<p><pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic native String stringFromJNI();\r\n\r\nstatic {\r\n\u3000\u3000System.loadLibrary(&quot;native-lib&quot;);\r\n}\r\n<\/pre>\n<\/p>\n<p>\u3068\u3044\u3046\u3068\u3053\u308d\u304c\u3042\u308a\u307e\u3059\u3002native\u3067\u5ba3\u8a00\u3057\u3066\u3001\u4e0b\u306e3\u884c\u3067C\u3092\u547c\u3093\u3067\u308b\u611f\u3058\u3060\u306d\u3002<br \/>\nC++\u306e\u30b3\u30fc\u30c9\u306fnative-lib.cpp\u306b\u66f8\u304f\u3068\u3088\u3055\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u3053\u3053\u3067\u7a4d\u307f\u672c\u306b\u306a\u3063\u3066\u3044\u305f\u6280\u8853\u8a55\u8ad6\u793e\uff1aC++\u30af\u30e9\u30b9\u3068\u7d99\u627f\u5b8c\u5168\u5236\u8987\u3092\u53d6\u308a\u51fa\u3057\u3066C++\u306e\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u307f\u3088\u3046\u3002<br \/>\n\u3068\u3001\u305d\u306e\u524d\u306b\u30eb\u30fc\u30eb\u3092\u30c1\u30a7\u30c3\u30af\u3084\u3067\u3002<\/p>\n<p>native-lib.cpp<\/p>\n<p><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nJava_net_tjapps_testc_MainActivity_stringFromJNI(\r\n        JNIEnv* env,\r\n        jobject \/* this *\/) {\r\n<\/pre>\n<\/p>\n<p>\u30e1\u30bd\u30c3\u30c9\u306f\u3053\u306e\u5f62\u5f0f\u3067\u3001\u7b2c1\u5f15\u6570\u3001\u7b2c2\u5f15\u6570\u306f\u3053\u308c\u3067\u56fa\u5b9a\u3089\u3057\u3044\u3002\u8ffd\u52a0\u306f\u7b2c3\u304b\u3089\u3002<br \/>\n\u3042\u3068\u306fDEMO\uff1f\u3068\u3044\u3046\u304b\u4f5c\u308a\u305f\u3066\u306e\u30b3\u30fc\u30c9\u306b\u3042\u3063\u305f\u3088\u3046\u306bC++\u5185\u90e8\u3067\u306fstd::string\u3067\u3001\u8fd4\u3059\u6642\u306b\u306fJstring\u3002<br \/>\n\u3053\u308c\u306fString\u3060\u3051\u3069\u3082\u3001\u3053\u306e\u3088\u3046\u306a\u611f\u3058\u306e\u30eb\u30fc\u30eb\u3089\u3057\u3044\u3002<br \/>\n\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3057\u3066\u3067\u304d\u308b\u30b3\u30fc\u30c9\u3092\u898b\u308b\u3068\u305d\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u6280\u8853\u8a55\u8ad6\u793e\uff1aC++\u30af\u30e9\u30b9\u3068\u7d99\u627f\u5b8c\u5168\u5236\u8987\u306eList1-1\u306e\u30b3\u30fc\u30c9\u304b\u3089\u629c\u304d\u51fa\u3057\u3066\u30d3\u30eb\u30c9\u3057\u307e\u3059\u3002<\/p>\n<p><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;jni.h&gt;\r\n#include &lt;string&gt;\r\n\r\nextern &quot;C&quot;\r\nJNIEXPORT jstring JNICALL\r\nJava_net_tjapps_testc_MainActivity_stringFromJNI(\r\n        JNIEnv* env,\r\n        jobject \/* this *\/) {\r\n\r\n    struct Jugyoin {\r\n        int number;\r\n        char shimei&#x5B;80];\r\n        long kyuyo;\r\n    };\r\n\r\n        struct Jugyoin tanaka;\r\n\r\n        tanaka.number = 1234;\r\n        strcpy(tanaka.shimei, &quot;\u7530\u4e2d\u4e00\u90ce&quot;);\r\n        tanaka.kyuyo = 200000;\r\n\r\n        return env-&gt;NewStringUTF(tanaka.shimei);\r\n}\r\n<\/pre>\n<\/p>\n<p>\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30d3\u30eb\u30c9\u3059\u308b\u3068<\/p>\n<p><a href=\"https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/device-2017-09-07-104231.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/device-2017-09-07-104231.png\" alt=\"\" width=\"500\" height=\"842\" class=\"alignnone size-full wp-image-5713\" srcset=\"https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/device-2017-09-07-104231.png 500w, https:\/\/www.vincentina.net\/wp-content\/uploads\/2017\/09\/device-2017-09-07-104231-178x300.png 178w\" sizes=\"auto, (max-width: 500px) 85vw, 500px\" \/><\/a><\/p>\n<p>\u51fa\u305f\u3051\u3069\u3061\u3087\u3063\u3068\u5bc2\u3057\u3044\u3002<br \/>\n\u3067\u306f\u3053\u306e\u52e2\u3044\u3067C++\u306e\u52c9\u5f37\u3092\u3057\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u305b\u3063\u304b\u304f\u672c\u8cb7\u3063\u305f\u3057\u306a\u3042\u3001\u3068\u3051\u3063\u3053\u3046\u8ca7\u4e4f\u6027\u306a\u3093\u3060\u306a\u3002<\/p>\n<p>\u3068\u3001\u6700\u5f8c\u306e\u66f4\u65b0\u304b\u3089\u305a\u3044\u3076\u3093\u3068\u65e5\u304c\u7a7a\u3044\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002\u4e45\u3057\u3076\u308a\u306e\u66f4\u65b0\u3067\u3059\u3002<br \/>\n\u6700\u8fd1\u307e\u3067\u7d9a\u3051\u3066\u3044\u305f\u82f1\u8a9e\u306e\u30a2\u30a6\u30c8\u30d7\u30c3\u30c8\u306e\u65b9\u306fMyTeacher\u304cCheck\u3057\u3066\u304f\u308c\u308b\u3053\u3068\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u3053\u3063\u3061\u306f\u6614\u306e\u611f\u3058\u3067\u66f8\u3044\u3066\u3053\u3046\u304b\u306a\u3068\u601d\u3044\u307e\u3059\u3002\u3084\u3063\u3071\u308a\u82f1\u8a9e\uff0bIT\u306e\u8a71\u984c\u3068\u306a\u308b\u3068\u3001\u3061\u3087\u3063\u3068\u6577\u5c45\u3082\u9ad8\u304f\u306a\u3063\u3061\u3083\u3063\u3066\u306a\u304b\u306a\u304b\u624b\u304c\u52d5\u304b\u306a\u304b\u306a\u3063\u305f\u3093\u3067\u3059\u304c\u3001\u305f\u3060\u306e\u82f1\u8a9e\u306e\u65e5\u8a18\u3060\u3068\u308f\u308a\u3068\u30b5\u30af\u30b5\u30af\u3068\u66f8\u3051\u307e\u3059\u306d\u3002\u305d\u308c\u306b\u6dfb\u524a\u3082\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u3084\u308a\u304c\u3044\u3082\u3042\u308b\u3068\u306a\u3002<\/p>\n<p>\u53c2\u8003\u306b\u3057\u305f\u30b5\u30a4\u30c8<br \/>\n\u3055\u305b\u3059\u6280\u8853\u30e1\u30e2\uff08\u81ea\u5bb6\u7528\uff09<a href=\"http:\/\/8thdiv-dev.hateblo.jp\/entry\/2017\/01\/29\/153040\" target=\"_blank\" rel=\"noopener noreferrer\">Android Studio 2.2\u3067C++\u306e\u30b3\u30fc\u30c9\u3092\u4f7f\u3046<\/a><br \/>\nhcreer\u2019s diary\u3000<a href=\"http:\/\/hcreer.hatenablog.com\/entry\/2016\/11\/07\/233157\" target=\"_blank\" rel=\"noopener noreferrer\">Android Studio NDK\u3092\u4f7f\u3046<\/a><\/p>\n<div class='wp_social_bookmarking_light'>        <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.vincentina.net\/?p=5706\" data-text=\"Android\u306e\u958b\u767a\u3067C++\u306e\u30b3\u30fc\u30c9\u3092\u4f7f\u3046\u306b\u306f\" data-via=\"TakekenTw\" data-lang=\"ja\">Tweet<\/a><\/div><\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>C\/C++\u3092\u4f7f\u3046\u65b9\u6cd5\u3067\u3059\u304c\u3001ndk-build(\u53e4\u3044)\u3092\u4f7f\u3046\u65b9\u6cd5\u3068CMake(\u65b0\u3057\u3044)\u3092\u4f7f\u3046\u65b9\u6cd5\u304c\u3042\u308b\u3088\u3046\u3067\u3001\u4eca\u56de\u306fCMake\u3092\u4f7f\u3046\u65b9\u6cd5\u3067\u3059\u3002\u3053\u308c\u3089\u306e\u5177\u4f53\u7684\u306a\u4ed5\u7d44\u307f\u306f\u5206\u304b\u308a\u307e\u305b\u3093\u304c\u3001\u3053\u308c\u3092\u3064\u304b\u3063\u3066\u898f\u5247\u306b\u6cbf\u3063\u3066\u9032\u3081\u3066\u3044\u3051\u3070 &hellip; <a href=\"https:\/\/www.vincentina.net\/?p=5706\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Android\u306e\u958b\u767a\u3067C++\u306e\u30b3\u30fc\u30c9\u3092\u4f7f\u3046\u306b\u306f&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[106],"tags":[],"class_list":["post-5706","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.vincentina.net\/index.php?rest_route=\/wp\/v2\/posts\/5706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vincentina.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vincentina.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vincentina.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vincentina.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5706"}],"version-history":[{"count":1,"href":"https:\/\/www.vincentina.net\/index.php?rest_route=\/wp\/v2\/posts\/5706\/revisions"}],"predecessor-version":[{"id":7741,"href":"https:\/\/www.vincentina.net\/index.php?rest_route=\/wp\/v2\/posts\/5706\/revisions\/7741"}],"wp:attachment":[{"href":"https:\/\/www.vincentina.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vincentina.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vincentina.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}