0

我们有一个活动菜单,允许 beta 用户在多个测试/暂存数据库/REST 服务器之间切换。在发布时,我想删除这个菜单甚至不被看到。我不希望代码中的变量必须手动修改。我希望我们的 CI 为我做这件事。只是不确定动态构建以删除它的最佳方法。我正在考虑在清单中添加 debuggable ,然后当 Jenkins 构建它以进行发布时,它将 manifest debuggable 更改为 false ,这反过来代码将对用户隐藏菜单。这是最好的方法还是有更好的方法?(也许在清单中使用 testOnly?)

4

1 回答 1

0

目前我在清单中使用 debuggable 属性,该属性最初没有在文件中设置,因为 Eclipse 对此不满意。然后在我的 ant 脚本中,我创建了一个 custom_rules.xml,在其中我根据目标手动设置清单中的属性,如果发布则为 false,如果调试版本则为 true。

<target name="-set-debug-files" depends="-set-mode-check">
.....
    <!-- alter the app manifest to reflect the testing state -->
    <property name="match.start" value="android:debuggable="/>
    <property name="match.end" value=">"/>
    <replaceregexp file="AndroidManifest.xml"
               match="${match.start}.*${match.end}"
               replace="${match.start}&quot;true&quot;${match.end}">
    </replaceregexp>

    <echo level="info">${ant.project.name} 
        setting manifest debug state to true</echo>
</target>

<target name="-set-release-mode" depends="-set-mode-check">
......
    <property name="match.start" value="android:debuggable="/>
    <property name="match.end" value=">"/>
    <replaceregexp file="AndroidManifest.xml"
               match="${match.start}.*${match.end}"
               replace="${match.start}&quot;false&quot;${match.end}">
    </replaceregexp>

    <echo level="info">${ant.project.name} 
         setting manifest debug state to false</echo>

</target>

然后在我放置在我的自定义应用程序类中的代码中,我创建了一个可以在我的活动中引用的静态。

DEBUG = (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;

然后当我需要隐藏/显示我使用的东西时:

if (MyApplication.DEBUGGABLE) {
    ...show stuff
} else {
    ...hide stuff
}
于 2013-07-18T19:45:36.287 回答