Android manifestPlaceholders值不是字符串
在我的AndroidManifest.xml文件中,我有以下应动态填充的元数据标记:Android manifestPlaceholders值不是字符串,android,android-manifest,build.gradle,android-flavors,Android,Android Manifest,Build.gradle,Android Flavors,在我的AndroidManifest.xml文件中,我有以下应动态填充的元数据标记: <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="${FACEBOOK_APP_ID}"/> 在“构建和组装”之后,清单文件中的FACEBOOK应用程序ID如下所示: manifestPlaceholders = [ GOOGLE_PROJECT_ID: "A8888446
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="${FACEBOOK_APP_ID}"/>
在“构建和组装”之后,清单文件中的FACEBOOK应用程序ID如下所示:
manifestPlaceholders = [
GOOGLE_PROJECT_ID: "A888844613784",
FACEBOOK_APP_ID: "888570042741264"
]
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="1481023616.000000" />
不幸的是,这不是一个字符串,而是一个浮点值。这是不对的,也不是我想要的
我知道还有另一种方法可以在string.xml
文件中定义FACEBOOK\u APP\u ID
。但是由于我有很多风格,如果我们将所有风格相关的参数放在build.gradle
文件中,而不是strings.xml
文件中,这将是一件非常好的事情,并且很容易维护
有人知道如何避免字符串到浮点的转换吗?您可以使用以下代码从build.gradle文件向字符串资源添加字符串值:
resValue 'string', 'FACEBOOK_APP_ID', 'facebook_application_id'
但是我不确定AndroidManifest.xml文件是否不支持特定于味道的字符串(我记得如果您尝试,您会得到警告,但我不确定)
您也可以尝试将空终止符添加到您的FACEBOOK_APP_ID占位符,如回答中所建议:
编辑:
直接从build.gradle文件使用时,代码null终止符方法似乎不起作用,但在AndroidManifest.xml
文件中使用null终止符时,它确实起作用:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="${FACEBOOK_APP_ID}\0"/>
我使用manifestPlaceholder并通过转义引号强制gradle识别字符串,如下所示:
manifestPlaceholders=[facebook\u应用程序\u id:“9999009990000\”,
fb\u登录\u协议\u方案:“FB9999009990000”]
您不需要为第二个参数使用它,因为它前面有字符串fb
。这对我有用(如果您不使用flavors,只需将resValue放入defaultConfig):
然后在舱单中:
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebookAppId" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/facebookSchemeId" />
</intent-filter>
</activity>
谢谢。resValue工作,没有警告。但是FACEBOOK应用程序ID:“888570042741264\0”不起作用。谢谢Rolf,现在android:value=“${FACEBOOK应用程序ID}\0”也起作用了。你真棒!“${FACEBOOK\u APP\u ID}\0”似乎不起作用(再也不起作用了?)
productFlavors {
production {
resValue 'string', 'facebookAppId', '22222222222'
resValue 'string', 'facebookSchemeId', 'fb22222222222'
}
development {
resValue 'string', 'facebookAppId', '11111111111'
resValue 'string', 'facebookSchemeId', 'fb11111111111'
}
}
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebookAppId" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/facebookSchemeId" />
</intent-filter>
</activity>