简体   繁体   中英

Converting native Android app to gradle-experimental 0.2.0

I'm trying to convert any project tango sample app to use the new experimental gradle build system. I downloaded an app, verified that it builds and deploys, and then updated files following the experimental-gradle guide . The process was straight-forward, except for the app build.gradle file, shown below before and after my edits. I have been studying the gradle plugin , the experimental guide, etc, but haven't figured out what to do with sourceSets and the two tasks and keep getting errors. What is the right way to modify build.gradle?

Note:
I used point-cloud-jni-example, but these changes should be the same for any project tango app, because the relevant files are essentially identical for all the tango sample apps.

stock app build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.projecttango.experiments.nativepointcloud"
        minSdkVersion 19
        targetSdkVersion 19
    }

    sourceSets.main {
        jniLibs.srcDir 'src/main/libs'
        jni.srcDirs = [];
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}

task ndkBuild(type: Exec) {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ndkbuild = properties.getProperty('ndk.dir', null)+"/ndk-build"
    commandLine ndkbuild, '-C', file('src/main/jni').absolutePath
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

modified app build.gradle:

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

model {
    android {
        compileSdkVersion = 19
        buildToolsVersion = "23.0.0"

        defaultConfig.with {
            applicationId = "com.projecttango.experiments.nativepointcloud"
            minSdkVersion.apiLevel = 19
            targetSdkVersion.apiLevel = 19
        }

        android.sourceSets.main {
            jniLibs.srcDir = 'src/main/libs'
            jni.srcDirs = [];
        }
    }

    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles += file('proguard-rules.pro')
            ndk.with {
                debuggable = true
            }
        }
    }

    android.ndk {
        moduleName = "point_cloud_jni_example"
        ldLibs += ["android", "EGL", "GLESv2", "dl", "log"]
        stl     = "stlport_static"
    }
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}

task ndkBuild(type: Exec) {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ndkbuild = properties.getProperty('ndk.dir', null)+"/ndk-build.cmd"
    commandLine ndkbuild, '-C', file('src/main/jni').absolutePath
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

I am not sure if it resolves all issues.

In any case, you have to change your buildTypes block using:

android.buildTypes {
    release {
         minifyEnabled = false
         proguardFiles += file('proguard-rules.pro')
    }
}

Also use the last version 0.2.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM