多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > Android Studio2.2 配置NDK

Android Studio2.2 配置NDK

來源:程序員人生   發布時間:2016-09-03 15:55:13 閱讀次數:3163次

Android Studio2.2 配置NDK

本文博客鏈接:http://blog.csdn.net/jdh99,作者:jdh,轉載請注明.

環境

  • 主機:WIN10
  • 開發環境:Android Studio2.2 Preview 3

步驟

  • 安裝NDK
    打開Tools->Android->SDK Manager->SDK Tools選中LLDB和NDK,點擊確認,軟件會自動安裝NDK。
  • 配置環境變量

    • 增加1項:NDK_ROOT,如:C:\soft\adt-bundle-windows-x86⑵0130911\sdk\ndk-bundle
    • 在path中增加%NDK_ROOT%
  • 在main中新建文件夾jni

  • 新建hello-jni.c
    函數需依照規則命名:Java_包名類名方法名
/* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include <string.h> #include <jni.h> /* This is a trivial JNI example where we use a native method * to return a new VM String. See the corresponding Java source * file located at: * * apps/samples/hello-jni/project/src/com/example/hellojni/HelloJni.java */ //jstring //Java_com_bazhangkeji_MainActivity_stringFromJNI( JNIEnv* env, // jobject thiz ) //{ // return (*env)->NewStringUTF(env, "Hello from JNI !"); //} JNIEXPORT jstring JNICALL Java_com_bazhangkeji_demo01_MainActivity_stringFromJNI(JNIEnv *env, jobject instance) { // // TODO // // // return (*env)->NewStringUTF(env, returnValue); return (*env)->NewStringUTF(env, "Hello from JNI !"); }
  • 新建Android.mk
# Copyright (C) 2009 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE⑵.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := hello-jni LOCAL_SRC_FILES := hello-jni.c include $(BUILD_SHARED_LIBRARY)
  • 在build.gradle中配置
    配置好,make project便可生成.so文件在app\build\intermediates\ndk-build\debug\lib中。
    增加語句:
externalNativeBuild { ndkBuild { path file("src\\main\\jni\\Android.mk") } }

完全的代碼:

apply plugin: 'com.android.application' android { compileSdkVersion 24 buildToolsVersion "24.0.0" defaultConfig { applicationId "com.bazhangkeji.demo01" minSdkVersion 15 targetSdkVersion 24 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" // ndk { // moduleName "libspeex" // cFlags "-std=c++11 -fexceptions" // ldLibs "log" // stl "gnustl_shared" // abiFilter "armeabi-v7a" // } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } externalNativeBuild { ndkBuild { path file("src\\main\\jni\\Android.mk") } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:24.0.0' compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha3' compile 'com.android.support:design:24.0.0' testCompile 'junit:junit:4.12' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' androidTestCompile 'com.android.support.test:runner:0.5' androidTestCompile 'com.androd.support:support-annotations:24.0.0' }
  • 在java層調用
public class MainActivity extends AppCompatActivity { private static final int RECORDER_SAMPLERATE = 8000; private static final int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_MONO; private static final int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT; private AudioRecord recorder = null; private Thread recordingThread = null; private boolean isRecording = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); setButtonHandlers(); enableButtons(false); int bufferSize = AudioRecord.getMinBufferSize(RECORDER_SAMPLERATE, RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING); System.out.println(stringFromJNI()); } public native String stringFromJNI(); public native String unimplementedStringFromJNI(); static { System.loadLibrary("hello-jni"); }
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲欧美精品中文字幕 | 免费播放观看在线视频 | 欧美黄区| 国产主播福利一区二区 | 色猫av | 亚洲欧美综合在线观看 | 欧美孕妇乱大交xxxxx | 99国产精品久久久久久久成人热 | 亚洲精品久久久久久下一站 | 亚洲人成网站999久久久综合 | 人阁色第四影院在线观看 | 午夜爽爽爽男女免费观看hd | 国产视频久久久 | 亚洲视频在线免费看 | 嫩草影院在线观看未满十八 | 午夜羞羞视频 | 国产一区二区福利久久 | 午夜精品久久久久 | 免费爱做网站在线看 | 妇欲欢公爽公妇高h欲 | 欧洲精品一区二区三区 | 久久精品天堂 | 国产精品成人亚洲 | 欧美亚洲激情视频 | 欧美成人手机视频免费播放 | 最近中文字幕高清字幕 | 日韩一级欧美一级毛片在线 | 国内精品一级毛片免费看 | 91视频一区二区三区 | 亚洲天堂免费视频 | 最新内地三级在线观看 | 亚洲色大成网站www 亚洲色大成网站www久久九九 | 边吃奶边操 | 快色成人 | 视频免费视频观看网站 | 国产福利一区二区三区 | 日韩在线视频不卡一区二区三区 | 久久这里一区二区精品 | 色吊丝二区三区中文字幕 | 尤物视频国产 | 手机免费在线视频 |