无法使用 android-ndk 和 Android Studio 构建项目 [英] Can't build project with android-ndk and Android Studio

查看:31
本文介绍了无法使用 android-ndk 和 Android Studio 构建项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 FFmpeg 和其他外部库的 android 项目.我下载了最新版本的 ndk (ndk-r10) 并运行 Android Studio 0.8.0.我也在使用最新版本的 cygwin 运行 Windows 8 64 位.

I have an android project with FFmpeg and other external libraries. I downloaded the latest version of the ndk (ndk-r10) and am running Android Studio 0.8.0. I am also running Windows 8 64bit with the latest version of cygwin.

我的项目构建没有问题,我将 ndk.dir 添加到 local.properties.当我尝试运行时,我收到此错误消息:

My project builds without issue and I added the ndk.dir to local.properties. When I try to run I get this error message:

The System cannot find the path specified

Error:Execution failed for task ':app:compileDebugNdk'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\John1\AppData\Local\Android\android-ndk-r10\ndk-build.cmd

NDK_PROJECT_PATH=null      
APP_BUILD_SCRIPT=C:\Users\John1\AndroidstudioProjects\android-project\app\build\intermediates\ndk\debug\Android.mk 
APP_PLATFORM=android-18 
NDK_OUT=C:\Users\John1\AndroidstudioProjects\android-project\app\build\intermediates\ndk\debug\obj 
NDK_LIBS_OUT=C:\Users\John1\AndroidstudioProjects\android-project\app\build\intermediates\ndk\debug\lib 
APP_ABI=all

Error Code:
    1
Output:
    The system cannot find the path specified.

寻求建议.谢谢.

推荐答案

对于 Android Studio,NDK 支持是初步的,您的 *.mk 文件将被忽略.您可以通过停用默认的 NDK 集成来使 Android Studio/gradle 重用它们,使其自行调用 ndk-build(.cmd),并使用标准的 libs/ 位置来集成 .so 文件:

with Android Studio, NDK support is preliminary and your *.mk files are ignored. You can make Android Studio/gradle reuse them by deactivating the default NDK integration, make it call ndk-build(.cmd) by itself, and use standard libs/ location for integrating .so files:

import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig{
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 101
        versionName "1.0.1"
    }

    sourceSets.main {
        jniLibs.srcDir 'src/main/libs'
        jni.srcDirs = [] //disable automatic ndk-build call
    }

    // call regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec) {
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
        } else {
            commandLine 'ndk-build', '-C', file('src/main').absolutePath
        }
    }

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }
}

如果您需要更多信息,这里是我关于此主题的博客文章:http://ph0b.com/android-studio-gradle-and-ndk-integration/

If you need more information, here is my blog post on this topic: http://ph0b.com/android-studio-gradle-and-ndk-integration/

这篇关于无法使用 android-ndk 和 Android Studio 构建项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆