NDKBuild Failure in android studio - android

I'm having trouble getting my NDK to compile properly in Android Studio. Whenever I try running to compile I am getting the following error.
Error:Execution failed for task ':app:ndkBuild'. A problem occurred starting process 'command 'ndk-build.cmd''
build.gradle:-
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.google.android.apps.watchme"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
sourceSets.main{
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
project.ext.versionCodes = ['armeabi':1, 'armeabi-v7a':2, 'arm64-v8a':3, 'mips':5, 'mips64':6, 'x86':8, 'x86_64':9] //versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-*
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + defaultConfig.versionCode
}
}
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'C:\\Users\\RAM-RAMADEVI\\AppData\\Local\\Android\\sdk\\ndk-bundle', '-C', file('src/main').absolutePath
} else {
commandLine 'ndk-build', '-C', file('src/main').absolutePath
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services-plus:7.8.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.google.apis:google-api-services-youtube:v3-rev120-1.19.0'
compile 'com.google.http-client:google-http-client-android:+'
compile 'com.google.api-client:google-api-client-android:+'
compile 'com.google.api-client:google-api-client-gson:+'
compile 'com.mcxiaoke.volley:library:1.0.18'
compile 'com.google.code.gson:gson:2.3'
}
local.properties:-
ndk.dir=C\:\\Users\\RAM-RAMADEVI\\AppData\\Local\\Android\\Sdk\\ndk-bundle
sdk.dir=C\:\\Users\\RAM-RAMADEVI\\AppData\\Local\\Android\\Sd
k

Related

android gradle build - run task before assembleRelease or assembleLive

Below is my build.gradle file for app.
build.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
google()
}
android {
signingConfigs {
liveSigning {
keyAlias 'xxxxxxx'
keyPassword 'xxxxxx'
storeFile file('D:\\xxxxx\\xxxxxxx\\xxxxx\\xxxx.jks')
storePassword 'xxxxxxx'
}
}
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
useLibrary 'org.apache.http.legacy'
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [];
}
defaultConfig {
applicationId rootProject.ext.applicationId
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.compileSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
multiDexEnabled true
resConfigs "en"
vectorDrawables.useSupportLibrary true
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.liveSigning
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
task ndkBuild(type: Exec) {
commandLine rootProject.ext.ndkPath, '-C', file('src/main').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
lintOptions {
abortOnError false
}
productFlavors {
live {
minSdkVersion rootProject.ext.minSdkVersion
applicationId rootProject.ext.applicationId
signingConfig signingConfigs.liveSigning
targetSdkVersion rootProject.ext.compileSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
resConfigs "en"
}
}
flavorDimensions "default"
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//compile files('libs/gson-2.2.4.jar')
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
compile "com.android.support:cardview-v7:${rootProject.ext.supportLibVersion}"
compile "com.android.support:design:${rootProject.ext.supportLibVersion}"
compile files('libs/cordova-5.jar')
compile files('libs/org.apache.commons.io.jar')
compile files('libs/httpmime-4.2.3.jar')
compile files('libs/jsoup-1.7.3.jar')
compile files('libs/activation.jar')
compile project(':libraries:EventBus')
compile project(':libraries:PDFViewCtrlTools')
compile project(':libraries:imageannotations')
compile project(':libraries:bottom-bar')
compile project(':libraries:tooltip')
compile('com.crashlytics.sdk.android:crashlytics:2.5.2#aar') {
transitive = true;
}
compile files('libs/glide-3.6.1.jar')
//compile 'com.roughike:bottom-bar:2.2.0'
compile project(':libraries:k4l-video-trimmer')
compile 'com.android.support:multidex:1.0.1'
compile 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.0.1'
compile 'com.google.firebase:firebase-messaging:10.2.0'
compile 'me.relex:circleindicator:1.2.2'
compile 'com.daimajia.swipelayout:library:1.2.0#aar'
compile 'org.apache.commons:commons-collections4:4.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
apply plugin: 'com.google.gms.google-services'
Before I generate signed APK to upload for google play store , I want to execute command line code. And by using that command line program i want to do some pre release activity like disable logs of NDK, change url to live website and etc. So how can I execute it before assembleLive or assembleRelease ? I don't want to execute that command line code before "assembleDebug". I want to execute it only before "assembleLive or assembleRelease".
I added below code to my gradle file and it works like a charm.
task prelivetask (type: Exec) {
commandLine 'cmd','/C', 'start', 'change.cmd'
}
tasks.whenTaskAdded { task ->
if (task.name == 'assembleRelease' || task.name == 'assembleLive') {
task.dependsOn prelivetask
}
}

add-application.mk file not found in ndk-build android

I am using this https://github.com/quiet/org.quietmodem.Quiet link to transfer sound. This is a library so added it in project and in buld.gradle , i have compiled the project as :
compile project(':quiet')
My code for build.gradle(Module : quiet) is
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable = true
jniDebuggable = true
}
}
sourceSets { main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = []
} }
externalNativeBuild{
ndkBuild{
path "$projectDir/src/main/jni/Android.mk"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:23.0.0'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test:runner:0.5'
compile 'com.android.support:appcompat-v7:23.1.1'
}
def getNdkDir() {
if (System.env.ANDROID_NDK_ROOT != null)
return System.env.ANDROID_NDK_ROOT
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkdir = properties.getProperty('ndk.dir', null)
if (ndkdir == null)
throw new GradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK_ROOT environment variable.")
return ndkdir
}
def getNdkBuildCmd() {
def ndkbuild = getNdkDir() + "/ndk-build"
if (Os.isFamily(Os.FAMILY_WINDOWS))
ndkbuild += ".cmd"
return ndkbuild
}
task ndkBuild(type:Exec, description: "Compile JNI Sources") {
workingDir file('src/main')
commandLine getNdkBuildCmd()
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkLibsToJar
}
task ndkLibsToJar(type: Zip, dependsOn: 'ndkBuild', description: 'Create a JAR of the native libs') {
destinationDir new File(buildDir, 'libs')
baseName 'ndk-libs'
extension 'jar'
from(new File(buildDir, 'libs')) { include '**/*.so' }
into 'lib/'
}
Now when i build my project , it throws ndk issues which is shown in the image
The issue I am facing is shown in the image

ERROR: Error:(3, 10) 'opencv2/opencv.hpp' file not found

I am using Android studio 2.2.3 and OpenCV 3.1.0. i resolved many errors but could not find solution for this one.
This is my Build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.example.ahmedarif.fyp3"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets.main {
jni.srcDirs = [] //disable automatic ndk-build call
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
commandLine "C:\\Android\\sdk1\\ndk-bundle/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'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/'] } }
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
compile project(':openCVLibrary310')
}
}
I also tried buigl.gradle from ph0b
but that build.gradle showing error about ndk-bulid.cmd. I tried almost every thing but didn't work for me. help to get rid of this. Tahnx
And then my build.gradle ;
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.c.a.engineer.imageprocessingpre"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { jni.srcDirs = []
jniLibs.srcDir 'src/main/jniLibs' } }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile project(':openCVLibrary310')
}
It's work for me. You can try this. And I developed image processing app. This my app screenshot;
If you are using latest version of android studio just use its built in support for c and c++ from here
And i am usnig the same build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.example.ahmedarif.fyp3"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets.main {
jni.srcDirs = [] //disable automatic ndk-build call
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
commandLine "C:\\Android\\sdk1\\ndk-bundle/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'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/'] } }
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
compile project(':openCVLibrary310')
}
}

Android Studio NDK Build trouble Error:Execution failed for task ':app:ndkBuild'

I'm using the latest android studio build 1.5 ,since i want to import an eclipse project that needs NDK. My project is working. i try to import org.apache.tools.ant.taskdefs.condition.Os But it's working when i built APK, It's make error:
Error:Execution failed for task ':app:ndkBuild'.
> A problem occurred starting process 'command 'ndk-build.cmd''
My build.gradle:
apply plugin: 'com.android.application'
import org.apache.tools.ant.taskdefs.condition.Os
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "vaeapp.gamecard.vn"
minSdkVersion 14
targetSdkVersion 19
multiDexEnabled = true
versionCode 4
versionName "1.3.4"
ndk {
moduleName "gc"
}
}
task ndkBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
} else {
commandLine 'C\\:\\\\Users\\\\Android\\\\AppData\\\\Local\\\\Android\\\\sdk\\\\ndk-bundle', '-C', file('src/main/jni').absolutePath
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'com.facebook.android:facebook-android-sdk:4.2.0'
// compile 'com.android.support:appcompat-v7:20.0.0'
// compile 'com.google.android.gms:play-services:+'
compile 'com.google.android.gms:play-services:4.0.30'
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/commons-io-2.4.jar')
compile files('libs/error-reporter.jar')
//compile files('libs/httpclient-4.0.1.jar')
compile files('libs/mail.jar')
compile files('libs/universal-image-loader-1.9.3.jar')
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
// compile 'com.parse:parse-android:1.10.1'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
}
My local.properties:
ndk.dir=C\:\\Users\\Android\\AppData\\Local\\Android\\sdk\\ndk-bundle
sdk.dir=C\:\\Users\\Android\\AppData\\Local\\Android\\sdk
Please help my fix error. Thanks you so much!
We use the following wrapper:
task ndkBuild(type: Exec) {
File ndkDir = project.getPlugins().getPlugin('com.android.library').sdkHandler.getNdkFolder()
if (ndkDir == null) {
ndkDir = file(System.getenv('NDK_ROOT'))
}
if (ndkDir == null) {
def gradle_project_root = project.rootProject.rootDir
throw new GradleException("NDK is not configured. Make sure there is a local.properties " +
"file with an ndk.dir entry in the directory ${gradle_project_root}, or set the " +
"ANDROID_NDK envrionment variable")
}
def ndkBuildExecutable = new File(ndkDir, 'ndk-build')
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
ndkBuildExecutable += '.cmd'
}
if (!ndkBuildExecutable.exists()) {
throw new GradleException("Could not find ndk-build. The configured NDK directory ${ndkDir} may not be correct.")
}
commandLine(ndkBuildExecutable, '-j8', '-C', file('src/main').absolutePath)
}
In your gradle, the actual path for ndk-build.cmd is set for non-Windows platform. I believe this is wrong, because the path you set there is a very Windows-y path. And, to avoid the craziness of escape-character multiplication, you can use forward slash / in your gradle files to define paths, e.g. 'C:/Users/Android/AppData/Local/Android/sdk/ndk-bundle'. Only make sure all paths you specify don't have spaces (e.g. 'C:/Program Files').

Configure Gradle to execute custom build step before starting compilation

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
}
}

Categories

Resources