我有一个具有多种构建风格的应用程序。我的主要 AndroidManifest.xml 的一部分如下所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="some.test.app"
android:installLocation="auto"
android:versionCode="36"
android:versionName="v1.0.3" >
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="17" />
<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name=".MyApp"
android:icon="@drawable/app_logo"
android:label="@string/app_name" >
<!-- possible values: dev, demo, prod -->
<meta-data
android:name="app_build_type"
android:value="dev" />
</application>
</manifest>
特定于 flavor 的示例 (
demo
) list 如下所示:<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="some.test.app">
<application>
<meta-data
android:name="app_build_type"
android:value="demo"
tools:replace="value"/>
</application>
</manifest>
gradle 合并的结果如下所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="some.test.app"
android:versionCode="36" >
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="17" />
<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name="some.test.app.MyApp"
android:icon="@drawable/app_logo"
android:label="@string/app_name" >
<meta-data
android:name="app_build_type"
android:value="demo" />
</application>
</manifest>
如您所见,除了
manifest.installLocation
之外,大多数节点和属性都已正确合并。和 manifest.versionName
,完全消失,而 manifest.versionCode
遗迹。这是什么原因,我该如何解决?
最佳答案
我有一个 UI 应用程序和一个服务,遇到了同样的问题。当构建过程自动进行合并时,它维护版本 1.0,无论 AndroidManifest.xml 是否具有正确的版本。我的解决方案是在适当的 build.gradle 文件中添加以下两个字段:
defaultConfig {
minSdkVersion 9
targetSdkVersion 22
versionCode 664
versionName "664"
}
其中 664 是您的版本。我希望这有帮助!
关于android - Gradle list 合并丢失的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26101029/