我使用Jenkins构建我的Android Apk。在build.xml中,iam使用正则表达式替换我的目标字符串,如下所示......
<replaceregexp file="BuildConfig.java"
match="public static final boolean IS_SAMSUNG_MDM_ENABLED =\"(.*)\""
replace="public static final boolean IS_SAMSUNG_MDM_ENABLED =\"" + ${properties.IS_SAMSUNG_MDM_ENABLED} + "\"" />
但是当我通过jenkins运行构建时出现以下错误。
BUILD FAILED
/var/lib/jenkins/workspace/Ace Build/build.xml:40: The following error occurred while executing this line:
/var/lib/jenkins/workspace/Ace Build/IgnitorACE/build.xml:70: Element type "replaceregexp" must be followed by either attribute specifications, ">" or "/>".
我的正则表达式有问题......
由于
答案 0 :(得分:0)
您获得的错误似乎是因为引号("
)。您应该使用"
代替。以下示例有效:
BuildConfig.java:
public class MyFirstJavaProgram {
public static void main(String []args) {
public static final boolean IS_SAMSUNG_MDM_ENABLED = false
System.out.println("Hello World");
}
}
file.properties:
IS_SAMSUNG_MDM_ENABLED=true
的build.xml:
<project name="MyProject" default="regextask" basedir=".">
<property file="file.properties"/>
<target name="regextask">
<replaceregexp file="BuildConfig.java"
match="public static final boolean IS_SAMSUNG_MDM_ENABLED = (.*)"
replace="public static final boolean IS_SAMSUNG_MDM_ENABLED = "${IS_SAMSUNG_MDM_ENABLED}""
/>
</target>
</project>
输出:
public class MyFirstJavaProgram {
public static void main(String []args) {
public static final boolean IS_SAMSUNG_MDM_ENABLED = "true"
System.out.println("Hello World");
}
}