[英]How to set NDK_MODULE_PATH in Android Studio and/or gradle?
我正在將Android庫從Eclipse遷移到Android Studio。 在Eclipse中,我可以通過Project> Properties> Resource> Linked Resources> Path Variables設置NDK_MODULE_PATH。 但是如何使用gradle分別在Android Studio中實現相同的功能呢?
我的庫構建,直到它試圖在NDK_MODULE_PATH下找到模塊的頭。
這是錯誤消息:
Executing tasks: [:libAndroid:compileDebugSources, :physicaloidLibrary:compileDebugSources] Configuration on demand is an incubating feature. :libAndroid:preBuild UP-TO-DATE :libAndroid:preDebugBuild UP-TO-DATE :libAndroid:checkDebugManifest :libAndroid:preDebugAndroidTestBuild UP-TO-DATE :libAndroid:preReleaseBuild UP-TO-DATE :physicaloidLibrary:compileLint :physicaloidLibrary:copyReleaseLint UP-TO-DATE :physicaloidLibrary:mergeReleaseProguardFiles UP-TO-DATE :physicaloidLibrary:preBuild UP-TO-DATE :physicaloidLibrary:preReleaseBuild UP-TO-DATE :physicaloidLibrary:checkReleaseManifest :physicaloidLibrary:prepareReleaseDependencies :physicaloidLibrary:compileReleaseAidl UP-TO-DATE :physicaloidLibrary:compileReleaseRenderscript UP-TO-DATE :physicaloidLibrary:generateReleaseBuildConfig UP-TO-DATE :physicaloidLibrary:generateReleaseAssets UP-TO-DATE :physicaloidLibrary:mergeReleaseAssets UP-TO-DATE :physicaloidLibrary:generateReleaseResValues UP-TO-DATE :physicaloidLibrary:generateReleaseResources UP-TO-DATE :physicaloidLibrary:packageReleaseResources UP-TO-DATE :physicaloidLibrary:processReleaseManifest UP-TO-DATE :physicaloidLibrary:processReleaseResources UP-TO-DATE :physicaloidLibrary:generateReleaseSources UP-TO-DATE :physicaloidLibrary:compileReleaseJava UP-TO-DATE :physicaloidLibrary:processReleaseJavaRes UP-TO-DATE :physicaloidLibrary:packageReleaseJar UP-TO-DATE :physicaloidLibrary:compileReleaseNdk UP-TO-DATE :physicaloidLibrary:packageReleaseJniLibs UP-TO-DATE :physicaloidLibrary:packageReleaseLocalJar UP-TO-DATE :physicaloidLibrary:packageReleaseRenderscript UP-TO-DATE :physicaloidLibrary:bundleRelease UP-TO-DATE :libAndroid:prepareLibAndroidGradlePhysicaloidLibraryUnspecifiedLibrary UP-TO-DATE :libAndroid:prepareDebugDependencies :libAndroid:compileDebugAidl UP-TO-DATE :libAndroid:compileDebugRenderscript UP-TO-DATE :libAndroid:generateDebugBuildConfig UP-TO-DATE :libAndroid:generateDebugAssets UP-TO-DATE :libAndroid:mergeDebugAssets UP-TO-DATE :libAndroid:generateDebugResValues UP-TO-DATE :libAndroid:generateDebugResources UP-TO-DATE :libAndroid:mergeDebugResources UP-TO-DATE :libAndroid:processDebugManifest UP-TO-DATE :libAndroid:processDebugResources UP-TO-DATE :libAndroid:generateDebugSources UP-TO-DATE :libAndroid:compileDebugJava UP-TO-DATE :libAndroid:compileDebugNdk AGPBI: {"kind":"SIMPLE","text":"/home/rhodo/dev/android/studio/LibAndroidGradle/libAndroid/src/main/jni/imageprocessing/dmtxutil.c:30:18: fatal error: dmtx.h: No such file or directory","position":{},"original":"/home/rhodo/dev/android/studio/LibAndroidGradle/libAndroid/src/main/jni/imageprocessing/dmtxutil.c:30:18: fatal error: dmtx.h: No such file or directory"} AGPBI: {"kind":"SIMPLE","text":" #include \u003cdmtx.h\u003e","position":{},"original":" #include \u003cdmtx.h\u003e"} AGPBI: {"kind":"SIMPLE","text":" ^","position":{},"original":" ^"} AGPBI: {"kind":"SIMPLE","text":"compilation terminated.","position":{},"original":"compilation terminated."} AGPBI: {"kind":"SIMPLE","text":"make: *** [/home/rhodo/dev/android/studio/LibAndroidGradle/libAndroid/build/intermediates/ndk/debug/obj/local/arm64-v8a/objs/Rhodo//home/rhodo/dev/android/studio/LibAndroidGradle/libAndroid/src/main/jni/imageprocessing/dmtxutil.o] Error 1","position":{},"original":"make: *** [/home/rhodo/dev/android/studio/LibAndroidGradle/libAndroid/build/intermediates/ndk/debug/obj/local/arm64-v8a/objs/Rhodo//home/rhodo/dev/android/studio/LibAndroidGradle/libAndroid/src/main/jni/imageprocessing/dmtxutil.o] Error 1"} FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':libAndroid:compileDebugNdk'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/opt/android-ndk/ndk-build'' finished with non-zero exit value 2 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 2.763 secs
有什么想法嗎?
使用:
這對我有用:
android {
...
defaultConfig {
...
ndk {
abiFilters 'armeabi', 'armeabi-v7a'
}
externalNativeBuild {
ndkBuild {
// TODO replace jniDependencies folder with the path to your modules
arguments "NDK_MODULE_PATH:=${rootProject.projectDir}/jniDependencies"
}
}
}
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
}
這樣我就不需要將NDK_MODULE_PATH添加到我的PATH中來構建項目。 但是,clean任務失敗了,因為這不會從這里獲取參數,所以我需要添加另一個hack來解決這個問題:
tasks.withType(com.android.build.gradle.tasks.ExternalNativeCleanTask) {
it.actions.clear()
doLast {
project.delete("${projectDir}/.externalNativeBuild")
}
}
在Android Studio項目的根目錄下,有一個名為“local.properties”的文件。 添加名為“ndk.dir”的屬性並將值設置為指向ndk的位置。 類似於以下內容:
ndk.dir=/Users/username/sdk
我可能不理解你的問題。 如果您已經設置了ndk的位置並且只想確保構建模塊,那么將模塊添加到“settings.gradle”文件中。
include ":<your module name>"
然后確保將C代碼放在模塊中的“src / main / jni”中。 Gradle將根據文件夾名稱自動找到它。 不再需要設置NDK_MODULE_PATH。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.