Code Monkey home page Code Monkey logo

Comments (9)

jenzz avatar jenzz commented on July 16, 2024

It looks like the plugin cannot find the processResources task for your build type (processDebugResources, processReleaseResources, etc).

I would have to see more of your build.gradle setup to tell you exactly what's wrong.
Also: Which version of the Android Build Tools are you using? 2.0.0-betaX?

from gradle-android-buildconstants-plugin.

CeccoCQ avatar CeccoCQ commented on July 16, 2024

Hi @jenzz, thanks for your response.

This is my (big) build.gradle:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0-alpha3'
        classpath 'io.fabric.tools:gradle:1.20.1'
        classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
        classpath 'org.codehaus.groovy:groovy-backports-compat23:2.4.3'
        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.2.1'
        classpath 'com.google.gms:google-services:1.4.0-beta1'
        classpath 'com.canelmas.let:let-plugin:0.1.9'
        classpath "gradle.plugin.com.jenzz:buildconstants:1.0.1"
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'http://maven.justbit.it/content/repositories/thirdparty/' }
        maven { url 'http://maven.justbit.it/content/repositories/releases/' }
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://jitpack.io" }
        maven { url 'https://clojars.org/repo/' }
        mavenLocal()
    }
    configurations {
        all {
            exclude module: 'httpclient'
            exclude module: 'httpcore'
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = "2.11-20151225230027+0000"
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'let'
apply plugin: 'com.jenzz.buildconstants'

android {

    enforceUniquePackageName = false
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    defaultConfig {
        multiDexEnabled true
        minSdkVersion 15
        targetSdkVersion 23
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        ndk {
            moduleName "native"
            stl "gnustl_shared"
            ldLibs "log"
        }
    }

    sourceSets {
        main {
            manifest.srcFile file('src/main/AndroidManifest.xml')
            aidl.srcDirs = ['src', 'src/main/aidl', 'src/main/aidl/']
            res.srcDirs 'src/main/res'
            assets.srcDirs = ['src/main/assets', 'src/main/assets/']
            renderscript.srcDirs = ['src/main/rs', 'src/main/rs/']
            resources.srcDirs = ['src/main/resources', 'src/main/resources/']
            jniLibs.srcDir 'src/main/libs'
            jni.srcDirs = ['src/main/jni', 'src/main/jni/']
        }
    }

    dexOptions {
        jumboMode = true
        preDexLibraries = false
        javaMaxHeapSize "4g"
    }
    lintOptions {
        disable 'InvalidPackage'
        checkReleaseBuilds false
        abortOnError false
    }
    packagingOptions {
        exclude 'lib/armeabi/libnative.so'
        exclude 'lib/mips/librsjni.so'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        pickFirst 'lib/mips/librsjni.so'
        pickFirst 'lib/mips/libblasV8.so'
        pickFirst 'lib/mips/libRSSupport.so'
        pickFirst 'lib/x86/librsjni.so'
        pickFirst 'lib/x86/libblasV8.so'
        pickFirst 'lib/x86/libRSSupport.so'
        pickFirst 'lib/armeabi-v7a/librsjni.so'
        pickFirst 'lib/armeabi-v7a/libblasV8.so'
        pickFirst 'lib/armeabi-v7a/libRSSupport.so'
    }
    signingConfigs {
        debug {
            storeFile file("../keystore_beta.jks")
            storePassword KEYSTORE_PASSWORD
            keyAlias KEYSTORE_ALIAS
            keyPassword KEYSTORE_PASSWORD
        }
        staging {
            storeFile file("../keystore_staging.jks")
            storePassword KEYSTORE_PASSWORD
            keyAlias KEYSTORE_ALIAS
            keyPassword KEYSTORE_PASSWORD
        }
        release {
            storeFile file("../keystore.jks")
            storePassword KEYSTORE_PASSWORD
            keyAlias KEYSTORE_ALIAS
            keyPassword KEYSTORE_PASSWORD
        }
    }
    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
            shrinkResources false
            signingConfig signingConfigs.debug
            ext.enableCrashlytics = false
        }
        staging {
            debuggable true
            minifyEnabled false
            shrinkResources false
            signingConfig signingConfigs.staging
        }
        release {
            debuggable false
            signingConfig signingConfigs.release
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    productFlavors {

        beta {
            applicationId appIdBeta
            versionCode 1
            versionName '0.1'
            signingConfig signingConfigs.debug
        }
        crashlytics {
            applicationId appIdStaging
            versionCode 4
            versionName '1.0.3'
            signingConfig signingConfigs.release
        }
        production {
            applicationId appIdProduction
            versionCode 1
            versionName '1.0.0'
            signingConfig signingConfigs.release
        }

    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

buildConstants {
    javaFileName 'BuildConstants'
    xmlFileName 'build_constants'
    constants {
        firstValue = 'one'
        secondValue = 'two'
        aNumber = 123
    }
}

dependencies {
  .....
}

crashlytics {
    enableNdk true
    androidNdkOut 'src/main/obj'
    androidNdkLibsOut 'src/main/libs'
}

dexcount {
    includeClasses = false
    includeFieldCount = false
    printAsTree = true
    orderByMethodCount = true
    verbose = false
}

task ndkBuild(type: Exec) {
    workingDir file('src/main')
    commandLine getNdkBuildCmd()
}

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

task cleanNative(type: Exec) {
    workingDir file('src/main')
    commandLine getNdkBuildCmd(), 'clean'
}
clean.dependsOn cleanNative

def getDate() {
    def dateNow = new Date()
    def formattedDate = dateNow.format('yyyyMMdd')
    return formattedDate
}

def getNdkDir() {
    if (System.env.ANDROID_NDK_ROOT != null)
        return System.env.ANDROID_NDK_ROOT

    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ndkdir = properties.getProperty('ndk.dir', null)
    if (ndkdir == null)
        throw new GradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK_ROOT environment variable.")

    return ndkdir
}

import org.apache.tools.ant.taskdefs.condition.Os
def getNdkBuildCmd() {
    def ndkbuild = getNdkDir() + "/ndk-build"
    if (Os.isFamily(Os.FAMILY_WINDOWS))
        ndkbuild += ".cmd"

    return ndkbuild
}


gradle.taskGraph.beforeTask { Task task ->
    if(task.name ==~ /process.*GoogleServices/) {
        android.applicationVariants.all { variant ->
            if(task.name ==~ /(?i)process${variant.name}GoogleServices/){
                copy {
                    from new File(System.getProperty("user.dir")+"/app/src/${variant.flavorName}")
                    into new File(System.getProperty("user.dir")+"/app/")
                    include 'google-services.json'
                }
            }
        }
    }
}

android.applicationVariants.all{ variant ->
    variant.mergeResources.doLast{
            def applicationId = variant.productFlavors[0].applicationId
            File valuesFile = file("${buildDir}/intermediates/res/merged/${variant.dirName}/xml/file_provider.xml")
            println("Replacing package number in " + valuesFile)
            println("Build number = " + applicationId)
            String content = valuesFile.getText('UTF-8')
            content = content.replaceAll(/_APP_ID_/, applicationId)
            valuesFile.write(content, 'UTF-8')
    }
}

android.applicationVariants.all { variant ->
    def appName
    if (project.hasProperty("applicationName")) {
        appName = applicationName
    } else {
        appName = parent.name
    }

    variant.outputs.each { output ->
        def newApkName
        if (output.zipAlign) {
            newApkName = "${appName}-${output.baseName}-${variant.versionName}(${variant.versionCode}).apk"
        } else {
            newApkName = "${appName}-${output.baseName}-${variant.versionName}(${variant.versionCode})-unaligned.apk"
        }
        output.outputFile = new File(output.outputFile.parent, newApkName)
    }
}

allprojects {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:deprecation"
    }
}

from gradle-android-buildconstants-plugin.

CeccoCQ avatar CeccoCQ commented on July 16, 2024

Hi,
any news about this issue?

from gradle-android-buildconstants-plugin.

nottix avatar nottix commented on July 16, 2024

+1

from gradle-android-buildconstants-plugin.

85simo avatar 85simo commented on July 16, 2024

Same issue here.

from gradle-android-buildconstants-plugin.

jenzz avatar jenzz commented on July 16, 2024

The problem here is that you are using product flavors in your build script which are currently not supported.
Gradle creates separate tasks for each product flavor (e.g. process(flavor)DebugResources) which this plugin needs to detect and rely on.

I can easily reproduce the issue myself so I'll look into this as part of the next version.

from gradle-android-buildconstants-plugin.

jenzz avatar jenzz commented on July 16, 2024

@CeccoCQ @nottix @85simo

I have just pushed v1.1.0 to the Gradle plugins repo which adds support for product flavors.

I updated the sample app with some new product flavors and constants are now being generated for the selected build variant.
Let me know if it also works for you.

from gradle-android-buildconstants-plugin.

CeccoCQ avatar CeccoCQ commented on July 16, 2024

Hi @jenzz ,
I've tried the new version and all seems to work. Great!

I've an idea: I think that could be very useful if you could divide the constants per flavor. For example

buildConstants {
    flavor1 {
        javaFileName 'BuildConstantsFlavor1'
        xmlFileName 'build_constants_flavor1'
        constants {
            firstValue = 'one'
            secondValue = 'two'
            aNumber = 123
        }
    }
    flavor2 {
        javaFileName 'BuildConstantsFlavor2'
        xmlFileName 'build_constants_flavor1'
        constants {
            aNumber = 327123
        }
    }
}

Is it possible?

from gradle-android-buildconstants-plugin.

jenzz avatar jenzz commented on July 16, 2024

Yep. I've had the same idea in mind a while ago.
I'm planning to add support for configs per product flavor with v2.0.0 since it requires quite significant changes and would also change slightly the DSL.

Check out #2 to get an idea of what I imagine it to look like.

from gradle-android-buildconstants-plugin.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.