Mac上的Android Studio 0.5.7出现了奇怪的错误。我无法使用gradle和ndk-build编译我的项目。它失败并出现此错误:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':SKG:ndkBuild'.
A problem occurred starting process 'command 'ndk-build''
但是,当我从CLI运行./gradlew compileArmDebugJava时,项目已成功编译。
android studio中的错误:
Executing tasks: [:SKG:compileArmDebugJava]
Parallel execution with configuration on demand is an incubating feature.
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:SKG:preBuild
:SKG:preArmDebugBuild
:SKG:checkArmDebugManifest
:SKG:preArmReleaseBuild
:SKG:preArmv7DebugBuild
:SKG:preArmv7ReleaseBuild
:SKG:preFatDebugBuild
:SKG:preFatReleaseBuild
:SKG:preMipsDebugBuild
:SKG:preMipsReleaseBuild
:SKG:preX86DebugBuild
:SKG:preX86ReleaseBuild
:SKG:prepareComAndroidSupportAppcompatV71910Library UP-TO-DATE
:SKG:prepareArmDebugDependencies
:SKG:compileArmDebugAidl UP-TO-DATE
:SKG:compileArmDebugRenderscript UP-TO-DATE
:SKG:generateArmDebugBuildConfig UP-TO-DATE
:SKG:mergeArmDebugAssets UP-TO-DATE
:SKG:generateArmDebugResValues UP-TO-DATE
:SKG:generateArmDebugResources UP-TO-DATE
:SKG:mergeArmDebugResources UP-TO-DATE
:SKG:processArmDebugManifest UP-TO-DATE
:SKG:processArmDebugResources UP-TO-DATE
:SKG:generateArmDebugSources UP-TO-DATE
:SKG:ndkBuild FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':SKG:ndkBuild'.
> A problem occurred starting process 'command 'ndk-build''
* 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: 16.103 secs
从cli成功构建
./gradlew compileArmDebugJava
Parallel execution is an incubating feature.
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:SKG:preBuild
:SKG:preArmDebugBuild
:SKG:checkArmDebugManifest
:SKG:preArmReleaseBuild
:SKG:preArmv7DebugBuild
:SKG:preArmv7ReleaseBuild
:SKG:preFatDebugBuild
:SKG:preFatReleaseBuild
:SKG:preMipsDebugBuild
:SKG:preMipsReleaseBuild
:SKG:preX86DebugBuild
:SKG:preX86ReleaseBuild
:SKG:prepareComAndroidSupportAppcompatV71910Library UP-TO-DATE
:SKG:prepareArmDebugDependencies
:SKG:compileArmDebugAidl UP-TO-DATE
:SKG:compileArmDebugRenderscript UP-TO-DATE
:SKG:generateArmDebugBuildConfig UP-TO-DATE
:SKG:mergeArmDebugAssets UP-TO-DATE
:SKG:generateArmDebugResValues UP-TO-DATE
:SKG:generateArmDebugResources UP-TO-DATE
:SKG:mergeArmDebugResources UP-TO-DATE
:SKG:processArmDebugManifest UP-TO-DATE
:SKG:processArmDebugResources UP-TO-DATE
:SKG:generateArmDebugSources UP-TO-DATE
:SKG:ndkBuild
make: Entering directory `/...my path.../SKG/src/main/jni'
[armeabi] Install : libcrypto.so => libs/armeabi/libcrypto.so
[armeabi] Install : libdatabase_sqlcipher.so => libs/armeabi/libdatabase_sqlcipher.so
[armeabi] Install : libgenerate.so => libs/armeabi/libgenerate.so
[armeabi] Install : libsqlcipher_android.so => libs/armeabi/libsqlcipher_android.so
[armeabi] Install : libssl.so => libs/armeabi/libssl.so
[armeabi] Install : libstlport_shared.so => libs/armeabi/libstlport_shared.so
make: Leaving directory `/...my path.../src/main/jni'
:SKG:compileArmDebugJava UP-TO-DATE
BUILD SUCCESSFUL
Total time: 16.327 secs
这是我的build.gradle文件:
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'android'
android {
compileSdkVersion 16
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 9
targetSdkVersion 16
versionCode 28
versionName "2.2"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
debuggable false
jniDebugBuild false
}
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = []
}
defaultConfig {
ndk {
moduleName "generate"
}
}
productFlavors {
x86 {
ndk {
abiFilter "x86"
}
}
mips {
ndk {
abiFilter "mips"
}
}
armv7 {
ndk {
abiFilter "armeabi-v7a"
}
}
arm {
ndk {
abiFilter "armeabi"
}
}
fat
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
}
// 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/jni/').absolutePath
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
答案 0 :(得分:4)
解决了,删除了最后一行'/',改变了这一行:
commandLine 'ndk-build', '-C', file('src/main/jni/').absolutePath
到此:
commandLine 'ndk-build', '-C', file('src/main/jni').absolutePath
答案 1 :(得分:2)
如果你正在使用windows,你需要在gradle.build中写这个:commandLine ndkCommand,'-C', file('src/main/jni').absolutePath,'clean'
但如果您使用其他操作系统,如Linux或Mac,则需要写下:
commandLine ndkCommand,'-C', file('src/main/jni/').absolutePath,'clean'