0

我们的活动菜单允许测试版用户在多个测试/临时数据库/ REST服务器之间切换。在发布时,我想从看到的菜单中删除这个菜单。我不想在代码中使用我必须手动修改的变量。我希望我们的CI为我做这件事。只是不确定动态构建以消除此问题的最佳方式。我正在考虑在清单中添加可调试项,然后当Jenkins构建它时,它会将可调试清单更改为false,然后代码将隐藏用户的菜单。这是最好的方式还是有更好的方法? (可能在清单中使用testOnly)为我们的测试版测试人员启用的功能,发布如何删除

回答

0

目前,我在清单中使用debuggable属性,它最初并未在文件中设置,因为Eclipse在此上皱眉。然后,在我的ant脚本中,我创建了一个custom_rules.xml,其中我根据目标手动设置清单中的属性,如果释放并且如果调试版本为true,则为false。

<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 
} 
相关问题