繁体   English   中英

Windows 或 Linux Android Studio 上的 ndkBuild 进程 'command'sh' 失败

[英]Failed ndkBuild process 'command 'sh' on Windows or Linux Android Studio

几个星期以来,我学习了如何从IBR-DTN Github编译 IBR-DTN 源代码,现在我被困在 Android NDK 的东西上。 这是我在 Android Studio 上的失败日志,我尝试了 Windows 版本和 Linux 版本,但总是出现相同的错误

Error:Execution failed for task ':app:ndkBuild'. 
> A problem occurred starting process 'command 'sh''

这是我的 build.gradle

    apply plugin: 'android-sdk-manager'
    apply plugin: 'com.android.application'

def createVersionName() {
    if (System.getenv().containsKey("BUILD_NUMBER")) {
        if (System.getenv().containsKey("GIT_COMMIT")) {
            return rootProject.ext.versionName + "-" + System.getenv("GIT_COMMIT").substring(0, 7)
        } else {
            return rootProject.ext.versionName + "-" + System.getenv("BUILD_NUMBER")
        }
    } else {
        return rootProject.ext.versionName
    }
}

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "de.tubs.ibr.dtn"
        minSdkVersion 9
        targetSdkVersion 22
        versionCode System.getenv("BUILD_NUMBER") as Integer ?: rootProject.ext.versionCode
        versionName createVersionName()
    }
    signingConfigs {
        release {
            storeFile file(System.getenv("KEYSTORE") ?: "publish.keystore")
            storePassword System.getenv("KEYSTORE_PASSWD")
            keyAlias System.getenv("KEY_ALIAS") ?: android.defaultConfig.applicationId
            keyPassword System.getenv("KEY_PASSWD")
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets.main {
        jniLibs.srcDir 'src/main/libs'
        jni.srcDirs = []
    }
}

// enable signing if the keystore exists
if (android.signingConfigs.release.storeFile.exists()) {
    android.buildTypes.release.signingConfig = android.signingConfigs.release
}

task ndkBuild(type: Exec) {
    executable "sh"
    workingDir "src/main/jni"
    args "build.sh"
}
preBuild.dependsOn ndkBuild

dependencies {
    compile 'de.tubs.ibr.dtn:library:1.1.2'
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.jjoe64:graphview:3.1.+'
    compile 'com.google.zxing:core:3.2.+'
    compile 'com.google.zxing:android-integration:3.2.+'
}

这是来自 Android Studio 的错误日志: 这是来自 Android Studio 的错误日志

寻求帮助来完成我的论文,我感谢这里的每一个建议。 非常喜欢XOXO

我以前从未见过这种定义 Gradle exec 任务的语法。

task ndkBuild(type: Exec) {
    executable "sh"
    workingDir "src/main/jni"
    args "build.sh"
}

根据Gradle 文档,我会这样定义它:

task ndkBuild(type: Exec) {
    if (isWindows()) {
        commandLine 'cmd', '/c', 'src/main/jni/build.bat'
    }
    else {
        commandLine 'src/main/jni/build.sh'
    }
}

我正在与同样的问题作斗争(也使用 IBR DTN)。 我可以通过将 NDK 路径添加到src/main/jni/build.sh脚本中的 PATH 变量来解决这个问题。

#!/bin/sh
PATH=/…/android-sdk/ndk-bundle/:$PATH
export PATH
…

这个链接也可能有帮助:

https://github.com/ibrdtn/ibrdtn/wiki/Build-IBR-DTN-for-Android

对于初学者,我建议您使用与他们测试过的 ndk 版本完全相同的 ndk 版本。 ndk 下载并解压它,然后直接在src/main/jni/build.sh更改变量路径。 然后运行脚本,它将构建它并最后运行./gradlew 我一次又一次地对其进行了测试,它仅适用于 Linux。 我使用了 mac,但有一些可怕的错误。 我也在做论文

我认为您的应用程序需要 ROOT 权限。

暂无
暂无

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

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