问题描述
我刚刚升级到 Android Studio 0.8.1 并升级了构建工具等.来自 Android Studio 0.6
I have just upgraded to Android Studio 0.8.1 and upgraded build tools ect. from Android Studio 0.6
但后来我收到此构建错误:
But then I get this build error:
发现任务配置有问题':processDevelopmentDebugResources'.
文件'C:\ProjectFolder\build\manifests\DevelopmentDebug\Development\debug\AndroidManifest.xml'为属性manifestFile"指定的不存在.
File 'C:\ProjectFolder\build\manifests\DevelopmentDebug\Development\debug\AndroidManifest.xml' specified for property 'manifestFile' does not exist.
但我无法弄清楚问题是什么.build 下的文件夹 manifests 不存在.
我怀疑它与我的代码的最后一部分有关,它替换了清单文件中的值.构建工具更改列表中的清单合并中的修复"发生了一些变化,但我不知道这是否相关.但话又说回来 - 该文件夹不存在,此代码应该更改其中的一些文件.
But I can't figure out what the problem is. The folder manifests under build does not exists.
I suspect it has something to do with the last part of my code that replaces values in the manifest file. There is something about "Fixes in the manifest mergers" changed in build tools changelist, but I don't know if that is related. But then again - the folder does not exists and this code should change some files in it.
有什么线索吗?
编辑 1:我只是尝试将variant.processManifest.doLast"部分注释掉并且它有效,所以问题在于这段代码.(为什么我之前没有尝试过..)
但是上一个版本中发生了什么变化导致此代码失败?它在升级之前有效.
Edit 1:I just tried to comment the "variant.processManifest.doLast" part out and it works, so the issue is with this code. (Why haven't I tried that before..)
But what has changed in the last version that make this code fail? It worked before the upgrade.
编辑 2:查看ianhanniballake 的回答下的评论.
Edit 2:See comments under ianhanniballake's answer.
这是我的 build.gradle 文件:
This is my build.gradle file:
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"
}
}
推荐答案
这很可能是由于 新的清单合并 成为默认设置.新清单合并的一个好处是您不必使用这种方法 - 相反,您可以定义自定义占位符并将它们插入到合并过程中:
This is most likely due to the new manifest merging becoming the default. One benefit of the new manifest merging is that you don't have to use this approach - instead, you can define custom placeholders and have them inserted into the merging process:
android {
defaultConfig {
manifestPlaceholders = [ activityLabel:"defaultName"]
}
productFlavors {
free {
}
pro {
manifestPlaceholders = [ activityLabel:"proName" ]
}
}
将替换以下声明中的占位符:
will substitute the placeholder in the following declaration:
<activity android:name=".MainActivity" android:label="${activityLabel}" >
注意:您还可以将多个占位符组合在一起,例如 android:label="${appName}${appType}"
以适当地分割字符串并减少重复输入相同信息.
Note: you can also compose multiple placeholders together such as android:label="${appName}${appType}"
to segment a string appropriately and reduce retyping the same information.
这篇关于清单合并 - Android studio 0.8.1 升级构建错误:属性“manifestFile"不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!