这不会解决你的问题version.code
一部分,但这里是我是如何实现它在我们的项目中:
我创建了一个C#的工具,收集,我想我们要包括信息页。该工具在我们项目的构建器列表(Properties->Builders)
的第一步中调用,您可以在其中指定工具和命令行参数。在我们的例子建设者信息如下:
地点:C:\Projects\Mobile\Tools\AndroidBuildVersioner\AndroidBuildVersioner\bin\Release\AndroidBuildVersioner.exe
参数: -f C:\Projects\Mobile\Android\ProjectName\res\values\build_version.xml
该工具使用一个Perforce lib和然后检查项目负责修订和相关的库在我的情况将此信息写入可写文件build_version.xml
。该文件在工作区中保持可写,因为它是自动生成的文件。输出只是一组字符串资源,因此信息很容易用于项目的活动。我最初也正在写清单,但当构建工具修改您还必须亲手修改的文件时,很容易发生冲突。
这里有几个例子,如果有帮助:
build_version.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="build_revision">9</string>
<string name="build_date">7/25/2011 9:48:13 AM</string>
<string name="build_machine">JMARTIN-PC</string>
<string name="build_user">jmartin</string>
</resources>
AndroidBuildVersioner.exe - 这个简化的只是增加一个本地版本号,并将其写入和一些额外的ENV信息回到字符串xml文件。
private static void updateBuildFileInfo(String file)
{
String fileContents = ReadFile(file);
String buildRevision = "0";
String newFileContents = @"<?xml version=""1.0"" encoding=""utf-8""?>"
+ Environment.NewLine + "<resources>" + Environment.NewLine ;
//find the build version in the contents of the file so it can be incremented
Match m = Regex.Match(fileContents, @"<string name=""build_revision"">(.*)</string>");
if (m.Success)
buildRevision = m.Groups[1].Value;
int intBuildRevision = 0;
try
{
intBuildRevision = Convert.ToInt32(buildRevision);
}
catch (FormatException e)
{
Console.WriteLine("Input string is not a sequence of digits.");
}
catch (OverflowException e)
{
Console.WriteLine("The number cannot fit in an Int32.");
}
finally
{
++intBuildRevision;
newFileContents += '\t' + @"<string name=""build_revision"">" + intBuildRevision + "</string>" + Environment.NewLine;
newFileContents += '\t' + @"<string name=""build_date"">" + DateTime.Now.ToString() + "</string>" + Environment.NewLine;
newFileContents += '\t' + @"<string name=""build_machine"">" + Environment.MachineName + "</string>" + Environment.NewLine;
newFileContents += '\t' + @"<string name=""build_user"">" + Environment.UserName + "</string>" + Environment.NewLine;
newFileContents += "</resources>";
}
writeOutput(file, newFileContents);
}
是的,除了我从'jni/Application.mk'(我们的大多数应用程序是C++)调用它之外,它和我最终做的非常相似。对于清单,事实证明,基于ant的构建器实际上可以替换版本。代码,但是我最终做了一个临时副本,并代之以各种各样的东西,因为我需要更多的更改,而不仅仅是'version.code'和自定义资源。 – 2011-07-26 05:39:58