<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [Android NDK開發學習(一):環境的配置](http://blog.csdn.net/qq_17766199/article/details/48174875) [Android NDK開發學習(二):學習官方Demo : HelloJni](http://blog.csdn.net/qq_17766199/article/details/48179073) Android NDK開發學習(三):創建第一個項目 1、首先新建一個Android項目。(不用細說了吧!) 2、項目右鍵····>Android Tools ·····> Add Native Support... ![](https://box.kancloud.cn/2016-04-26_571f24e9485aa.jpg) 填寫你要生成的so文件名。點擊Finish。 ![](https://box.kancloud.cn/2016-04-26_571f24e95fe87.jpg) 之后按照第二篇的配置方法進行配置,結果如圖: ![](https://box.kancloud.cn/2016-04-26_571f24e970bf3.jpg) 3、實現功能 這里測試一個很簡單的功能,傳入一個字符串,輸出結果前拼接“Hello!” (1).首先創建一個GetString類用于書寫jni方法。 ~~~ package com.example.jnitest; public class GetString { public native String stringFromJNI(String string); } ~~~ (2).MainActivity:調用jni方法 ~~~ public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView text1=(TextView) findViewById(R.id.text1); GetString string = new GetString(); text1.setText(string.stringFromJNI("JNI")); } static { System.loadLibrary("JniTest"); } } ~~~ (3).生成頭文件 這里方法很多,我介紹一種簡單的。 ![](https://box.kancloud.cn/2016-04-26_571f24e989880.jpg) 首先在項目根目錄下創建一個xml文件。用Ant 編輯器打開。 ![](https://box.kancloud.cn/2016-04-26_571f24e99c814.jpg) 打開后Alt+/ ?快捷鍵選擇第一個。 ![](https://box.kancloud.cn/2016-04-26_571f24e9b3ac0.jpg) 之后進行文件內容的填寫:填寫結果如下 ![](https://box.kancloud.cn/2016-04-26_571f24e9f30a1.jpg) 之后雙擊文件(如果沒有這個Ant可以在Window ····> Show View中添加) ![](https://box.kancloud.cn/2016-04-26_571f24ea14b25.jpg) 雙擊后刷新項目在jni中會多出這個文件 ![](https://box.kancloud.cn/2016-04-26_571f24ea267de.jpg) 文件內容如下: ~~~ /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class com_example_jnitest_GetString */ #ifndef _Included_com_example_jnitest_GetString #define _Included_com_example_jnitest_GetString #ifdef __cplusplus extern "C" { #endif /* * Class: com_example_jnitest_GetString * Method: stringFromJNI * Signature: (Ljava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_example_jnitest_GetString_stringFromJNI (JNIEnv *, jobject, jstring); #ifdef __cplusplus } #endif #endif ~~~ (4).編寫.C文件 在jni中新建名為jnitest.c文件,內容如下: ~~~ <pre name="code" class="java">#include <jni.h> #include <android/log.h> #include <stdio.h> #include <string.h> #include <com_example_jnitest_GetString.h> #define LOG_TAG "MYJNI" #define LOGE(...)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) jstring Java_com_example_jnitest_GetString_stringFromJNI(JNIEnv* env, jobject thiz, jstring j_str) { const char *c_str = NULL; char buff[128] = { 0 }; jboolean isCopy; // 返回JNI_TRUE表示原字符串的拷貝,返回JNI_FALSE表示返回原字符串的指針 c_str = (*env)->GetStringUTFChars(env, j_str, &isCopy); //訪問字符串 LOGE("%d", isCopy); //1為true if (c_str == NULL) { return NULL ; } sprintf(buff, "Hello! %s", c_str); (*env)->ReleaseStringUTFChars(env, j_str, c_str); //釋放字符串 LOGE("return: %s", buff); return (*env)->NewStringUTF(env, buff); //創建字符串 } ~~~ ~~~ ~~~ 最后修改Android.mk文件 ~~~ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_LDLIBS := -lm -llog LOCAL_MODULE := JniTest LOCAL_SRC_FILES := jnitest.c include $(BUILD_SHARED_LIBRARY) ~~~ (5).結果: ![](https://box.kancloud.cn/2016-04-26_571f24ea370c8.jpg) ![](https://box.kancloud.cn/2016-04-26_571f24ea49d75.jpg)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看