มีหลายวิธีที่คุณสามารถทำได้
คุณสามารถสร้างmanifestPlaceholders หรือ ในระดับแอปresValue build.gradleเช่น
buildTypes {
release {
...
manifestPlaceholders = [appLabel: "My App"]
//resValue "string", "appLabel", '"My App"'
}
debug {
...
manifestPlaceholders = [appLabel: "My App - Debug"]
//resValue "string", "appLabel", '"My App - Debug"'
}
}
หรือ
หากคุณมีproductFlavorsคุณสามารถสร้างที่นั่นได้
flavorDimensions "env"
productFlavors {
dev {
dimension "env"
...
manifestPlaceholders = [appLabel: "My App - Development"]
//resValue "string", "appLabel", '"My App - Development"'
}
prod {
dimension "env"
...
manifestPlaceholders = [appLabel: "My Awesome App"]
//resValue "string", "appLabel", '"My Awesome App"'
}
}
จากนั้นAndroidManifest.xmlหากคุณกำลังใช้manifestPlaceholdersงานอยู่ให้เปลี่ยนandroid:label="${appLabel}"ตามด้านล่างหรือหากคุณกำลังใช้อยู่resValueก็แค่เปลี่ยนandroid:label=@string/appLabel
<application
...
android:label="${appLabel}"> //OR `android:label=@string/appLabel`
<activity
...
android:label="${appLable}">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
หมายเหตุ:ให้แน่ใจว่ามีการเปลี่ยนแปลงandroid:lableเช่นกันใน<activity>ของLAUNCHERหมวดหมู่ หากไม่จำเป็นต้องใช้android:labelใน<activity>ให้ลบสิ่งนี้ออก
หากคุณไม่ต้องการเพิ่มbuild.gradleโดยตรงคุณสามารถเพิ่มในรายการที่values/string.xmlเลือกProductFlavorsได้ เช่น
เพิ่ม
<string name="appLabel">My App - Development</string>
ใน app/src/dev/res/values/string.xml
และ
<string name="appLabel">My Awesome App</string>
ใน app/src/prod/res/values/string.xml