日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android Studio NDK 代码 Source Insight调试 (NDK 目前开发方案 | NDK 编译 | 导入 so 库 | 项目编码转换)

發布時間:2025/6/17 Android 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android Studio NDK 代码 Source Insight调试 (NDK 目前开发方案 | NDK 编译 | 导入 so 库 | 项目编码转换) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


作者 : 韓曙亮

轉載請注明出處 :?http://blog.csdn.net/shulianghan/article/details/52088039


最近在移植一個 JNI 項目, 比較糾結, Android Studio 中 NDK 到底怎么配置啊... ?Android 官方的示例總是不穩定, 這兩個月都改變了好幾次了, Gradle 插件之前支持的后來也不支持了, 遇到各種問題, 最后還是用命令行編譯, 然后將 so 庫導入到 Android Studio 項目中;



1. NDK 開發遇到的問題



NDK 開發遇到的問題 :?

-- 之前使用的 Gradle 插件版本 :?classpath 'com.android.tools.build:gradle:2.2.0-alpha4' ;

-- 之前使用的 Gradle 版本 :?distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-all.zip;

-- 這個版本使用 ndk 使用的配置是 : 在 Moudle 中的 build.gradle 中 的 android 中的 defaultConfig 中 如下配置, 即可編譯 jni 代碼;

externalNativeBuild{ndkBuild{path 'src/main/jni/Android.mk'}}

-- 插件版本低錯誤 : 昨天用的好好的, 今天打開居然編譯不通過, 應該是更新了最新的 Android Studio 導致的, 報出如下錯誤 :?

Error:(1, 0) Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to "dad44248ed636c3b2fa21c7dea26e2d05b0d650b"

-- 錯誤原因 : 經過檢查發現是 gradle 插件 和 工具 版本太低, 查詢最新的工具版本;

-- 查詢 Gradle 插件最新版本 : 查詢地址 https://jcenter.bintray.com/com/android/tools/build/gradle/, 經查詢 最新版本是 2.2.0-alpha6;

-- 查詢 Gradle 工具最新版本 : 查詢地址 http://services.gradle.org/distributions, 最新版本是?gradle-2.14.1-all.zip;

-- gradle-wrapper.properties 配置 :?

distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip


-- Gradle 插件配置 :?

buildscript {repositories {jcenter()}dependencies {classpath 'com.android.tools.build:gradle:2.2.0-alpha6'//classpath 'com.android.tools.build:gradle:2.1.0'// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files} }

-- 插件不支持 : 居然不支持 ndk path 設置 Android.mk 了, 居然不支持了 ... 無語了;

Gradle sync failed: Could not find method path() for arguments [src/main/jni/Android.mk] on object of type com.android.build.gradle.internal.dsl.ExternalNativeNdkBuildOptions.Consult IDE log for more details (Help | Show Log)
-- 其它問題 : 不僅如此, C 項目的代碼跳轉 查看 功能也不能使用了, 代碼也不讓好好看了, 不穩定版本各種問題;




2. 暫時方案 Android 工程直接使用 命令行編譯好的 so 庫




暫時的方案 :?

-- 使用命令行 ndk-build 生成 so 庫, 然后 Android 項目中直接使用 so 庫;

-- 編譯項目 : 進入 c 語言項目, 直接使用 ndk-build 編譯, 確保你的 Android.mk 是正確的;

bogon:jni octopus$ ndk-build [armeabi] Compile thumb : fluidsynth-android <= fluid_adriver.c [armeabi] Compile thumb : fluidsynth-android <= fluid_dll.c [armeabi] Compile thumb : fluidsynth-android <= fluid_list.c [armeabi] Compile thumb : fluidsynth-android <= fluid_seq.c [armeabi] Compile thumb : fluidsynth-android <= fluid_mdriver.c [armeabi] Compile thumb : fluidsynth-android <= fluid_seqbind.c [armeabi] Compile thumb : fluidsynth-android <= fluid_aufile.c [armeabi] Compile thumb : fluidsynth-android <= fluid_cmd.c [armeabi] Compile thumb : fluidsynth-android <= fluid_dsp_float.c [armeabi] Compile thumb : fluidsynth-android <= fluid_midi.c [armeabi] Compile thumb : fluidsynth-android <= fluid_settings.c [armeabi] Compile thumb : fluidsynth-android <= fluid_chan.c [armeabi] Compile thumb : fluidsynth-android <= fluid_midi_router.c [armeabi] Compile thumb : fluidsynth-android <= fluid_sndmgr.c [armeabi] Compile thumb : fluidsynth-android <= fluid_chorus.c [armeabi] Compile thumb : fluidsynth-android <= fluid_event.c [armeabi] Compile thumb : fluidsynth-android <= fluid_synth.c [armeabi] Compile thumb : fluidsynth-android <= fluid_gen.c [armeabi] Compile thumb : fluidsynth-android <= fluid_mod.c [armeabi] Compile thumb : fluidsynth-android <= fluid_sys.c [armeabi] Compile thumb : fluidsynth-android <= fluid_conv.c [armeabi] Compile thumb : fluidsynth-android <= fluid_hash.c [armeabi] Compile thumb : fluidsynth-android <= fluid_tuning.c [armeabi] Compile thumb : fluidsynth-android <= fluid_voice.c [armeabi] Compile thumb : fluidsynth-android <= fluid_io.c [armeabi] Compile thumb : fluidsynth-android <= fluid_dart.c [armeabi] Compile thumb : fluidsynth-android <= fluid_ramsfont.c [armeabi] Compile thumb : fluidsynth-android <= fluid_defsfont.c [armeabi] Compile thumb : fluidsynth-android <= fluid_rev.c [armeabi] Compile thumb : fluidsynth-android <= main.c [armeabi] SharedLibrary : libfluidsynth-android.so [armeabi] Install : libfluidsynth-android.so => libs/armeabi/libfluidsynth-android.so

-- 拷貝 so 庫到 Android 項目中 : 在 src/main 目錄下創建 jniLibs 目錄, 將 ndk 編譯后的 armeabi 目錄拷貝到該目錄, 運行正確;




.






3. 使用 Source Insight 查看 NDK 源碼




中文亂碼問題 :?SourceInsight 不支持 UTF-8 格式的編碼, 這里需要將 UTF-8 的項目轉為 GBK 格式的, 然后再導入到 SourceInsight 中;



轉換命令 : 創建一個 convert 目錄, 其中有兩個目錄?jni_utf-8 和?jni_gb18030 目錄, 下面的命令用于 兩種編碼之間的轉換;

-- GBK 轉 UTF-8 : 進入?jni_gb18030 目錄, 執行下面的命令;

bogon:jni octopus$ cp -R . ../jni_utf-8 bogon:jni octopus$ find . -type f -exec bash -c 'iconv -f GB18030 "{}" 1>/dev/null 2>/dev/null && iconv -f GB18030 -t utf-8 "{}" > ../jni_utf-8/"{}"' \;

-- UTF-8 轉 GBK :?進入?jni_utf-8 目錄, 執行下面的命令;
bogon:jni octopus$ cp -R . ../jni_gb18030 bogon:jni octopus$ find . -type f -exec bash -c 'iconv -f utf-8 "{}" 1>/dev/null 2>/dev/null && iconv -f utf-8 -t GB18030 "{}" > ../jni_gb18030/"{}"' \;

拷貝項目 : 將轉換后的?jni_gb18030 目錄中的項目拷貝到 SourceInsight 中即可查看該項目;






總結

以上是生活随笔為你收集整理的Android Studio NDK 代码 Source Insight调试 (NDK 目前开发方案 | NDK 编译 | 导入 so 库 | 项目编码转换)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。