Fabrizio Duroni Fabrizio Duroni - 2 months ago 34
Android Question

Open GL ES - GLM Library and Android Studio

I'm trying to import a little C++ Open GL ES framework I wrote for an iOS application into an Android application.
I want to use Android NDK to import this framework.
As the framework will be shared between iOS and Android, I placed it outside the jni folder. I specified the path to the source dir of this framework in my grade file as follow (http://tools.android.com/tech-docs/new-build-system/gradle-experimental#TOC-Source-Set):

enter image description here

In this framework I used the GLM library for math operation, but as you could see again from the above screenshot, when I try to compile the project I receive the error:

/Users/chicio/Desktop/SpectralBRDFExplorer/SpectralBRDFExplorer/glm/detail/glm.cpp:4:10: fatal error: 'glm/glm.hpp' file not found

What am I doing wrong?

Answer

I found a solution to the problem by myself. As stated before, it was a problem in the setup of the include directories. I made the app compile by specifying in the gradle file the include directories suing the C++ flag -I Here you can find the complete gradle file:

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

model {
    android {
        compileSdkVersion 24
        buildToolsVersion "23.0.3"

        defaultConfig {
            applicationId "it.chicio.android.spectralbrdfexplorer"
            minSdkVersion.apiLevel 22
            targetSdkVersion.apiLevel 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles.add(file('proguard-android.txt'))
            }
        }
        ndk {
            moduleName "LibOpenGLJNI"
            toolchain = 'clang'
            stl         = 'gnustl_static'
            CFlags.addAll(['-Wall'])
            cppFlags.addAll(['-std=c++11','-Wall',
                             '-I' + file('src/main/jni'),
                             '-I' + file('../../SpectralBRDFExplorer'),
                             '-I' + file('../../SpectralBRDFExplorer/lodepng')])
            ldLibs.addAll(['android', 'log', 'GLESv3'])
        }
        sources {
            main {
                jni {
                    source {
                        srcDir "../../SpectralBRDFExplorer"
                    }
                }
            }
        }
        sources {
            main {
                assets {
                    source {
                        srcDir "../../Assets"
                    }
                }
            }
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:design:24.2.0'
}
Comments