我可以使用资源字符串作为包名称吗?
这样的事情有可能吗?
<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.