将原生Android应用转换为gradle-experimental 0.2.0

时间:2015-09-01 17:52:29

标签: android android-studio gradle android-gradle build.gradle

我正在尝试将any project tango sample app转换为使用新的实验性gradle构建系统。我下载了一个应用程序,验证了它的构建和部署,然后在experimental-gradle guide之后更新了文件。这个过程是直接的,除了app build.gradle文件,在我的编辑之前和之后显示如下。我一直在研究gradle plugin,实验指南等,但还没弄清楚如何处理sourceSets和两个任务并不断出错。修改build.gradle的正确方法是什么?

注意:
我使用了point-cloud-jni-example,但是对于任何项目探戈应用程序来说,这些更改应该是相同的,因为所有探戈示例应用程序的相关文件基本相同。

股票应用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'])
}

修改了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'])
}

1 个答案:

答案 0 :(得分:1)

我不确定它是否能解决所有问题。

在任何情况下,您都必须使用以下内容更改buildTypes

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

也使用最新版本0.2.1