这是对这篇文章帮助我的答案的延续
我们可以添加字符串资源,如下所示build.gradle:
Run Code Online (Sandbox Code Playgroud)productFlavors { main{ resValue "string", "app_name", "InTouch Messenger" } googlePlay{ resValue "string", "app_name", "InTouch Messenger: GPE Edition" } }
它的作用就像一个魅力,并且每个风格都有不同的app名称.(app_name从strings.xml文件中删除原始字符串资源.
但是,我们如何为这个添加的字符串资源添加本地化字符串build.gradle?
我们可以通过指定区域设置的附加参数吗?
或者
可以使用gradle任务来完成它?
注意:我不能这样做strings.xml(因为我的项目结构的几种方式不可行)
android android-resources android-studio android-gradle-plugin android-productflavors
我有 2 种构建口味,例如,flavor1 和 flavor2
我希望我的应用程序被命名为“AppFlavor1”,当我为flavor1 构建时,“AppFlavor2”当我为flavor 2 构建时
这是我的清单源代码片段
<application
android:name=".PApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".ui.activities.SplashActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
这是一个 gradle 文件的源代码片段
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
flavorDimensions "default"
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
signingConfigs {
release {
}
}
buildTypes {
release {
minifyEnabled false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors.whenObjectAdded { flavor -> …Run Code Online (Sandbox Code Playgroud) 我的应用程序有多种构建类型和风格gradle。
buildTypes {
release {}
test {}
debug {}
}
productFlavors {
europe {}
asia {}
}
Run Code Online (Sandbox Code Playgroud)
如何根据构建类型和风格的组合命名应用程序?
示例:
Flavor europe会有应用名称AppEurope
BuildType test会在应用名称后面添加“ Test ”后缀,AppEuropeTest