manifestPlaceholders值不是字符串 [英] manifestPlaceholders value is not string
问题描述
在我的AndroidManifest.xml文件中,我具有以下应动态填充的元数据标记:
In my AndroidManifest.xml file I have the following meta-data tag which should be populated dynamically:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="${FACEBOOK_APP_ID}"/>
我的gradle文件如下:
My gradle file looks like this:
manifestPlaceholders = [
GOOGLE_PROJECT_ID: "A888844613784",
FACEBOOK_APP_ID: "888570042741264"
]
清单文件中的"FACEBOOK_APP_ID"构建并组装"后,如下所示:
After "Build & Assemble" the FACEBOOK_APP_ID in the manifest file looks like this:
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="1481023616.000000" />
不幸的是,这不是字符串,而是浮点值.那是不正确的或我想要的.
Unfortunately this is not a String, but a float value. That's not correct or what I want.
我知道还有另一种方法可以在string.xml
文件中定义FACEBOOK_APP_ID
.但是,由于我有很多口味,因此,如果将所有与口味相关的参数放在build.gradle
文件而不是strings.xml
文件中,则将很容易维护.
I know there is another way to define the FACEBOOK_APP_ID
in the string.xml
file. But since I have lots of flavors it would be nice and easy to maintain if we put all flavors-related parameters in the build.gradle
file instead of the strings.xml
files.
有人知道如何避免字符串进行浮点转换吗?
Does anyone know how to avoid the string to float conversion?
推荐答案
您可以使用以下代码从build.gradle文件向字符串资源添加字符串值:
You can use the following code to add a String value to your string resources from a build.gradle file:
resValue 'string', 'FACEBOOK_APP_ID', 'facebook_application_id'
但是我不确定AndroidManifest.xml文件是否不支持风味特定的字符串(我记得您尝试时会收到警告,但我不确定).
But I'm not sure if the AndroidManifest.xml file does not support flavor specific strings (I can remember you will get a warning if you try, but I'm not sure).
您还可以尝试按照此答案中的建议,将空终止符添加到FACEBOOK_APP_ID manifestPlaceholder中.
You could also try to add a null-terminator to your FACEBOOK_APP_ID manifestPlaceholder as suggested in this answer:
FACEBOOK_APP_ID: "888570042741264\0"
直接从build.gradle文件使用时,代码null-terminator方法似乎不起作用,但是当在AndroidManifest.xml
文件中使用null-terminator时,它确实起作用:
The code null-terminator method seems not to be working when used directly from the build.gradle file, it does however work when using the null-terminator inside the AndroidManifest.xml
file:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="${FACEBOOK_APP_ID}\0"/>
这篇关于manifestPlaceholders值不是字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!