替换AndroidManifest.xml中的一个构建变量的字符串不适用于Gradle Android Plugin Version> 0.5.4

前端之家收集整理的这篇文章主要介绍了替换AndroidManifest.xml中的一个构建变量的字符串不适用于Gradle Android Plugin Version> 0.5.4前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
就在几周前,我有以下问题: How to replace a string for a buildvariant with gradle?

我也自己回答了这个问题.

一切工作正常到现在为止:我只是意识到我的复制任务不再工作了.我花了几个小时的问题,直到我意识到这取决于Gradle Android Plugin版本:一切,直到0.5.4工作正常.对于上层版本,我不会进入我的复制任务.

这是控制台输出

// gradle android plugin version: 0.5.6 and 0.5.5 --> copy tas doesn't work
:etscanner:prepareFlavor1Flavor1ReviewDependencies
:etscanner:compileFlavor1Flavor1ReviewAidl
:etscanner:generateFlavor1Flavor1ReviewBuildConfig
:etscanner:mergeFlavor1Flavor1ReviewAssets
:etscanner:compileFlavor1Flavor1ReviewRenderscript
:etscanner:mergeFlavor1Flavor1ReviewResources
:etscanner:processFlavor1Flavor1ReviewManifest
:etscanner:processFlavor1Flavor1ReviewResources
:etscanner:compileFlavor1Flavor1ReviewNote: Some input files use or override a d
eprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: <path>.DetailAdapter
.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

:etscanner:dexFlavor1Flavor1Review
:etscanner:processFlavor1Flavor1ReviewJavaRes UP-TO-DATE
:etscanner:validateFlavor1Flavor1Signing
:etscanner:packageFlavor1Flavor1Review
:etscanner:zipalignFlavor1Flavor1Review

// gradle android plugin version: 0.5.4 --> copy task work
:etscanner:prepareFlavor1Flavor1ReviewDependencies
:etscanner:compileFlavor1Flavor1ReviewAidl
:etscanner:generateFlavor1Flavor1ReviewBuildConfig
:etscanner:mergeFlavor1Flavor1ReviewAssets
:etscanner:compileFlavor1Flavor1ReviewRenderscript
:etscanner:mergeFlavor1Flavor1ReviewResources
:etscanner:processFlavor1Flavor1ReviewManifest
...hey you are in the copy task!
:etscanner:processFlavor1Flavor1ReviewResources
:etscanner:compileFlavor1Flavor1ReviewNote: Some input files use or override a d
eprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: <path>DetailAdapter
.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

:etscanner:dexFlavor1Flavor1Review
:etscanner:processFlavor1Flavor1ReviewJavaRes UP-TO-DATE
:etscanner:validateFlavor1Flavor1Signing
:etscanner:packageFlavor1Flavor1Review
:etscanner:zipalignFlavor1Flavor1Review
:etscanner:assembleFlavor1Flavor1Review

这真是一件奇怪的事情
有谁有一个想法如何解决这个问题?

更新1 2013-08-23

我的build.gradle文件

buildscript {
    repositories {
        // maven central repo doesn't work with gradle android plugin version 0.5.+
        // error message is describe in this post:
        // https://plus.google.com/117954254390243608387/posts/RVBjoDMkLV5
        //mavenCentral()
        maven {
            url 'http://nexus/content/groups/public/'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.4'
        // copy task doesn't work for following versions:
        //classpath 'com.android.tools.build:gradle:0.5.5'
        //classpath 'com.android.tools.build:gradle:0.5.6'
        //classpath 'com.android.tools.build:gradle:0.5.+'
    }
}

apply plugin: 'android'

dependencies {
    compile 'com.android.support:support-v4:13.0.+' // support lib
    //compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile project(':libraries:actionbarsherlock')
    compile project(':libraries:google-play-services_lib')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 17
        versionName = "2.3"
        versionCode = 4
    }

    // SIGN CONFIGS
    signingConfigs {
        flavor1 {
            storeFile file("keystore/myKeystore.keystore")
            storePassword = "store_password"
            keyAlias = "alias"
            keyPassword = "key_password"
        }
        flavor2 {
            storeFile file("keystore/myKeystore.keystore")
            storePassword = "store_password"
            keyAlias = "alias"
            keyPassword = "key_password"
        }
        debug {
            storeFile file("keystore/debug.keystore")
            storePassword = "android"
            keyAlias = "androiddebugkey"
            keyPassword = "android"
        }

    }

    // FLAVORS
    productFlavors {
        flavor1 {
            packageName 'myPackageName'
            signingConfig signingConfigs.flavor1
        }
        flavor2 {
            packageName 'myPackageName'
            signingConfig signingConfigs.flavor2
        }
    }

    // BUILDTYPES
    buildTypes {
        falvor1Review {
            versionNameSuffix = versionNameSuffixOfReviewVersion
            signingConfig signingConfigs.flavor1
        }
        flavor2Review {
            versionNameSuffix = versionNameSuffixOfReviewVersion
            signingConfig signingConfigs.flavor2
        }

        debug {
            packageNameSuffix ".debug"
            versionNameSuffix = versionNameSuffixOfReviewVersion
            signingConfig signingConfigs.debug
        }
    }

    // Override Data in Manifest
    android.applicationVariants.each { variant ->
        variant.processManifest.doLast {
            copy {
                // *** SET COPY PATHS ***
                try {
                    from("${buildDir}/manifests") {
                        //println "from: ${buildDir}/manifests"
                        include "${variant.dirName}/AndroidManifest.xml"
                        //println "included: ${variant.dirName}/AndroidManifest.xml"
                    }
                } catch (e) {
                    println "error: " + e
                }

                into("${buildDir}/manifests/${variant.name}")
                //println "into (neues Manifest): ${buildDir}/manifests/${variant.name}"

                // *** DEFINE VARS ***
                def brandVersion = variant.buildType.name
                def brandVersionString = brandVersion.toString()
                def appName = "empty"

                // *** SET APP NAME ***
                if (brandVersionString.contains("flavor1")) {
                    appName = "my app name for flavor 1"
                } else if (brandVersionString.contains("flavor2")) {
                    appName = "my app name for flavor 2"
                }

                println "...hey you are in the copy task"
                // *** REPLACE LINES IN MANIFEST ***
                // --- add appName
                filter {
                    String line ->
                        line.replaceAll("<application android:allowBackup=\"true\" android:icon=\"@drawable/ic_launcher\" android:label=\"todo\" android:theme=\"@style/AppTheme\">","<application android:allowBackup=\"true\" android:icon=\"@drawable/ic_launcher\" android:label=\"" + appName + "\" android:theme=\"@style/AppTheme\">");
                }
            }
        }

        // *** SET PATH TO NEW MANIFEST *** 
        variant.processResources.manifestFile = file("${buildDir}/manifests/${variant.name}/${variant.dirName}/AndroidManifest.xml")
        //println "newManifest: ${buildDir}/manifests/${variant.name}/${variant.dirName}/AndroidManifest.xml"
    }
}

更新2 2013-08-23

昨天我有另外一个奇怪的行为AS 0.2.5,它做了一些非常奇怪的构建:
正如你在我的过滤器中看到的,我之前在“清单”中的appName是“todo”:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="todo"
    android:theme="@style/AppTheme">

当我进行构建时,应用程序中的appName是正确的.但是在应用程序启动器和设置/应用程序中,已将“todo”显示为appName.

在AS 0.2.0中构建项目后,一切正常.

解决方法

我有同样的问题,并阅读0.5.5的发行说明,在那里我找到答案.

“访问变体容器不强制创建任务.这意味着android.[application | Library | Test]在评估阶段,变体将为空.要使用它,请使用.all而不是.each“

原文链接:https://www.f2er.com/android/312422.html

猜你在找的Android相关文章