android - list 合并 - Android studio 0.8.1 升级构建错误 : property 'manifestFile' does not exist

标签 android android-studio android-manifest android-gradle-plugin build.gradle

我刚刚升级到 Android Studio 0.8.1 并升级了构建工具等。来自 Android Studio 0.6

但是后来我得到了这个构建错误:

A problem was found with the configuration of task ':processDevelopmentDebugResources'.

File 'C:\ProjectFolder\build\manifests\DevelopmentDebug\Development\debug\AndroidManifest.xml' specified for property 'manifestFile' does not exist.

但是我不知道问题出在哪里。构建下的文件夹 list 不存在。
我怀疑这与我的代码的最后一部分替换 list 文件中的值有关。在构建工具变更列表中更改了有关“ list 合并中的修复”的内容,但我不知道这是否相关。但话又说回来 - 该文件夹不存在,此代码应该更改其中的一些文件。

有什么线索吗?

编辑 1: 我只是尝试注释“variant.processManifest.doLast”部分并且它有效,所以问题出在这段代码上。 (为什么我以前没有尝试过..)
但是上一个版本中发生了什么变化导致此代码失败?它在升级之前有效。

编辑 2: 请参阅 ianhanniballake 的回答下的评论。

这是我的 build.gradle 文件:

buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2'
    }
}

repositories {
    mavenCentral()
    maven { url 'http://download.crashlytics.com/maven' }
}

apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
apply plugin: 'android-apt'

dependencies {
    compile 'com.crashlytics.android:crashlytics:1.+'
    compile fileTree(dir: 'libs', include: '*.jar')

    apt "org.androidannotations:androidannotations:3.0.1"
    compile "org.androidannotations:androidannotations-api:3.0.1"
}

apt {
    arguments {
        resourcePackageName "dk.packagename"
        androidManifestFile variant.processResources.manifestFile
    }
}

android {
    packagingOptions { //Fix: http://stackoverflow.com/a/20675331/860488
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    compileSdkVersion 10
    buildToolsVersion "20.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 10
        buildConfigField "int", "appId", "2"
    }

    lintOptions {
        checkReleaseBuilds false
    }

    signingConfigs {
        //Use terminal command: gradle assembleKonnektRelease
        releaseKonnekt {

        }
    }

    productFlavors{
        def konnektSigningConfig = signingConfigs.releaseKonnekt

        Development {
            applicationId "dk.packagename"
            versionCode 1
            versionName "1.0.0"
            buildConfigField "int", "appId", "2"
        }
    }

    buildTypes {
        testflight.initWith(buildTypes.debug)
        debug {
            applicationIdSuffix ".debug"
        }

        testflight {
            applicationIdSuffix ".test"
        }

        release {
        }
    }

    // Override Data in Manifest
    android.applicationVariants.all { 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}")

                def variantName = variant.name.toString()
                def appName = "empty"
                def facebookId = "empty"

                // *** SET APP NAME ***
                if (variantName.contains("Development")) {
                    appName = "Development"
                } else if (variantName.contains("Konnekt")) {
                    appName = "Konnekt"
                    facebookId = "**"
                } 

                if(variantName.contains("Debug")){
                    appName = appName + " debug"
                } else if(variantName.contains("Test")){
                    appName = appName + " test"
                }

                // *** REPLACE LINES IN MANIFEST ***
                filter {
                    String line -> line.replaceAll("<application android:allowBackup=\"true\" android:icon=\"@drawable/ic_launcher\" android:label=\"todo\" android:name=\"dk.packagename.App\">", // implicit "." is replaced with: "dk.packagename."
                                                    "<application android:allowBackup=\"true\" android:icon=\"@drawable/ic_launcher\" android:label=\"" + appName + "\" android:name=\"dk.packagename.App\">");
                }
                filter {
                    String line -> line.replaceAll("<activity android:label=\"todo\" android:name=\"dk.packagename.SplashActivity\">",
                                                    "<activity android:label=\"" + appName + "\" android:name=\"dk.packagename.SplashActivity\">");
                }
                filter{
                    String line -> line.replaceAll("<meta-data android:name=\"com.facebook.sdk.ApplicationId\" android:value=\"\"/>",
                                                    "<meta-data android:name=\"com.facebook.sdk.ApplicationId\" android:value=\"" + facebookId + "\"/>")
                }
            }
        }

        // *** 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"
    }
}

最佳答案

这很可能是由于 new manifest merging成为默认值。新 list 合并的好处之一是您不必使用此方法 - 相反,您可以定义自定义占位符并将它们插入到合并过程中:

android {
    defaultConfig {
        manifestPlaceholders = [ activityLabel:"defaultName"]
    }
    productFlavors {
        free {
        }
        pro {
            manifestPlaceholders = [ activityLabel:"proName" ]
        }
    }

将替换以下声明中的占位符:

<activity android:name=".MainActivity" android:label="${activityLabel}" >

注意:您还可以将多个占位符组合在一起,例如 android:label="${appName}${appType}" 来适当分段字符串并减少重复输入相同信息。

关于android - list 合并 - Android studio 0.8.1 升级构建错误 : property 'manifestFile' does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24536065/

相关文章:

android - 使用聚合调用 Google Fit REST API

id 为 : 'kotlin-android-extensions' 的 android studio 插件

android - Android:更新Android Studio tu 0.8.7后,Gradle错误:找不到com.android.tools.build:gradle:2.0

android - 如何将我的 Intent 添加到 android gallery 图像上下文 "set as"?

安卓 : Restrict app not to run on Tablet

android - 什么是 ERROR_INTERNAL

android - 如何在 android kotlin 中更改 onScrollChanged 上的选项卡

android - 媒体播放器错误 (-4, -4)

android - 如何在两个布局之间放置一个按钮

android - 无法启动服务 - 需要 ACCESS_MOCK_LOCATION 安全设置