android - 为gradle传递的参数为null

标签 android gradle android-gradle-plugin

我正在尝试安装相同的应用程序,但具有不同的版本/变体。所以我找到了这个博客。
https://blog.grandcentrix.net/how-to-install-different-app-variants-on-one-android-device/
我想用不同的应用程序针对不同的sprint对博客的图片执行相同的操作
这是我的gradle文件:

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'
}

运行此命令后:

enter image description here

在Gitbash中,我在Windows上
debugsuffix为NULL。

这是我尝试通过显示debugsuffix作为应用程序名称进行调试时的屏幕截图。
enter image description here

我在正确执行命令吗?还是我错过了什么?这是我第一次用传递的参数来进行这样的gradlebtw。有人尝试过吗?这真的是一个很好的帮助:)

最佳答案

我终于做到了!我实际上阅读了Gradle提供的免费电子书。并且了解了如何解决如何在一台设备上安装多个相同应用的想法。

这是我的Gradle文件。

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'
}

然后您运行以下命令:

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

您可以在命令行中用空格隔开链接任务。

这是输出:

enter image description here

您现在可以执行[AppName] -Sprint1等或[AppName] -bug-fix-05之类的操作。这样的事情。

关于android - 为gradle传递的参数为null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39101068/

相关文章:

android - react native 编译报错android - react-native-webview

java - gradle 到 maven 插件转换

plugins - Gradle新插件安装

android - 重复条目 : com/google/android/gms/internal/zzahl. 类

android - MediaCodec 的 presentationTimeUs 有什么用?

java - 如何在 <string-array> 上使用 Java/Android 字符串格式

java - 工作服徽章显示为 'unknown'

Android Studio : Gradle - build fails -- Execution failed for task ':dexDebug'

android - 多个 dex 文件定义 Lcom/google/firebase/FirebaseException

java - 使用之前生成的 token 在 Android 应用程序中进行 Dropbox 身份验证