问题描述
在我的应用级 build.gradle 中,我有以下风格:
In my app-level build.gradle I have the following flavors:
productFlavors {
originalFlavour{
}
freeFlavour{
}
}
事情正在构建两种风格,我获得了相同的应用程序名称.相反,我希望每种口味都有不同的应用程序名称.只需添加一个后缀就会很有用.希望有人能帮助我.
The thing is building both flavors I get the same App Name. Instead I would like to have different app names for each flavors. Just adding a suffix would be useful. Hope someone could help me.
提前致谢
编辑:
app/src/main/AndroidManifest.xml
app/src/main/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="z.fncapps.etsiipod" >
<uses-permission
android:name="android.permission.CALL_PHONE"
android:required="false" />
<uses-feature
android:name="android.hardware.telephony"
android:required="false"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- actvities declared here -->
</application>
</manifest>
app/src/freeFlavour/AndroidManifest.xml
app/src/freeFlavour/AndroidManifest.xml
<uses-permission
android:name="android.permission.CALL_PHONE"
android:required="false" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- actvities declared here -->
</application>
推荐答案
从现有的 strings.xml
文件中删除 app_name
字符串,然后你可以这样做:
Remove the app_name
string from your existing strings.xml
file, then you can do this:
productFlavors {
originalFlavour{
resValue "string", "app_name", "Original Flavor Name"
}
freeFlavour{
resValue "string", "app_name", "Free Flavor Name"
}
}
然后,清单中对 @string/app_name
的现有引用将引用生成的字符串资源,该资源基于所选的风格.
Then the existing reference to @string/app_name
in your manifest will refer to a generated string resource, which is based on the flavor selected.
请注意,如果您为启动 Activity 指定标签(通过在 <activity>
元素中定义 android:label
xml 标记),该值将是用于许多用户可见的地方而不是应用程序的标签.为了解决这个问题,您可以完全从 元素中删除标签.请参阅https://stackoverflow.com/a/13200774/2911458了解有关此区别的更多详细信息.
Note that if you specify a label for your launch Activity (by defining the android:label
xml tag in the <activity>
element), that value will be used in many user-visible places rather than your application's label. To overcome this for your case, you can just remove the label from your <activity>
element altogether. See https://stackoverflow.com/a/13200774/2911458 for more details on this distinction.
这篇关于如何在 Android Studio 中使用具有不同应用名称的风味?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!