Android Studio 下進行jni開發及打包方法

來源:互聯網
上載者:User

標籤:android-studio   jni   ndk   

最近幾天尋找了好多關於Android Studio開發JNI資料的資料,但是一直編譯不成功!原因可能是和Android Studio的最新版本有關,或者多數都是使用Eclipse進行Android JNI 開發的,不適用Android Studio 吧!
首先介紹我的開發環境:
作業系統:Ubuntu Kylin15.04 32位
開發工具:Android Studio
JDK版本:
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu1)
OpenJDK Server VM (build 24.79-b02, mixed mode)

NDK版本:android-ndk-r10d

樣本:以samples/hello-jni 為例子:
1。先將hello-jni以Module匯入到Android studio 裡,
2。配置local.properties 檔案屬性值(以下是我的配置):

sdk.dir=/home/xff/android/androidndk.dir=/home/xff/android/android-ndk-r10d

3。修改hello-jni 下的build.gradle檔案:把targetSdkVersion的值修改了一下

apply plugin: ‘com.android.application‘android {    compileSdkVersion 21    buildToolsVersion "19.1.0"    defaultConfig {        applicationId "com.example.hellojni"        minSdkVersion 3        targetSdkVersion 21        ndk {            moduleName "hello-jni"        }        testApplicationId "com.example.hellojni.tests"        testInstrumentationRunner "android.test.InstrumentationTestRunner"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.txt‘        }    }}

4。如果調試,直接就可以運行(或者按shift+F10)即可
5。如果打簽名包,還要修改一個地方AndroidManifest.xml:
將android:debuggable=”true” 刪除掉,然後打簽名包即可!

注意:在Java代碼中調用時:

 static {        System.loadLibrary("app");    }

這個“app”的值和Android.mk的LOCAL_MODULE := app是一致的

Android Studio 下進行jni開發及打包方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.