用于android包名称的ant正则表达式 [英] ant regex for android package names

查看:19
本文介绍了用于android包名称的ant正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 android 项目中,我所有的 .java 视图文件都根据当前包的名称导入 R 文件.当我在 Android Manifest 中更改我的包名称时(动态地,不是通过 Eclipse 或任何其他 IDE 重构),我需要我所有的 java 文件的引用指向生成的新 R 文件

in my android project all of my .java view files import the R file based on the name of the current package. When I change the name of my package name in the Android Manifest (dynamically, not refactoring via Eclipse or any other IDE), I need to the references of all my java files to point to the new R file that gets generated

我正在通过 Ant 制作构建脚本,但我不确定正则表达式约定会是什么样子

I am making a build script via Ant, but I am not sure what the regular expression convention would look like

需要替换的字符串如下所示:

The strings that need to be replaced look like this:

import com.mysite.myapp.R;

即.

import com.sushiroll.california.R

这就是我的 ant 构建脚本中的内容

This is what I have in my ant build script

<replaceregexp file="src/*"
           match="import*.R"
           replace="import ${current.package}.R"
           byline="true">
        <fileset dir="src/.">
            <include name="*.java"/>
        </fileset>
</replaceregexp>

我想匹配所有显示 import 并以 .R

where I want to match all strings that say import and end in .R

并将其替换为 import $current.package}.R

对于 ant 正则表达式,我该怎么说呢?我写的匹配和替换只是猜测

how would I word that for ant regex? the match and replace that I wrote were just guesses

推荐答案

你需要在 .R 之前将旧的包名字符分组

You need to group old package name chars before .R

如果你知道包名

    match="import com\.mysite\.myapp\.R;"

如果你现在知道包名,但如果你从不同的包导入 R,准备好因错误导入而失败

if you do now know package name, but be prepared to be failed for wrong imports if you import R from different packages

    match="import (.*).R;"

替换为

replace="import ${current.package}.R;"

    <fileset dir="src">
        <include name="**/*.java"/>
    </fileset>

这篇关于用于android包名称的ant正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆