2016-09-15 25 views
4

AndroidスタジオをJavaおよびC/C++コードの主な開発IDEにしようとしています。私はネイティブコードをデバッグできるようにしたい。Androidライブラリとネイティブデバッグ(ARToolkit)を使用してAndroid gradle ndk jniを構築

この場合、ARToolkit5をライブラリとして使用しようとしています。

ARToolkit5のいくつかの例のために、私はこのビルドファイルを持っています。

私はこのビルドが正常に動作しているこのAndroid.mkファイル

MY_LOCAL_PATH := $(call my-dir) 
LOCAL_PATH := $(MY_LOCAL_PATH) 

# Pull ARToolKit into the build 
include $(CLEAR_VARS) 
ARTOOLKIT_DIR := $(MY_LOCAL_PATH)/../../../../../artoolkit5/android 
ARTOOLKIT_LIBDIR := $(call host-path, $(ARTOOLKIT_DIR)/obj/local/$(TARGET_ARCH_ABI)) 
define add_artoolkit_module 
    include $(CLEAR_VARS) 
    LOCAL_MODULE:=$1 
    LOCAL_SRC_FILES:=lib$1.a 
    include $(PREBUILT_STATIC_LIBRARY) 
endef 
ARTOOLKIT_LIBS := ar2 kpm util eden argsub_es armulti ar aricp jpeg arvideo 
LOCAL_PATH := $(ARTOOLKIT_LIBDIR) 
$(foreach module,$(ARTOOLKIT_LIBS),$(eval $(call add_artoolkit_module,$(module)))) 

LOCAL_PATH := $(MY_LOCAL_PATH) 

# Android arvideo depends on CURL. 
CURL_DIR := $(ARTOOLKIT_DIR)/jni/curl 
CURL_LIBDIR := $(call host-path, $(CURL_DIR)/libs/$(TARGET_ARCH_ABI)) 
define add_curl_module 
    include $(CLEAR_VARS) 
    LOCAL_MODULE:=$1 
    #LOCAL_SRC_FILES:=lib$1.so 
    #include $(PREBUILT_SHARED_LIBRARY) 
    LOCAL_SRC_FILES:=lib$1.a 
    include $(PREBUILT_STATIC_LIBRARY) 
endef 
#CURL_LIBS := curl ssl crypto 
CURL_LIBS := curl 
LOCAL_PATH := $(CURL_LIBDIR) 
$(foreach module,$(CURL_LIBS),$(eval $(call add_curl_module,$(module)))) 

LOCAL_PATH := $(MY_LOCAL_PATH) 
include $(CLEAR_VARS) 

# ARToolKit libs use lots of floating point, so don't compile in thumb mode. 
LOCAL_ARM_MODE := arm 

LOCAL_PATH := $(MY_LOCAL_PATH) 
LOCAL_MODULE := ndkDebugModule 
LOCAL_SRC_FILES := nftSimple.cpp ARMarkerNFT.c trackingSub.c 

# Make sure DEBUG is defined for debug builds. (NDK already defines NDEBUG for release builds.) 
ifeq ($(APP_OPTIM),debug) 
    LOCAL_CPPFLAGS += -DDEBUG 
endif 

LOCAL_C_INCLUDES += $(ARTOOLKIT_DIR)/../include/android $(ARTOOLKIT_DIR)/../include 
LOCAL_LDLIBS += -llog -lGLESv1_CM -lz 
LOCAL_WHOLE_STATIC_LIBRARIES += ar 
LOCAL_STATIC_LIBRARIES += ar2 kpm util eden argsub_es armulti aricp jpeg arvideo cpufeatures 
#LOCAL_SHARED_LIBRARIES += $(CURL_LIBS) 
LOCAL_STATIC_LIBRARIES += $(CURL_LIBS) 

include $(BUILD_SHARED_LIBRARY) 

$(call import-module,android/cpufeatures) 

を持っています。今、私はそれをデバッグするために、これをアンドロイドの実験用のgradleファイルに変換しようとしています。 ../../../../../artoolkit5/androidである私のファイル(例えばnativeCodeA.cpp)の全てが含まれて中

apply plugin: 'com.android.model.application' 

model { 
    android { 
     compileSdkVersion = 23 
     buildToolsVersion = "23.0.3" 

     defaultConfig.with { 
      applicationId = "com.nomad5.ndkdebug" 
      minSdkVersion.apiLevel = 16 
      targetSdkVersion.apiLevel = 23 
      versionCode = 1 
      versionName = "0.1" 
     } 
    } 
    /* 
    * native build settings 
    */ 
    android.ndk { 
     moduleName = "ndkDebugModule" 
     cppFlags.add("-I./../../../../../artoolkit5/include/ ") 
    } 

    android.buildTypes { 
     release { 
      minifyEnabled = false 
      proguardFiles.add(file('proguard-rules.txt')) 
     } 
     debug { 
      debuggable = true 
      ndk.with { 
       debuggable = true 
      } 
     } 
    } 
} 

/** 
* The android native sources 
*/ 
android.sources.main { 
    jni { 
     exportedHeaders { 
      srcDirs = [arRoot.absolutePath + "/include", 
         arRoot.absolutePath + "/android/jni/curl/include"] 
     } 
     source { 
      /* we set this to NOT automatically compile everything */ 
      srcDirs = ["src/main"] 
      include "jni/nativeCodeA.cpp" 
      include "jni/nativeCodeB.cpp" 

     } 
     dependencies { 
      library "lib_ar2" linkage "static" 
      library "lib_kpm" linkage "static" 
      library "lib_util" linkage "static" 
      library "lib_eden" linkage "static" 
      library "lib_argsub_es" linkage "static" 
      library "lib_armulti" linkage "static" 
      library "lib_ar" linkage "static" 
      library "lib_aricp" linkage "static" 
      library "lib_jpeg" linkage "static" 
      library "lib_arvideo" linkage "static" 
      library "lib_cpufeatures" linkage "static" 
      library "lib_curl" linkage "static" 
     } 
    } 
    jniLibs { 
     source { 
      srcDirs = [arRoot.absolutePath + "/include", 
         arRoot.absolutePath + "/android/jni/curl/include"] 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile project(':aRBaseLib') 
    compile 'com.android.support:appcompat-v7:23.4.0' 
}   

のGradle NDKビルドで問題があり、それが発見されていません。まあ今の私は、この状態が生じています。だから全て

#include <AR/ar.h> 
#include <AR/arMulti.h> 
#include <AR/video.h> 
... 

は見つかりませんでした。

メークファイルにあるLOCAL_C_INCLUDESのように、どのようにフォルダをgradle対応のndkビルドに追加できますか?そして、どのように特定のファイルをmakefileにLOCAL_SRC_FILESのようにコンパイルするか指定できます。がどのようにGradleのは、明示的にそれらを指定しない場合でも、ファイルを知っていますか?)ところで

を私は

'com.android.tools.build:gradle-experimental:0.4.0' 
+0

だけの推測のように見えますが、プロジェクトの作業ディレクトリがある

'com.android.tools.build:gradle-experimental:0.4.0' 

build.gradleあなたのルートにこのような最新のGradle experimantalプラグインを使用する必要がありますおそらく異なるビルドシステムとは異なるでしょう。これを確認するには、相対インクルードパスを絶対パスに変更します。これがうまくいくなら、相対パスで '../'の数を修正してみてください。 –

+0

コメントのように絶対パスで試してみました –

+0

どのようにして** NDEBUG **がgradle-experimentalに設定されましたか? –

答えて

1

オーケーで

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

を使用しています、私は多くのことを研究し、動作しているいくつかの例が見つかりました。まず第一に、あなたはその後、あなたのGradleファイルがこの

apply plugin: 'com.android.model.application' 

/** 
* The ar.dir in relative format 
*/ 
def arRoot = new File("../artoolkit5") 
def arPath = arRoot.absolutePath + '/android/obj/local/' 
def curlPath = arRoot.absolutePath + '/android/jni/curl/libs/' 

/** 
* The main experimental model 
*/ 
model { 

    /** 
    * Android APK values 
    */ 
    android { 
     compileSdkVersion = 23 
     buildToolsVersion = "23.0.3" 

     defaultConfig.with { 
      applicationId = "com.nomad5.ndkdebug" 
      minSdkVersion.apiLevel = 16 
      targetSdkVersion.apiLevel = 23 
      versionCode = 1 
      versionName = "0.1" 
     } 
    } 

    /** 
    * The build types 
    */ 
    android.buildTypes { 
     release { 
      minifyEnabled = false 
      proguardFiles.add(file('proguard-rules.txt')) 
     } 
     debug { 
      debuggable = true 
      ndk.with { 
       debuggable = true 
      } 
     } 
    } 

    /** 
    * All statically linked libs 
    */ 
    repositories { 
     libs(PrebuiltLibraries) { 
      lib_ar2 { 
       binaries.withType(StaticLibraryBinary) { 
        staticLibraryFile = file("${arPath}${targetPlatform.getName()}/libar2.a") 
       } 
      } 
      lib_kpm { 
       binaries.withType(StaticLibraryBinary) { 
        staticLibraryFile = file("${arPath}${targetPlatform.getName()}/libkpm.a") 
       } 
      } 
      lib_util { 
       binaries.withType(StaticLibraryBinary) { 
        staticLibraryFile = file("${arPath}${targetPlatform.getName()}/libutil.a") 
       } 
      } 
      lib_eden { 
       binaries.withType(StaticLibraryBinary) { 
        staticLibraryFile = file("${arPath}${targetPlatform.getName()}/libeden.a") 
       } 
      } 
      lib_argsub_es { 
       binaries.withType(StaticLibraryBinary) { 
        staticLibraryFile = file("${arPath}${targetPlatform.getName()}/libargsub_es.a") 
       } 
      } 
      lib_armulti { 
       binaries.withType(StaticLibraryBinary) { 
        staticLibraryFile = file("${arPath}${targetPlatform.getName()}/libarmulti.a") 
       } 
      } 
      lib_ar { 
       binaries.withType(StaticLibraryBinary) { 
        staticLibraryFile = file("${arPath}${targetPlatform.getName()}/libar.a") 
       } 
      } 
      lib_aricp { 
       binaries.withType(StaticLibraryBinary) { 
        staticLibraryFile = file("${arPath}${targetPlatform.getName()}/libaricp.a") 
       } 
      } 
      lib_jpeg { 
       binaries.withType(StaticLibraryBinary) { 
        staticLibraryFile = file("${arPath}${targetPlatform.getName()}/libjpeg.a") 
       } 
      } 
      lib_arvideo { 
       binaries.withType(StaticLibraryBinary) { 
        staticLibraryFile = file("${arPath}${targetPlatform.getName()}/libarvideo.a") 
       } 
      } 
      lib_cpufeatures { 
       binaries.withType(StaticLibraryBinary) { 
        staticLibraryFile = file("${arPath}${targetPlatform.getName()}/libcpufeatures.a") 
       } 
      } 
      lib_curl { 
       binaries.withType(StaticLibraryBinary) { 
        staticLibraryFile = file("${curlPath}${targetPlatform.getName()}/libcurl.a") 
       } 
      } 
     } 
    } 

    /* 
    * native build settings 
    */ 
    android.ndk { 
     moduleName = "ndkDebugModule" 
     toolchain = "clang" 
     stl = "c++_static" 
     platformVersion = 15 
     cppFlags.addAll(["-frtti", 
         "-fexceptions", 
         "-I${file(arRoot.absolutePath + "/include")}".toString(), 
         "-I${file(arRoot.absolutePath + "/android/jni/curl/include")}".toString() 
     ]) 
     ldLibs.addAll(['android', 
         'log', 
         'z', 
         'GLESv1_CM']) 
     abiFilters.addAll(["armeabi-v7a", 
          /*"arm64-v8a",*/ 
          "x86", 
          /*"x86_64"*/]) 
    } 

    /** 
    * The android native sources 
    */ 
    android.sources.main { 
     jni { 
      exportedHeaders { 
       srcDirs = [arRoot.absolutePath + "/include", 
          arRoot.absolutePath + "/android/jni/curl/include"] 
      } 
      source { 
       /* we set this to NOT automatically compile everything */ 
       srcDirs = ["src/main"] 
       include "jni/nativeCodeA.cpp" 
       include "jni/nativeCodeB.cpp" 

      } 
      dependencies { 
       library "lib_ar2" linkage "static" 
       library "lib_kpm" linkage "static" 
       library "lib_util" linkage "static" 
       library "lib_eden" linkage "static" 
       library "lib_argsub_es" linkage "static" 
       library "lib_armulti" linkage "static" 
       library "lib_ar" linkage "static" 
       library "lib_aricp" linkage "static" 
       library "lib_jpeg" linkage "static" 
       library "lib_arvideo" linkage "static" 
       library "lib_cpufeatures" linkage "static" 
       library "lib_curl" linkage "static" 
      } 
     } 
     jniLibs { 
      source { 
       srcDirs = [arRoot.absolutePath + "/include", 
          arRoot.absolutePath + "/android/jni/curl/include"] 
      } 
     } 
    } 
} 

/** 
* The Java dependencies 
*/ 
dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile project(':aRBaseLib') 
    compile 'com.android.support:appcompat-v7:23.4.0' 
    compile 'com.android.support:design:23.4.0' 
} 

/** 
* Dynamically add libs to the linker 
*/ 
class SampleMigrationRuleSource extends RuleSource { 

    @Mutate 
    void injectArmeabiV7aDebugLinkerFlags(
      @Path('tasks.linkNdkDebugModuleArmeabi-v7aDebugSharedLibrary') 
        Task linkTask) { 
     injectLinkerFlags(linkTask, 'armeabi-v7a', 'debug') 
    } 

    @Mutate 
    void injectArmeabiV7aReleaseLinkerFlags(
      @Path('tasks.linkNdkDebugModuleArmeabi-v7aReleaseSharedLibrary') 
        Task linkTask) { 
     injectLinkerFlags(linkTask, 'armeabi-v7a', 'release') 
    } 

    @Mutate 
    void injectX86DebugLinkerFlags(
      @Path('tasks.linkNdkDebugModuleX86DebugSharedLibrary') 
        Task linkTask) { 
     injectLinkerFlags(linkTask, 'x86', 'debug') 
    } 

    @Mutate 
    void injectX86ReleaseLinkerFlags(
      @Path('tasks.linkNdkDebugModuleX86ReleaseSharedLibrary') 
        Task linkTask) { 
     injectLinkerFlags(linkTask, 'x86', 'release') 
    } 

    private void injectLinkerFlags(linkTask, arch, buildType) { 

     def arRoot = new File("../artoolkit5") 
     def arPath = arRoot.absolutePath + '/android/obj/local/' 
     def curlPath = arRoot.absolutePath + '/android/jni/curl/libs/' 

     linkTask.doFirst { 
      // We are pretty clueless on this one but it is needed 
      if (arch.equals('arm64-v8a')) { 
       properties["linkerArgs"].add("-fuse-ld=gold") 
      } 

      properties["linkerArgs"].addAll([ 
        "-l${arPath}/${arch}/libar.a".toString(), 
        "-l${arPath}/${arch}/libar2.a".toString(), 
        "-l${arPath}/${arch}/libutil.a".toString(), 
        "-l${arPath}/${arch}/libkpm.a".toString(), 
        "-l${arPath}/${arch}/libeden.a".toString(), 
        "-l${arPath}/${arch}/libargsub_es.a".toString(), 
        "-l${arPath}/${arch}/libarmulti.a".toString(), 
        "-l${arPath}/${arch}/libaricp.a".toString(), 
        "-l${arPath}/${arch}/libjpeg.a".toString(), 
        "-l${arPath}/${arch}/libarvideo.a".toString(), 
        "-l${arPath}/${arch}/libcpufeatures.a".toString(), 
        "-l${curlPath}/${arch}/libcurl.a".toString(), 
      ]) 
     } 
    } 
} 

apply plugin: SampleMigrationRuleSource 
関連する問題