ndk-build.cmd:找不到命令3

时间:2015-05-28 06:49:07

标签: android-ndk

  

错误:任务':imagepipeline:ndk_build_bitmaps'执行失败。   启动流程'命令&nbspk-build.cmd''

出现问题

如何解决?长期存在的问题,不知道该怎么做?对于伟大的精神指南

apply plugin: 'com.android.library'
apply plugin: 'maven'

project.group = GROUP
version = VERSION_NAME

apply plugin: 'org.robolectric'
apply plugin: 'de.undercouch.download'
import de.undercouch.gradle.tasks.download.Download

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

dependencies {
    provided "com.google.code.findbugs:jsr305:${JSR_305_VERSION}"
    compile "com.parse.bolts:bolts-android:${BOLTS_ANDROID_VERSION}"
    compile "com.nineoldandroids:library:${NINEOLDANDROID_VERSION}"
    compile "com.android.support:support-v4:${SUPPORT_V4_VERSION}"
    provided "javax.annotation:javax.annotation-api:${ANNOTATION_API_VERSION}"
    compile project(':fbcore')

    testCompile "com.google.guava:guava:${GUAVA_VERSION}"
    testCompile "junit:junit:${JUNIT_VERSION}"
    testCompile "org.mockito:mockito-core:${MOCKITO_CORE_VERSION}"
    testCompile "org.powermock:powermock-api-mockito:${POWERMOCK_VERSION}"
    testCompile "org.powermock:powermock-module-junit4-rule:${POWERMOCK_VERSION}"
    testCompile "org.powermock:powermock-classloading-xstream:${POWERMOCK_VERSION}"
    testCompile("org.robolectric:robolectric:${ROBOLECTRIC_VERSION}") {
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
}
apply from: rootProject.file('release.gradle')

// We download various C++ open-source dependencies from SourceForge into nativedeps/downloads.
// We then copy both downloaded code and our custom makefiles and headers into nativedeps/merge.

def nativeDepsDir = new File("${projectDir}/nativedeps")
def downloadsDir = new File("${nativeDepsDir}/downloads")
def mergeDir = new File("${nativeDepsDir}/merge")

task createNativeDepsDirectories {
    nativeDepsDir.mkdirs()
    downloadsDir.mkdirs()
    mergeDir.mkdirs()
}

task downloadGiflib(dependsOn: createNativeDepsDirectories, type: Download) {
    src 'http://downloads.sourceforge.net/project/giflib/giflib-5.1.1.tar.gz'
    onlyIfNewer true
    overwrite false
    dest downloadsDir
}

task downloadLibjpeg(dependsOn: createNativeDepsDirectories, type: Download) {
    src 'http://downloads.sourceforge.net/project/libjpeg-turbo/1.3.1/libjpeg-turbo-1.3.1.tar.gz'
    onlyIfNewer true
    overwrite false
    dest downloadsDir
}

task downloadLibpng(dependsOn: createNativeDepsDirectories, type: Download) {
    src 'http://downloads.sourceforge.net/project/libpng/libpng16/older-releases/1.6.10/libpng-1.6.10.tar.gz'
    onlyIfNewer true
    overwrite false
    dest downloadsDir
}

task downloadLibwebp(dependsOn: createNativeDepsDirectories, type: Download) {
    src 'https://github.com/webmproject/libwebp/archive/v0.4.2.tar.gz'
    onlyIfNewer true
    overwrite false
    dest downloadsDir
}

task unpackGiflib(dependsOn: downloadGiflib, type: Copy) {
    from tarTree(resources.gzip("${downloadGiflib.dest}/giflib-5.1.1.tar.gz"))
    into "${downloadsDir}"
}

task unpackLibjpeg(dependsOn: downloadLibjpeg, type: Copy) {
    from tarTree(resources.gzip("${downloadLibjpeg.dest}/libjpeg-turbo-1.3.1.tar.gz"))
    into "${downloadsDir}"
}

task unpackLibpng(dependsOn: downloadLibpng, type: Copy) {
    from tarTree(resources.gzip("${downloadLibpng.dest}/libpng-1.6.10.tar.gz"))
    into "${downloadsDir}"
}

task unpackLibwebp(dependsOn: downloadLibwebp, type: Copy) {
    from tarTree(resources.gzip("${downloadLibwebp.dest}/v0.4.2.tar.gz"))
    into "${downloadsDir}"
}

task copyGiflib(dependsOn: unpackGiflib, type: Copy) {
    from "${unpackGiflib.destinationDir}/giflib-5.1.1/lib"
    from 'src/main/jni/third-party/giflib'
    include('*.c', '*.h', '*.mk')
    into "${mergeDir}/giflib"
}

task copyLibjpeg(dependsOn: unpackLibjpeg, type: Copy) {
    from "${unpackLibjpeg.destinationDir}/libjpeg-turbo-1.3.1"
    from 'src/main/jni/third-party/libjpeg-turbo-1.3.x'
    include('**/*.c', '**/*.h','**/*.S', '**/*.asm', '**/*.inc', '*.mk')
    into "${mergeDir}/libjpeg-turbo-1.3.x"
}

task copyLibpng(dependsOn: unpackLibpng, type: Copy) {
    from "${unpackLibpng.destinationDir}/libpng-1.6.10"
    from 'src/main/jni/third-party/libpng-1.6.10'
    include('**/*.c', '**/*.h', '**/*.S', '*.mk')
    into "${mergeDir}/libpng-1.6.10"
}

task copyLibwebp(dependsOn: unpackLibwebp, type: Copy) {
    from "${unpackLibwebp.destinationDir}/libwebp-0.4.2"
    from 'src/main/jni/third-party/libwebp-0.4.2'
    include('src/**/*.c', 'src/**/*.h', '*.mk')
    into "${mergeDir}/libwebp-0.4.2"
}

task fetchNativeDeps(dependsOn: [copyGiflib, copyLibjpeg, copyLibpng, copyLibwebp]) {
}

task removeNativeDeps(type: Delete) {
    delete nativeDepsDir
}
allclean.dependsOn removeNativeDeps

def getNdkBuildName() {
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        return "ndk-build.cmd"
    } else {
        return "ndk-build"
    }
}

def getNdkBuildFullPath() {
    // we allow to provide full path to ndk-build tool
    if (hasProperty('ndk.command')) {
        return property('ndk.command')
    }
    // or just a path to the containing directiry
    if (hasProperty('ndk.path')) {
        def path = property('ndk.path')
        if (!path.endsWith(File.separator)) {
            path += File.separator
        }
        return path + getNdkBuildName()
    }
    // if none of above is provided, we assume ndk-build is already in $PATH
    return getNdkBuildName()
}

def makeNdkTasks(String name, Object[] deps) {
    task "ndk_build_$name"(dependsOn: deps, type: Exec) {
        inputs.file("src/main/jni/$name")
        outputs.dir("$buildDir/$name")
        commandLine getNdkBuildFullPath(),
            'NDK_PROJECT_PATH=null',
            'NDK_APPLICATION_MK=../Application.mk',
            'NDK_OUT=' + temporaryDir,
            "NDK_LIBS_OUT=$buildDir/$name",
            '-C', file("src/main/jni/$name").absolutePath,
            '--jobs', '8'
    }

    task "ndk_clean_$name"(type: Exec) {
        ignoreExitValue true
        commandLine getNdkBuildFullPath(),
            'NDK_PROJECT_PATH=null',
            'NDK_APPLICATION_MK=../Application.mk',
            'NDK_OUT=' + temporaryDir,
            "NDK_LIBS_OUT=$buildDir/$name",
            '-C', file("src/main/jni/$name").absolutePath,
            'clean'
    }

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn "ndk_build_$name"
    }
    clean.dependsOn "ndk_clean_$name"
}


android {
    def ndkLibs = [
        ['bitmaps', []],
        ['gifimage', [copyGiflib]],
        ['imagepipeline', [copyLibjpeg, copyLibpng, copyLibwebp]],
        ['memchunk', []],
        ['webpimage', [copyLibwebp]]]

    buildToolsVersion "21.1.2"
    compileSdkVersion 21
    sourceSets {
        main {
            jni.srcDirs = []
            jniLibs.srcDirs = ndkLibs.collect { "$buildDir/${it[0]}" }
        }
    }
    ndkLibs.each { lib -> makeNdkTasks lib[0], lib[1] }
}

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}
artifacts.add('archives', sourcesJar)

1 个答案:

答案 0 :(得分:0)

你没有路径中的ndk-build。 你有没有正确配置android-ndk? 尝试添加它,这个问题应该解决