我可以使用资源字符串作为包名称吗? [英] Can I use a resource string for a package name?

查看:63
本文介绍了我可以使用资源字符串作为包名称吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这样的事情有可能吗?

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="@string/package_name"
      android:versionCode="1"
      android:versionName="@string/version_name">

上面的代码给了我一个错误:

The code above gives me an error:

C:\android-sdk\tools\ant\build.xml:539:应用包'@string/package_name' 必须至少有 2 个段.

C:\android-sdk\tools\ant\build.xml:539: Application package '@string/package_name' must have a minimum of 2 segments.

我的字符串在 res/strings.xml 中定义如下:

My strings are defined in res/strings.xml like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">My app</string>
    <string name="version_name">1.00</string>
    <string name="package_name">com.mycompany.myapp</string>

如果我将 @string/package_name 替换为包的名称,android:versionName 似乎设置正确.
所以问题是为什么包名在 android:versionName 工作时不起作用?

If I replace @string/package_name with the name of the package, android:versionName seems to be set correctly.
So the question is why package name doesn't work while android:versionName works?

有没有办法使用外部文件中指定的包名?

Is there any way to use a package name specified in external file?

推荐答案

AFAIK,对于 android 中定义的属性,您只能使用 @resource/name 格式访问 XML 资源代码> xmlns (http://schemas.android.com/apk/res/android).

AFAIK, you may only access XML resources using the @resource/name format for attributes defined in the android xmlns (http://schemas.android.com/apk/res/android).

由于包没有在 android 架构中定义,它不能以这种方式访问​​资源,而 versionName 可以.

As package is not defined in the android schema, it cannot access resources that way, while versionName can.

这篇关于我可以使用资源字符串作为包名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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