如何配置build.gradle

时间:2016-08-08 03:53:36

标签: android gradle

我尝试添加cppFlags,但始终报告错误:

"Error:(16, 0) Could not find property 'cppFlags' on com.android.build.gradle.internal.dsl.NdkOptions_Decorated@44658d55. <a href="openFile:/Users/liut1/Documents/Projects/Android/GitSourceCode/VideoWall/app/build.gradle">Open File</a>"

请帮助我,谢谢!

以下是我的评论:

  1. top gradle

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        repositories {
        jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.1.2'
            //        classpath 'com.android.tools.build:gradle-experimental:0.4.0'
    
            // 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
    }
    
  2. app gradle

      apply plugin: 'com.android.application'
    
    android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    
    defaultConfig {
        applicationId "andrewl.videowall"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        ndk {
             moduleName = "HelloARVideoNative"
    //               cppFlags.add("-I${file("include")}".toString())
            cppFlags.add("-DANDROID")
            cppFlags.add("-fexceptions")
            cppFlags.add("-frtti")
            stl = "gnustl_static"
            ldLibs "log","GLESv2"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            java.srcDirs = ['src/main/java', 'src/main/java-gen']
            jniLibs.srcDirs = ['libs']
        }
    }
    productFlavors {
        create("arm") {
            ndk.with {
                    abiFilters.add("armeabi-v7a")
                }
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.4.0'
        compile files('libs/greendao-1.3.7.jar')
    }
    
  3. gradle wrapper

    #Mon Dec 28 10:00:20 PST 2015
    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
    

1 个答案:

答案 0 :(得分:0)

看看这个。此示例包含您在cpp支持的应用程序中所需的配置。

ndk {
    moduleName = 'hello-jni'
    toolchain = 'clang'
    CFlags.addAll(['-Wall'])
}

Source