Gradle - build sass per productflavor (multi folder)

前端 未结 1 1077
我在风中等你
我在风中等你 2021-01-17 13:25

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

The project has different Product Flavors to generate diffent apps with

相关标签:
1条回答
  • 2021-01-17 13:55

    I finaly have the solution!

    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()
        }
    }
    

    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 assetsDir = output.packageApplication.assets;
                tasks["merge${variant.name.capitalize()}Assets"].doLast() {
                    println "Assets folder: " + assetsDir
    
                    def _ccsDir = file("$assetsDir/css")
                    def _sassDir = file("$assetsDir/sass")
                    def _imagesDir = file("$assetsDir/images")
                    def _javascriptsDir = file("$assetsDir/js")
                    def _fontsDir = file("$assetsDir/fonts")
    
                    project.compass {
                        cssDir = _ccsDir
                        sassDir = _sassDir
                        imagesDir = _imagesDir
                        javascriptsDir = _javascriptsDir
                        fontsDir = _fontsDir
                    }
                    //compileSass
                    project.compassCompile.execute()
                }
            }
        }
    }
    

    I never thought it would work out but it works!

    0 讨论(0)
提交回复
热议问题