Arth Limchiu Arth Limchiu - 2 months ago 7
Android Question

Argument passed for gradle is null android

I'm trying to install the same app but with different versions/variants. So I found this blog.
https://blog.grandcentrix.net/how-to-install-different-app-variants-on-one-android-device/
I wanted to do something same with the blog's picture with different apps for different sprints
Here's my gradle file:

apply plugin: 'com.android.application'

def debugsuffix = System.getProperty('debugsuffix', project.getProperties().get('debugsuffix', null))

def final appId = 'com.arthlimchiu.testapp'

android {
compileSdkVersion 23
buildToolsVersion "24.0.0"

defaultConfig {
applicationId = appId
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}

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

productFlavors {
dev {
applicationId = appId + "." + debugsuffix + ".dev"
resValue "string", "app_name", ".dev-" + debugsuffix
}
}

lintOptions {
abortOnError false
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}


After running this command:

enter image description here

in Gitbash i'm on windows btw,
debugsuffix is NULL.

Here's a screenshot when I tried to debug it by displaying the debugsuffix as the application name.
enter image description here

Am I doing the command right? or am I missing something? It's my first time doing this kind gradle thingy btw with passing arguments. Has anyone tried this?It would really be a great help guys :)

Answer

I finally did it! I actually read the free ebook provided by Gradle. And got an idea how to solve how to install multiple of the same apps in one device.

This is my Gradle file.

apply plugin: 'com.android.application'

def debugsuffix = System.getProperty('debugsuffix', project.getProperties().get('debugsuffix', null))

def final appId = 'com.arthlimchiu.testapp'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId = appId
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        debug {
            applicationIdSuffix ".$debugsuffix"
            resValue "string", "app_name", "testApp-$debugsuffix"
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
}

And the you run this command:

Make sure you use "-P" and it's first executed

You can chain tasks in your command line separated by space.

And here's the output:

enter image description here

You can now do something like [AppName]-Sprint1 etc. or [AppName]-bug-fix-05. Something like that.