Mohan
Mohan

Reputation: 1901

How to build and debug native code (c) with neon enabled in android studio?

I am referring is-it-possible-to-debug-c-c-in-android-studio? last answer by Yuchen Zhong and did some basic example also, that I am able to build and debug also.

So now I am trying with my old app project to do same thing. My old app buil.gradle is

apply plugin: 'com.android.application'
android {
    compileSdkVersion 18
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "pku......"
        minSdkVersion 9
        targetSdkVersion 17

        sourceSets.main {
            jni.srcDirs = []
            jniLibs.srcDir 'C:/Users/Admin/AndroidStudioProjects/and..../app/src/main/libs'
        }

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            ndk {
               debuggable = true
            }
        }
        debug {
              debuggable = true
              jniDebuggable = true
        }
        debug {
            jniDebuggable true
        }
    }
}

Updated build.gradle is follow so I will able to debug my code through android studio.

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

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion  = "23.0.1"

        defaultConfig.with {
            applicationId = "pku........"
            minSdkVersion.apiLevel = 18
            targetSdkVersion.apiLevel = 23
            versionCode = 1
            versionName = "1.0"
            //sourceSets.main {
            //    jni.srcDirs = []
            //    jniLibs.srcDir 'C:/Users/Admin/AndroidStudioProjects/andh...../app/src/main/libs'
            //}
        }
    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles.add(file('proguard-android.txt'))
        }
    }

   android.ndk {

        abiFilters.add("armeabi-v7a")
        moduleName = "icandroid"
        //CFlags.add("-std=c99")
        //CFlags.add("-mfloat-abi=soft")
        //CFlags.add("-mfpu=neon")
        CFlags.addAll(["-std=c99 ", "-mfloat-abi=softfp", "-mfpu=neon", "-O3", "-DCARES_STATICLIB", "-Wno-c++11-long-long"])
        stl = "stlport_shared" // stlport_shared, gnustl_static, "system"

    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
}

But while build I got the error

prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9\include\arm_neon.h Error:(31, 2) error: #error You must enable NEON instructions (e.g. -mfloat-abi=softfp -mfpu=neon) to use arm_neon.h

I don't know how to solve this problem because I have mentioned cflag also.

Please help me to solve this error and if there are some more error then also correct me.

Upvotes: 2

Views: 1119

Answers (1)

travisjayday
travisjayday

Reputation: 814

What does your Application.mk file look like? Adding

APP_CFLAGS := -mfloat-abi=softfp -mfpu=neon to Application.mk should fix the error.

Upvotes: 1

Related Questions