Android Studio:新的gradle构建NDK示例应用程序错误

时间:2015-07-12 19:00:05

标签: android android-ndk

我从https://github.com/googlesamples/android-ndk构建示例项目MoreTeapots并获取错误

  

信息:Gradle任务[:app:assembleAllDebug]   :应用:copyArm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer   :应用:createArm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup   :应用:compileArm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC   :应用:compileArm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp   :应用:linkArm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:stripSymbolsArm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:arm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:copyArmeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer   :应用:createArmeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup   :应用:compileArmeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC   :应用:compileArmeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp   :应用:linkArmeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:stripSymbolsArmeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:armeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:copyArmeabiDebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer   :应用:createArmeabiDebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup   :应用:compileArmeabiDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC   :应用:compileArmeabiDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp   :应用:linkArmeabiDebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:stripSymbolsArmeabiDebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:armeabiDebugAllMoreTeapotsNativeActivitySharedLibrary   :app:preBuild UP-TO-DATE   :app:preAllDebugBuild UP-TO-DATE   :应用:checkAllDebugManifest   :应用:prepareAllDebugDependencies   :app:compileAllDebugAidl UP-TO-DATE   :app:compileAllDebugRenderscript UP-TO-DATE   :app:generateAllDebugBuildConfig UP-TO-DATE   :app:generateAllDebugAssets UP-TO-DATE   :app:mergeAllDebugAssets UP-TO-DATE   :app:generateAllDebugResValues UP-TO-DATE   :app:generateAllDebugResources UP-TO-DATE   :app:mergeAllDebugResources UP-TO-DATE   :app:processAllDebugManifest UP-TO-DATE   :app:processAllDebugResources UP-TO-DATE   :app:generateAllDebugSources UP-TO-DATE   :app:processAllDebugJavaRes UP-TO-DATE   :应用:compileAllDebugJavaWithJavac   注意:C:\ Users \ Cuong \ Downloads \ MoreTeapots \ app \ src \ main \ java \ com \ sample \ moreteapots \ MoreTeapotsNativeActivity.java使用或覆盖不推荐使用的API。   注意:使用-Xlint重新编译:弃用以获取详细信息。   :应用:copyMips64DebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer   :应用:createMips64DebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup   :应用:compileMips64DebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC   :应用:compileMips64DebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp   :应用:linkMips64DebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:stripSymbolsMips64DebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:mips64DebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:copyMipsDebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer   :应用:createMipsDebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup   :应用:compileMipsDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC   :应用:compileMipsDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp   :应用:linkMipsDebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:stripSymbolsMipsDebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:mipsDebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:copyX86DebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer   :应用:createX86DebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup   :应用:compileX86DebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC   :应用:compileX86DebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp   :应用:linkX86DebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:stripSymbolsX86DebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:x86DebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:copyX86_64DebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer   :应用:createX86_64DebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup   :应用:compileX86_64DebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC   :应用:compileX86_64DebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp   :应用:linkX86_64DebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:stripSymbolsX86_64DebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:x86_64DebugAllMoreTeapotsNativeActivitySharedLibrary   :应用:compileAllDebugSources   :应用:preDexAllDebug   :应用:dexAllDebug   意外的顶级例外情况:   ...在解析com / sample / helper / NDKHelper.class时   意外的顶级例外情况:   ...在解析com / sample / moreteapots / BuildConfig.class时   意外的顶级例外情况:   ...在解析com / sample / moreteapots / MoreTeapotsApplication.class时   意外的顶级例外情况:   ...解析com / sample / moreteapots / MoreTeapotsNativeActivity $ 1.class   意外的顶级例外情况:   ...解析com / sample / moreteapots / MoreTeapotsNativeActivity $ 2.class   意外的顶级例外情况:   ...解析com / sample / moreteapots / MoreTeapotsNativeActivity $ 3.class   意外的顶级例外情况:   ...在解析com / sample / moreteapots / MoreTeapotsNativeActivity.class时   意外的顶级例外情况:   ...在解析com / sample / moreteapots / R $ attr.class时   意外的顶级例外情况:   ...在解析com / sample / moreteapots / R $ drawable.class时   意外的顶级例外情况:   ...在解析com / sample / moreteapots / R $ id.class时   意外的顶级例外情况:   ...在解析com / sample / moreteapots / R $ layout.class时   意外的顶级例外情况:   ...在解析com / sample / moreteapots / R $ string.class时   意外的顶级例外情况:   ...在解析com / sample / moreteapots / R $ style.class时   意外的顶级例外情况:   ...在解析com / sample / moreteapots / R.class时   14个错误;中止   错误:任务':app:dexAllDebug'执行失败。   com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'命令' C:\ Program Files \ Java \ jdk1.8.0_45 \ bin \ java.exe& #39;'完成非零退出值1   信息:建筑失败   信息:总时间:4分钟1.033秒   信息:1错误   信息:0警告   信息:请参阅控制台中的完整输出

这是指南http://tools.android.com/tech-docs/new-build-system/gradle-experimental。 它的app build.gradle

apply plugin: 'com.android.model.application'

model {
android {
    compileSdkVersion    = 22
    buildToolsVersion    ="22.0.1"

    defaultConfig.with {
        applicationId    = "com.sample.moreteapots"
        minSdkVersion.apiLevel    = 11
        targetSdkVersion.apiLevel = 22

    }
}
android.ndk {
    moduleName ="MoreTeapotsNativeActivity"
    cppFlags   += "-I${file("src/main/jni/cpufeatures")}".toString()
    cppFlags   += "-I${file("src/main/jni/native_app_glue")}".toString()
    cppFlags   += "-I${file("src/main/jni/ndk_helper")}".toString()

    // CFlags is configured in similiar way as cppFlags
    // CFlags    += "-I${file("src/main/jni/native_app_glue")}".toString()

    ldLibs     += ["android", "EGL", "GLESv2","log"]
    stl         = "stlport_static"
}

android.sources {
    main {
        jni {
            source {
                srcDirs 'src/main/jni'
            }
        }
    }
}

android.productFlavors {
    create ("arm7") {
        ndk.abiFilters += "armeabi-v7a"
    }
    create ("arm8") {
        ndk.abiFilters += "arm64-v8a"
    }
    create ("x86-32") {
        ndk.abiFilters += "x86"
    }
    // for detailed abiFilter descriptions, refer to "Supported ABIs" @
    // https://developer.android.com/ndk/guides/abis.html#sa
    // build one including all productFlavors
    create("all")
}

}

其项目build.gradle

// Top-level build file where you can add configuration options common to      all sub-projects/modules.
buildscript {
repositories {
   maven {
     url  "http://dl.bintray.com/android/android-tools"
   }
   jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle-experimental:0.1.0'
}
}

allprojects {
repositories {
    jcenter()
}

}

其gradle-wrapper.properties

#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-rc-1-bin.zip

我该如何解决?感谢。

更新:已解决。我添加

    compileOptions.with {
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7
}

到app build.gradle,如

apply plugin: 'com.android.model.application'
model {
android {
    compileSdkVersion    = 22
    buildToolsVersion    ="22.0.1"

    defaultConfig.with {
        applicationId    = "com.sample.moreteapots"
        minSdkVersion.apiLevel    = 10
        targetSdkVersion.apiLevel = 22

    }
}
android.ndk {
    moduleName ="MoreTeapotsNativeActivity"
    cppFlags   += "-I${file("src/main/jni/cpufeatures")}".toString()
    cppFlags   += "-I${file("src/main/jni/native_app_glue")}".toString()
    cppFlags   += "-I${file("src/main/jni/ndk_helper")}".toString()

    // CFlags is configured in similiar way as cppFlags
    // CFlags    += "-I${file("src/main/jni/native_app_glue")}".toString()

    ldLibs     += ["android", "EGL", "GLESv2","log"]
    stl         = "stlport_static"
}

android.sources {
    main {
        jni {
            source {
                srcDirs 'src/main/jni'
            }
        }
    }
}

android.productFlavors {
    create ("arm7") {
        ndk.abiFilters += "armeabi-v7a"
    }
    create ("arm8") {
        ndk.abiFilters += "arm64-v8a"
    }
    create ("x86-32") {
        ndk.abiFilters += "x86"
    }
    // for detailed abiFilter descriptions, refer to "Supported ABIs" @
    // https://developer.android.com/ndk/guides/abis.html#sa
    // build one including all productFlavors
    create("all")
}
compileOptions.with {
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7
}

}

2 个答案:

答案 0 :(得分:9)

试试这个

tasks.withType(JavaCompile) {
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7
}

此处提交了错误https://code.google.com/p/android/issues/detail?id=179660

编辑:将其附加到所有部分之外的app build.gradle文件的末尾

答案 1 :(得分:1)

或者,可以在'apply plugin:...'

之后立即添加两行
apply plugin: 'com.android.model.application'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7