A
A
Alexey Perelygin2016-04-13 11:49:17
Android
Alexey Perelygin, 2016-04-13 11:49:17

How to make Android Studio see imports for jni.h, android/log.h in editor?

Hi all. There is a problem - trying to move to AndroidStudio from Eclipse. The project uses ndk, prebuild libs, stl. the joke is that stl sees the inclusions, but does not see jni.h, android / log.h and my prebuilds. It concerns the editor, as the project is going and running. But I would like to write c / c ++ right there. Of course, you can score on tips, but it’s kind of boring without them.
here is gradle:project

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.7.0-alpha5'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

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

model{

    repositories {
        libs(PrebuiltLibraries) {
            avcodec {
                headers.srcDir "${nativeIncludes}\\libavcodec"
                binaries.withType(SharedLibraryBinary) {
                    sharedLibraryFile = file("${nativePrebuildLibs}\\ffmpeg\\armeabi-v7a\\lib\\libavcodec-56.so")
                }
            }

            avfilter {
                headers.srcDir "${nativeIncludes}\\libavfilter"
                binaries.withType(SharedLibraryBinary) {
                    sharedLibraryFile = file("${nativePrebuildLibs}\\ffmpeg\\armeabi-v7a\\lib\\libavfilter-5.so")
                }
            }

            avformat {
                headers.srcDir "${nativeIncludes}\\libavformat"
                binaries.withType(SharedLibraryBinary) {
                    sharedLibraryFile = file("${nativePrebuildLibs}\\ffmpeg\\armeabi-v7a\\lib\\libavformat-56.so")
                }
            }

            mp3lame {
                headers.srcDir "${nativeIncludes}\\lame"
                binaries.withType(SharedLibraryBinary) {
                    sharedLibraryFile = file("${nativePrebuildLibs}\\lame\\armeabi-v7a\\libmp3lame.so")
                }
            }

            avutil {
                headers.srcDir "${nativeIncludes}\\libavutil"
                binaries.withType(SharedLibraryBinary) {
                    sharedLibraryFile = file("${nativePrebuildLibs}\\ffmpeg\\armeabi-v7a\\lib\\libavutil-54.so")
                }
            }

            swresample {
                headers.srcDir "${nativeIncludes}\\libswresample"
                binaries.withType(SharedLibraryBinary) {
                    sharedLibraryFile = file("${nativePrebuildLibs}\\ffmpeg\\armeabi-v7a\\lib\\libswresample-1.so")
                }
            }

            swscale {
                headers.srcDir "${nativeIncludes}\\libswscale"
                binaries.withType(SharedLibraryBinary) {
                    sharedLibraryFile = file("${nativePrebuildLibs}\\ffmpeg\\armeabi-v7a\\lib\\libswscale-3.so")
                }
            }

        }
    }

    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.3"

        ndk {
            moduleName "codecs"
            abiFilters.add("armeabi-v7a")
            CFlags.addAll(["-D__STDC_CONSTANT_MACROS","-frtti", "-fexceptions"])
            ldLibs.addAll(["log"])
            stl "gnustl_shared"
        }
        defaultConfig {
            applicationId "my.app.id"
            minSdkVersion.apiLevel 11
            targetSdkVersion.apiLevel 23
            versionCode 13
            versionName "2.0.2.2"
        }

        buildTypes {
            release {
                minifyEnabled false
                proguardFiles.add(file("proguard-rules.pro"))
                signingConfig = $("android.signingConfigs.mysigning")
                ndk {
                    debuggable true
                }
            }
        }
//
//        productFlavors {
//            create("armv7a") {
//                ndk {
//                    // You can customize the NDK configurations for each
//                    // productFlavors and buildTypes.
//
//                }
//            }
//        }
    }

    android.signingConfigs {
        create("my_signing") {
            storeFile "path_to_jks"
            storePassword "password"
            keyAlias "Key Alias"
            keyPassword "AliasPass"
            storeType "jks"
        }
    }

    android.sources {
        main {
            jni {
                exportedHeaders{
                    srcDir "${nativeIncludes}".toString()
                }
                dependencies{
                    library "avcodec" linkage "shared"
                    library "avfilter" linkage "shared"
                    library "avformat" linkage "shared"
                    library "mp3lame" linkage "shared"
                    library "avutil" linkage "shared"
                    library "swresample" linkage "shared"
                    library "swscale" linkage "shared"
                }
            }
            jniLibs {
                dependencies {
                    library "avcodec"
                    library "avfilter"
                    library "avformat"
                    library "mp3lame"
                    library "avutil"
                    library "swresample"
                    library "swscale"
                }
            }
        }
    }


}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile 'com.google.android.gms:play-services-analytics:8.4.0'
    compile 'com.google.android.gms:play-services-ads:8.4.0'
}

#include <fstream>
#include "android/log.h"
#include "Rect.h"
#include "RectF.h"
#include <vector>


#ifdef __cplusplus
extern "C" {
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Droid924, 2016-04-29
@Droid924

android.sources {
        main {
            jni {
                source {
                    srcDir "src/main/jni"
                }
                exportedHeaders{
                    srcDir "${nativeIncludes}".toString()
                }
    ...

As I understand it, in order to connect editing capabilities, the studio needs Gradle to know about your source files.
I also find this line a bit odd:
I would rather use cppFlags

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question