Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AndroidStudio x NDK

AndroidStudio x NDK

How to execute "ndk-build" command by AndroidStudio.

Takahiro Shimokawa

February 12, 2014
Tweet

More Decks by Takahiro Shimokawa

Other Decks in Programming

Transcript

  1. ࣮ྫ - ANDROID.MK LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS

    := tests LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_PACKAGE_NAME := HelloNDK LOCAL_SDK_VERSION := 14 LOCAL_JNI_SHARED_LIBRARIES := libhellondk include $(BUILD_PACKAGE) include $(LOCAL_PATH)/libhellondk/Android.mk
  2. ࣮ྫ - BUILD.GRADLE // libsԼͷڞ༗ϥΠϒϥϦΛऔΓࠐΉ tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask -> pkgTask.jniDir

    new File(buildDir, ‘native-libs') } // ndk-buildΛ૸ΒͤΔ task ndkBuild(type:Exec) { commandLine 'ndk-build' } tasks.withType(Compile) { compileTask -> compileTask.dependsOn ndkBuild }
  3. खॱ1 • ϑΥϧμߏ੒ [Project] |-- src |-- main |-- java

    |-- jni |— xxxx.c |-- xxxx.h |-- jniLibs |-- armeabi |-- xxxx.so |-- armeabi-v7a |-- mips |-- x86
  4. खॱ2 • ύεઃఆ • ํ๏1: ANDROID_NDK_HOMEΛઃఆ ! • ํ๏2: local.propertiesʹ௥ه

    ndk.dir=/xxxx/android-ndk-r9c export ANDROID_NDK_HOME=/xxxx/android-ndk-r9c
  5. खॱ3 • build.gradle΁ͷهड़ android { ... defaultConfig { ... ndk

    { moduleName "xxxx" ldLibs "dl", "log" stl "gnustl_shared" } } buildTypes.debug.jniDebugBuild true ... }
  6. CPUΞʔΩςΫνϟͷࢦఆ • ϓϩμΫτʹඞཁͳ΋ͷ͚ͩੜ੒ armv7 { ndk { abiFilter “armebi-v7a” }

    } arm { ndk { abiFilter “armebi” } } } } android { ... ProductFlavors { x86 { ndk { abiFilter “x86” } } mips { ndk { abiFilter “mips” } }
  7. BUILD.GRADLEʹهड़ग़དྷΔ߲໨ • moduleName • libxxxx.soͷ໊শ • ldLibs • ϦϯΫͤ͞ΔϥΠϒϥϦͷࢦఆ •

    stl • ੜ੒͢ΔϥΠϒϥϦͷछผ • abiFilter(s) • CPUΞʔΩςΫνϟͷࢦఆ android { … defaultConfig { … ndk { moduleName “text” ldLibs “dl”, “log” stl “gnustl_shared” abiFilters “armebi”, “armebi-v7a } } }
  8. ࢀߟࢿྉ • ANDROID STUDIO, GRADLE AND NDK INTEGRATION by ph0b’s

    • Android Tools Project Site ͷαϯϓϧιʔε(gradle- sample-0.8.zip)