Reputation: 760
Is something like this possible?
<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: Application package '@string/package_name' must have a minimum of 2 segments.
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>
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?
Edit: Is there any way to use a package name specified in external file?
Upvotes: 11
Views: 4602
Reputation: 1887
@Lev I know its very late, but it may help others.
I am also wanted to use @string/package_name
in some cases.
I am getting it done by creating string resource in app/build.gradle
like below.
defaultConfig {
// your other code
applicationId 'com.example'
resValue "string", "package_name", applicationId
// your other code
}
Upvotes: 3
Reputation: 82543
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
).
As package is not defined in the android schema, it cannot access resources that way, while versionName can.
Upvotes: 8