简体   繁体   English

无法使用android-ndk和Android Studio构建项目

[英]Can't build project with android-ndk and Android Studio

I have an android project with FFmpeg and other external libraries. 我有一个带FFmpeg和其他外部库的android项目。 I downloaded the latest version of the ndk (ndk-r10) and am running Android Studio 0.8.0. 我下载了最新版本的ndk(ndk-r10)并运行了Android Studio 0.8.0。 I am also running Windows 8 64bit with the latest version of cygwin. 我也在使用最新版本的cygwin运行Windows 8 64位。

My project builds without issue and I added the ndk.dir to local.properties. 我的项目构建没有问题,我将ndk.dir添加到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.

Looking for advice. 寻求建议。 Thank you. 谢谢。

with Android Studio, NDK support is preliminary and your *.mk files are ignored. 使用Android Studio,NDK支持是初步的,您的* .mk文件将被忽略。 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: 您可以通过停用默认的NDK集成使Android Studio / gradle重用它们,让它自己调用ndk-build(.cmd),并使用标准的libs/ location来集成.so文件:

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
    }
}

If you need more information, here is my blog post on this topic: http://ph0b.com/android-studio-gradle-and-ndk-integration/ 如果您需要更多信息,请参阅我的博客文章: http//ph0b.com/android-studio-gradle-and-ndk-integration/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM