Android Studio构建计数
是否有可能在计算机上查看一个项目自启动以来已生成了多少个版本 也许是10或100或1000 手动还是android代码Android Studio构建计数,android,build,count,Android,Build,Count,是否有可能在计算机上查看一个项目自启动以来已生成了多少个版本 也许是10或100或1000 手动还是android代码 有什么有用的吗?从来没有想过给Gradle添加一个计数器。但是给你。将此添加到build.gradle: defaultConfig { applicationId "xy" // ... def buildCountFile = new File("D:\\gradle-counter.txt") String content = ""
有什么有用的吗?从来没有想过给Gradle添加一个计数器。但是给你。将此添加到
build.gradle
:
defaultConfig {
applicationId "xy"
// ...
def buildCountFile = new File("D:\\gradle-counter.txt")
String content = ""
if(buildCountFile.exists()) {
content = buildCountFile.getText('UTF-8')
}
int count = 0;
if(content.isNumber()) {
count = content.toInteger() + 1;
}
buildCountFile.write(count.toString())
}
要创建每日计数器,可以添加如下内容:
defaultConfig {
applicationId "xy"
// ...
def buildCountFile = new File("D:\\gradle-counter.txt")
def sdf = new java.text.SimpleDateFormat("MM/dd/yyyy")
String date = sdf.format(new Date())
String content = ""
if(buildCountFile.exists()) {
content = buildCountFile.getText('UTF-8')
}
String dateRegex = "(" + date.replace("/","\\/") + ":\\s*)(\\d+)"
def matcher = java.util.regex.Pattern.compile(dateRegex).matcher(content)
if (matcher.find()) {
// Current date already in the file
int countToday = matcher.group(2).toInteger()
countToday = countToday + 1
String newLine = matcher.group(1) + countToday
content = content.replace(matcher.group(), newLine)
} else {
// Need to create a new line with current date
content = content + date + ": 1\r\n";
}
buildCountFile.write(content)
}
D:\gradle counter.txt的内容
:
01/21/2015: 4
02/21/2015: 2
01/21/2015: 4
02/21/2015: 2
注意:
同步Gradle文件也被计算在内
源代码是针对Windows的,需要进行一些小的更改才能与Linux配合使用。我正在路上-这是我的版本。。。不管怎么说,没有用户输入-我已经用console或swing启动了一些东西,但直到现在它还不起作用- 但是我再试一次
// Setting Preferences
def f_name = 'Buildlog.txt'
def f_path = 'e:/'
def BFile = new File(f_path+f_name);
def DateTime = new Date();
def sdf = new SimpleDateFormat("EEEE dd/MM/YYYY k:m:s")
if (BFile.exists()){
BFile.append(System.getProperty("line.separator") + sdf.format(DateTime))
} else {
}
所以我们到了,一些回到你身边 代码现在看起来像这样
// Setting Preferences
def f_name = 'Buildxx.txt'
def f_path = 'e:/'
def Seperator =';'
def BFile = new File(f_path+f_name);
def LineList = []
def readln = javax.swing.JOptionPane.&showInputDialog
def usertext = readln 'What have you done?'
def DateTime = new Date();
def sdf = new SimpleDateFormat("EEEE dd/MM/YYYY kk:mm:ss")
def x =0;
if (BFile.exists()){
def Max = BFile.length();
BFile.eachLine { line ->
x++;
LineList.add(line);
}
def LastLine = LineList.last();
def number = ""
number = LastLine.split(' ');
def InumStr = number[0];
def Inum = InumStr.toInteger();
def Nextnumber = Inum+1;
BFile.append(System.getProperty("line.separator")+Nextnumber+" " + sdf.format(DateTime)+ " "+usertext)
}
else
{
BFile.write("0 "+ sdf.format(DateTime)+ " Start of the project");
}
最后,您有一个日志文件,可以在Excel中打开(csv.file)。。。
它会处理一些像这样的格式
(我喜欢彩色Excel表格;)
注意:同步Gradle文件也被计算在内
这是唯一的麻烦:(
也许有一些属性可以阅读很好,如果它工作的话-但是我把代码放在哪里了?有可能把添加日期/时间放在哪里吗?这必须放在
build.gradle
中。我已经在我的答案中添加了一个每日计数器。有没有任何对话框我可以把一些文本放在文件中?当你打开Android Studio时,文件就在这个对话框中左侧。在Java文件下方,有一个名为Gradle Scripts
的类别。如果扩展该类别,则有两个build.Gradle
文件。选择一个显示为Module:xy
的文件。将我的答案中的代码添加到块defaultConfig
。不,我的意思是在每次生成时都向文件添加一些文本:)此答案必须已更新,而不是发布新答案(关于同一问题),该答案已更新。