本文介绍了摇篮 - 构建以productflavor SASS(多文件夹)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们创建了一个web视图,显示从资产的文件夹的本地网站上的Andr​​oid应用程序。

We created an Android app with a webview which shows a local website from the assets folder.

该项目有不同的产品口味产生不同的风格和内容,但与同codeBA的(本地Java和HTML / JS)diffent的应用程序。

The project has different Product Flavors to generate diffent apps with different styles and content but with the same codebas (native Java and HTML / JS).

有关,我们要定义的颜色,并调整为特定的味道diffent青菜文件中的每个味道。

For each flavor we want to define a diffent sass file with the colors and tweaks for that specific flavour.

我知道,我需要建立在摇篮它建立的CSS文件一个任务,但我不知道从哪里开始:

I know that I need to create a task in gradle which builds the CSS files but I have no idea where to start:

  • 如何获得特定香味的资产文件夹的网址是什么?
  • 我可以用一个特殊的摇篮插件构建青菜或做我必须创建一个执行青菜命令任务?
  • 当我使用另一个摇篮插件像指南针,我怎么配置每种口味合适的文件夹?该插件设置在顶层,而不是在Android插件水平。

推荐答案

我finaly有解决方案!

I finaly have the solution!

本加入(不是你的应用程序),以你的build.gradle主文件夹:

Add this to your build.gradle in the main folder (not of your app):

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'http://dl.bintray.com/robfletcher/gradle-plugins' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.github.robfletcher:compass-gradle-plugin:2.0.6'

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

allprojects {
    repositories {
        jcenter()
    }
}

添加此应用程序模块的build.gradle:

Add this the build.gradle of the app module:

apply plugin: 'com.android.application'
apply plugin: 'com.github.robfletcher.compass'

android {

[..]

    android.applicationVariants.all { variant ->
        for (output in variant.outputs) {
            def procTask = output.processResources
            def sassTask = project.tasks.create("sassToCss${variant.name.capitalize()}") << {
                println "Assets folder: " + procTask.assetsDir

                def _ccsDir = file("$procTask.assetsDir\\css")
                def _sassDir = file("$procTask.assetsDir\\sass")
                def _imagesDir = file("$procTask.assetsDir\\images")
                def _javascriptsDir = file("$procTask.assetsDir\\js")
                def _fontsDir = file("$procTask.assetsDir\\fonts")


                project.compass{
                    cssDir = _ccsDir
                    sassDir = _sassDir
                    imagesDir = _imagesDir
                    javascriptsDir = _javascriptsDir
                    fontsDir = _fontsDir
                }
                //compileSass
                project.compassCompile.execute()
            }
            procTask.dependsOn(sassTask)
        }
    }
}

我从来没有想过它会工作了,但它的作品!

I never thought it would work out but it works!

这篇关于摇篮 - 构建以productflavor SASS(多文件夹)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 22:44