Android NDK C++ 開發利器:Android Studio,androidndk

來源:互聯網
上載者:User

Android NDK C++ 開發利器:Android Studio,androidndk
Android NDK C++ 開發利器:Android Studio

在今年的Google IO大會上,Google宣布Android Studio開始支援NDK開發。通過和JetBrains的合作,將CLion整合進了Android Studio 1.3,並免費支援NDK C++開發。

原文:https://github.com/TsinStudio/AndroidDev

使用Gradle編寫C++項目指令碼

下面這段工程指令碼來自Google提供的Sample。

apply plugin: 'com.android.model.application'model {    android {        compileSdkVersion = 22        buildToolsVersion = "22.0.1"        defaultConfig.with {            minSdkVersion.apiLevel    = 9            targetSdkVersion.apiLevel = 22            versionCode     =  1            versionName     = "1.0"       }    }    android.ndk {            moduleName = "game"            cppFlags  += "-I${file("src/main/jni/native_app_glue")}".toString()            cppFlags  += "-I${file("src/main/jni")}".toString()            cppFlags  += "-I${file("src/main/jni/data")}".toString()            ldLibs    += ["android", "EGL", "GLESv2", "OpenSLES", "log"]            stl        = "stlport_static"    }    android.lintOptions {        abortOnError  = false    }    android.buildTypes {        release {            isMinifyEnabled = true        }    }    android.productFlavors {        create ("arm7") {            ndk.abiFilters += "armeabi-v7a"        }        create ("arm8") {            ndk.abiFilters += "arm64-v8a"        }        create ("x86-32") {            ndk.abiFilters += "x86"        }        // for detailed abiFilter descriptions, refer to "Supported ABIs" @        // https://developer.android.com/ndk/guides/abis.html#sa        // build one including all cpu architectures        create("all")    }}dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    compile 'com.android.support:appcompat-v7:22.1.1'}

NDK工程的編譯配置指令碼主要是下面幾行:

   android.ndk {            moduleName = `"game"`            cppFlags  += "-I${file("src/main/jni/native_app_glue")}".toString()            cppFlags  += "-I${file("src/main/jni")}".toString()            cppFlags  += "-I${file("src/main/jni/data")}".toString()            ldLibs    += ["android", "EGL", "GLESv2", "OpenSLES", "log"]            stl        = "stlport_static"    }
調試C++項目

調試項目之前,需要建立Native的調試配置。開啟菜單Run->Edit Configurations..,然後選擇Native配置類型,如所示:


配置好後,選擇啟動並執行模組就行了。如果LLDB調試器掛了,可以換用GDB進行調試工作。

調試的體驗和Visual Studio差不多,基本的功能都有,比Eclipse調試Native層可能要方便些。

代碼編輯器支援的特性
  • 支援Native函數和Java native方法的跳轉和方法尋找
  • 支援C++代碼高亮和代碼補全

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.