for several weeks i learn how to compile IBR-DTN source from IBR-DTN Github , and now im being stuck at Android NDK stuff.
here my failure log on Android Studio, i tried Windows version and Linux version there are always same error
Error:Execution failed for task ':app:ndkBuild'.
> A problem occurred starting process 'command 'sh''
and this is my 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.+'
}
Here is the error log from Android Studio:
Looking for help to finish my thesis, i appreciate every single advice here. MUCH LOVE XOXO
I haven't seen this syntax for defining a Gradle exec task before.
task ndkBuild(type: Exec) {
executable "sh"
workingDir "src/main/jni"
args "build.sh"
}
I would define it like this instead, per the Gradle docs:
task ndkBuild(type: Exec) {
if (isWindows()) {
commandLine 'cmd', '/c', 'src/main/jni/build.bat'
}
else {
commandLine 'src/main/jni/build.sh'
}
}
I was fighting against the same problem (also with IBR DTN). I could fix the problem by adding the NDK-path to the PATH variable inside the src/main/jni/build.sh script.
#!/bin/sh
PATH=/…/android-sdk/ndk-bundle/:$PATH
export PATH
…
And this link might also be helpful:
https://github.com/ibrdtn/ibrdtn/wiki/Build-IBR-DTN-for-Android
Well for starter I would suggest you use exactly the same ndk version against which they tested. ndk. Download and extract it and then simply change variable path directly in src/main/jni/build.sh. Then run the script it will build it and lastly run ./gradlew. I have tested it again and again, it works only on Linux. I used mac but there were some scary errors. I am also doing thesis on it
I think that your application need ROOT permission.
Related
i would have loved to put this as a comment to the original question, but i have not enough access rights to make comments....
i tried to use the answer of Android+Gradle: list directories into a file for an android java project developed with AIDE....
as far as i understand all this gradle/maven stuff AIDE still uses gradle v 1.
estracted from the general build.gradle file:
dependencies {classpath 'com.android.tools.build:gradle:1.+'}
so i added the whole new assets reading task to the app build.gradle (in the app director) that now looks this way:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "com.nohkumado.quelkar"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
//try to compile a asset directory listing....
task indexAssets
{
description 'Index Build Variant assets for faster lookup by AssetManager later'
ext.assetsSrcDir = file( "${projectDir}/src/main/assets" )
ext.assetsBuildDir = file( "${buildDir}/assets" )
inputs.dir assetsSrcDir
//outputs.dir assetsBuildDir
doLast
{
android.applicationVariants.each
{
target ->
ext.variantPath = "${buildDir.name}/assets/${target.dirName}"
println "copyAssetRec:${target.dirName} -> ${ext.variantPath}"
def relativeVariantAssetPath = projectDir.name.toString() + "/" + ext.variantPath.toString()
def assetIndexFile = new File(relativeVariantAssetPath +"/assets.index")
def contents = ""
def tree = fileTree(dir: "${ext.variantPath}", exclude: ['**/.svn/**', '*.index'])
tree.visit
{
fileDetails ->
contents += "${fileDetails.relativePath}" + "\n"
}
assetIndexFile.write contents
}
}
}
indexAssets.dependsOn
{
tasks.matching { task -> task.name.startsWith( 'merge' ) && task.name.endsWith( 'Assets' ) }
}
tasks.withType( Compile )
{
compileTask -> compileTask.dependsOn indexAssets
}
}
dependencies {
compile project('::../UtilsApp:nohutils')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
so i thought i did it right..... but seems not, adding that task to the gradle file, break the dependcies directive meaning that suddenly all my imports from the external library nohutils don't work anymore.....
and in fact, it happens as soon as i declare, even an empty "task indexAssets".....
unfortunately, each time i try to apply what i read in the gradle manual, fails in AIDE and since AIDE has no manual whatsoever, its just dabbling in the dark....
so if anyone has a possible explanation/solution i will gladly take it....
I downloaded sipdroid project from here and tried to import in Android Studio. While building error:
Error: NDK integration is deprecated in the current plugin. Consider trying the new experimental plugin. For details, see http://tools.android.com/tech-docs/new-build-system/gradle-experimental. Set "android.useDeprecatedNdk=true" in gradle.properties to continue using the current NDK integration.`
I created file with name gradle.properties and added android.useDeprecatedNdk=true
Then while building I had errors with including libs, for example:
#include <myinttypes.h>
#include <spandsp/telephony.h>
#include <spandsp/g722.h>
#include <spandsp/private/g722.h>
And one more error:
Error:Execution failed for task ':app:compileDebugNdk'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users....\ndk-bundle\ndk-build.cmd'' finished with non-zero exit value 2
What's wrong? How to build project without this errors?
At first, you always can build jni-part with command line, doing this way:
$ export NDK_PROJECT_PATH=/opt/umake/AndroidStudioProjects/Sipdroid/app/src/main
$ /opt/umake/android/android-ndk/ndk-build
and create gradle.properties file with
android.useDeprecatedNdk=true
at the root of the project.
And with new build.gradle (Module: app) will be this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.0.1"
defaultConfig {
applicationId "org.sipdroid.sipua"
minSdkVersion 5
targetSdkVersion 21
ndk {
moduleName "OSNetworkSystem"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets.main.jni.srcDirs = [] // disable automatic ndk-build call, which ignore our Android.mk
sourceSets.main.jniLibs.srcDir 'src/main/libs'
}
Its works for me.
Usually I use Experimental Android Gradle Plugin, it much better for native projects. After import sipdroid to Android Studio you need to change build.gradle (Module: app) to this:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 21
buildToolsVersion = "21.0.1"
defaultConfig.with {
applicationId = "org.sipdroid.sipua"
minSdkVersion.apiLevel = 10
targetSdkVersion.apiLevel = 21
}
}
compileOptions.with {
sourceCompatibility=JavaVersion.VERSION_1_7
targetCompatibility=JavaVersion.VERSION_1_7
}
/*
* native build settings
*/
android.ndk {
moduleName = "OSNetworkSystem"
/*
* Other ndk flags configurable here are
* cppFlags.add("-fno-rtti")
* cppFlags.add("-fno-exceptions")
* ldLibs.addAll(["android", "log"])
* stl = "system"
*/
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
}
android.productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" #
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm") {
ndk.abiFilters.add("armeabi")
}
create("arm7") {
ndk.abiFilters.add("armeabi-v7a")
}
create("arm8") {
ndk.abiFilters.add("arm64-v8a")
}
create("x86") {
ndk.abiFilters.add("x86")
}
create("x86-64") {
ndk.abiFilters.add("x86_64")
}
create("mips") {
ndk.abiFilters.add("mips")
}
create("mips-64") {
ndk.abiFilters.add("mips64")
}
// To include all cpu architectures, leaves abiFilters empty
create("all")
}
}
and change classpath in build.gradle (whole project, root directory) from
'com.android.tools.build:gradle:1.5.0'
to
'com.android.tools.build:gradle-experimental:0.4.0'
and delete gradle.properties file with 'android.useDeprecatedNdk=true' at the root of the project.
After build Android Studio will eliminate with Gradle Build Messages lots of errors in sources with includes, and locate them by clicking at corresponding message.
I don't see any other variants with Experimental Android Gradle Plugin, rather than to change includes in cpp and c-files like this:
Such as in ndk/silk/src/SKP_Silk_main_FIX.h:
#include "SKP_Silk_typedef.h"
to
#include "../interface/SKP_Silk_typedef.h"
It's sad that this fragment synch with Gradle Experimental Plugin gratefully, but hasn't effect.
android.sources {
main {
jni {
source {
srcDirs = []
}
}
}
}
There is the solution from
How to use custom Android.mk with new gradle build system
android.sources{
main.jni {
source {
srcDirs = []
}
}
main.jniLibs {
source {
srcDirs = ['src/main/libs']
}
}
}
It seems a bug in plugin gradle-experimental:0.4.0 throws this error
BError:Attempt to read a write only view of model of type 'java.lang.Object' given to rule 'model.android.sources'
but gradle-experimental:0.3.0-alpha7 works fine if remove jni and save only libs directory.
Recently i decided to take the new NDK plugin in Android Studio for a ride
The changes needed are explained here
My build.gradle was ported successfully. Today i decided that i need a copy task in order to copy files into my 'asset' folder.
Searching online says that i must use a 'preBuild.dependsOn taskName' line, which i am sure works Ok for normal Gradle, but fails in the new experimental one (With the introduction of the 'model' behaviour)
Now my build.gradle fails.
Error:(25, 0) Could not find property 'preBuild' on root project 'Android'.
I am sure that the task is defined correctly, since the error comes from the preBuild... line
Here is my build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.0'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.model.application'
task copyWebViewAssets(type: Copy){
from '../Common/WebView'
into 'src/main/assets'
include('**/*')
}
preBuild.dependsOn copyWebViewAssets
model {
compileOptions.with {
sourceCompatibility=JavaVersion.VERSION_1_7
targetCompatibility=JavaVersion.VERSION_1_7
}
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "com.company.product"
minSdkVersion.apiLevel = 9
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
}
}
android.ndk {
moduleName = "native"
}
android.buildTypes {
release {
minifyEnabled = false
}
debug {
ndk.with {
debuggable = true
}
}
}
android.productFlavors {
// To include all cpu architectures, leaves abiFilters empty
create("all")
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
}
I would like to address again that this is related to the new experimental Gradle for NDK. I am currently on Android Studio 1.4, using Gradle 2.5.
Thank you for your support
Use compileTask instead of prebuild
it works for me.
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(changeNamespace)
}
Every time i try to build an android app, that uses ndk to run native code, i get the following error:
Error:Gradle: Execution failed for task ':sampleNDK:ndkBuild'.
> Process 'command 'C:\NDK\android-ndk-r10e/ndk-build.cmd'' finished with non-zero exit value 2
I use Intellij with a grandle projekt. I think the error appears in this function in the build.gradle file:
task ndkBuild(type: Exec) {
def ndkDir = plugins.getPlugin('com.android.application').sdkHandler.getNdkFolder()
if(org.gradle.internal.os.OperatingSystem.current().windows){
commandLine "$ndkDir/ndk-build.cmd", 'NDK_PROJECT_PATH=src/main'
//does not work too
//commandLine "$ndkDir\\ndk-build.cmd", 'NDK_PROJECT_PATH=src/main'
}else{
commandLine "$ndkDir/ndk-build", 'NDK_PROJECT_PATH=src/main'
}
}
In fact that i'm using windows, i think the error appears in the if case.
Does anyone know what went wrong or what i can try to avoid the failure?
UPDATE
That's the whole build script. Maybe that is helpful.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
}
apply plugin: 'com.android.application'
repositories {
jcenter()
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "de.anmi.android.samplendk"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
sourceSets.main.jni.srcDirs = []
sourceSets.main.jniLibs.srcDirs = ['src/main/libs']
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
task ndkBuild(type: Exec) {
// http://stackoverflow.com/questions/28615439/android-gradle-plugin-1-1-0-getndkfolder-not-found-anymore-any-replacement
def ndkDir = plugins.getPlugin('com.android.application').sdkHandler.getNdkFolder()
if (org.gradle.internal.os.OperatingSystem.current().windows) {
commandLine "$ndkDir/ndk-build.cmd", 'NDK_PROJECT_PATH=src/main'
//does not work too
// commandLine "$ndkDir\\ndk-build.cmd", 'NDK_PROJECT_PATH=src/main'
} else {
commandLine "$ndkDir/ndk-build", 'NDK_PROJECT_PATH=src/main'
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
I've started using Gradle today and after searching for an hour and trying every possible answer from SO (e.g. 1) and different blogs (e.g. 2) and documentations (e.g. 3) I need some help.
My question is simple: How to execute a custom build-step (in my case the execution of ndk-build with a customized Android.mk) as part of the regular build-process?
The build.gradle looks like this:
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "myApp.prototype"
minSdkVersion 16
targetSdkVersion 19
testApplicationId "myApp.prototype.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
sourceSets.main.jni.srcDirs = []
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
def rootDir = project.rootDir
def localProperties = new File(rootDir, "local.properties")
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}
def ndkDir = properties.getProperty('ndk.dir')
println ndkDir
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "$ndkDir\\ndk-build.cmd",
'NDK_PROJECT_PATH=build/intermediates/ndk',
'NDK_LIBS_OUT=src/main/jniLibs',
'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
'NDK_APPLICATION_MK=src/main/jni/Application.mk'
} else {
commandLine "$ndkDir/ndk-build",
'NDK_PROJECT_PATH=build/intermediates/ndk',
'NDK_LIBS_OUT=src/main/jniLibs',
'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
'NDK_APPLICATION_MK=src/main/jni/Application.mk'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services-location:6.5+'
compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.code.gson:gson:2.2.4'
compile fileTree(dir: new File(buildDir, 'libs'), include: '*.jar')
}
When executing gradle ndkBuild from the command-line, everything works fine. But I want that Android Studio automatically runs ndkBuild when it runs the rest of the Android compile procedures (such as generateDebugSources, preBuild, preDebugBuild, ...).
I have tried to attach myself to these events like this:
gradle.projectsEvaluated {
preBuild.dependsOn(ndkBuild)
}
but regardless where I put that code, or what task I use from the variety of tasks available (when running gradle tasks), nothing seems to work.
Have you tried adding a dependency for ndkBuild on JavaCompile tasks ?
android {
...
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}