I build sample project MoreTeapots from https://github.com/googlesamples/android-ndk and get errors
Information:Gradle tasks [:app:assembleAllDebug] :app:copyArm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer :app:createArm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup :app:compileArm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC :app:compileArm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp :app:linkArm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibrary :app:stripSymbolsArm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibrary :app:arm64-v8aDebugAllMoreTeapotsNativeActivitySharedLibrary :app:copyArmeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer :app:createArmeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup :app:compileArmeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC :app:compileArmeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp :app:linkArmeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibrary :app:stripSymbolsArmeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibrary :app:armeabi-v7aDebugAllMoreTeapotsNativeActivitySharedLibrary :app:copyArmeabiDebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer :app:createArmeabiDebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup :app:compileArmeabiDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC :app:compileArmeabiDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp :app:linkArmeabiDebugAllMoreTeapotsNativeActivitySharedLibrary :app:stripSymbolsArmeabiDebugAllMoreTeapotsNativeActivitySharedLibrary :app:armeabiDebugAllMoreTeapotsNativeActivitySharedLibrary :app:preBuild UP-TO-DATE :app:preAllDebugBuild UP-TO-DATE :app:checkAllDebugManifest :app: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 :app:compileAllDebugJavaWithJavac Note: C:\Users\Cuong\Downloads\MoreTeapots\app\src\main\java\com\sample\moreteapots\MoreTeapotsNativeActivity.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. :app:copyMips64DebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer :app:createMips64DebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup :app:compileMips64DebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC :app:compileMips64DebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp :app:linkMips64DebugAllMoreTeapotsNativeActivitySharedLibrary :app:stripSymbolsMips64DebugAllMoreTeapotsNativeActivitySharedLibrary :app:mips64DebugAllMoreTeapotsNativeActivitySharedLibrary :app:copyMipsDebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer :app:createMipsDebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup :app:compileMipsDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC :app:compileMipsDebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp :app:linkMipsDebugAllMoreTeapotsNativeActivitySharedLibrary :app:stripSymbolsMipsDebugAllMoreTeapotsNativeActivitySharedLibrary :app:mipsDebugAllMoreTeapotsNativeActivitySharedLibrary :app:copyX86DebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer :app:createX86DebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup :app:compileX86DebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC :app:compileX86DebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp :app:linkX86DebugAllMoreTeapotsNativeActivitySharedLibrary :app:stripSymbolsX86DebugAllMoreTeapotsNativeActivitySharedLibrary :app:x86DebugAllMoreTeapotsNativeActivitySharedLibrary :app:copyX86_64DebugAllMoreTeapotsNativeActivitySharedLibraryGdbServer :app:createX86_64DebugAllMoreTeapotsNativeActivitySharedLibraryGdbsetup :app:compileX86_64DebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainC :app:compileX86_64DebugAllMoreTeapotsNativeActivitySharedLibraryMoreTeapotsNativeActivityMainCpp :app:linkX86_64DebugAllMoreTeapotsNativeActivitySharedLibrary :app:stripSymbolsX86_64DebugAllMoreTeapotsNativeActivitySharedLibrary :app:x86_64DebugAllMoreTeapotsNativeActivitySharedLibrary :app:compileAllDebugSources :app:preDexAllDebug :app:dexAllDebug UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/helper/NDKHelper.class UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/moreteapots/BuildConfig.class UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/moreteapots/MoreTeapotsApplication.class UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/moreteapots/MoreTeapotsNativeActivity$1.class UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/moreteapots/MoreTeapotsNativeActivity$2.class UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/moreteapots/MoreTeapotsNativeActivity$3.class UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/moreteapots/MoreTeapotsNativeActivity.class UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/moreteapots/R$attr.class UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/moreteapots/R$drawable.class UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/moreteapots/R$id.class UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/moreteapots/R$layout.class UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/moreteapots/R$string.class UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/moreteapots/R$style.class UNEXPECTED TOP-LEVEL EXCEPTION: ...while parsing com/sample/moreteapots/R.class 14 errors; aborting Error:Execution failed for task ':app:dexAllDebug'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 1 Information:BUILD FAILED Information:Total time: 4 mins 1.033 secs Information:1 error Information:0 warnings Information:See complete output in console
This is guide http://tools.android.com/tech-docs/new-build-system/gradle-experimental. Its 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")
}
}
Its project 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()
}
}
Its 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
How can I solve? Thanks.
UPDATE: Solved. I add
compileOptions.with {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
to app build.gradle like
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
}
}
To include ndk-build projects in your Gradle build, you need to use Android Studio 2.2 and higher with Android plugin for Gradle 2.2. 0 and higher. To learn more about Android Studio's support for external native builds, read Add C and C++ Code to Your Project.
Open your Android Studio Preference (or "File->Settings") > Appearance & Behavior > System Settings > Android SDK. You can find the path to your SDK and NDK, which is in the same directory.
Try this
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
Bug is submitted here https://code.google.com/p/android/issues/detail?id=179660
edit: append it to end of app build.gradle file outside all of sections
Alternatively, the two lines can be added immediately following the 'apply plugin: ...'
apply plugin: 'com.android.model.application'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With