manifestPlaceholders value is not string
在我的AndroidManifest.xml文件中,我具有以下应动态填充的元数据标记:
1 | <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="${FACEBOOK_APP_ID}"/> |
我的gradle文件如下所示:
1 2 3 4 | manifestPlaceholders = [ GOOGLE_PROJECT_ID:"A888844613784", FACEBOOK_APP_ID:"888570042741264" ] |
在"构建并组装"清单文件后,FACEBOOK_APP_ID如下所示:
1 2 3 | <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="1481023616.000000" /> |
不幸的是,这不是字符串,而是浮点值。 那是不正确的或我想要的。
我知道在
有谁知道如何避免将字符串转换为浮点数?
您可以使用以下代码从build.gradle文件向字符串资源添加字符串值:
1 | resValue 'string', 'FACEBOOK_APP_ID', 'facebook_application_id' |
但是我不确定AndroidManifest.xml文件是否不支持风味特定的字符串(我记得您尝试时会收到警告,但我不确定)。
您还可以尝试按照以下答案中的建议将空终止符添加到FACEBOOK_APP_ID manifestPlaceholder:
1 | FACEBOOK_APP_ID:"888570042741264\0" |
strike>
编辑:
直接从build.gradle文件使用时,代码null-terminator方法似乎不起作用,但是当在
1 | <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="${FACEBOOK_APP_ID}\0"/> |
我使用manifestPlaceholders并强制gradle通过转义引号来识别字符串,如下所示:
fb_login_protocol_scheme:"fb9999000099990000"]
对于第二个参数,您不需要它,因为它的前面有字符串
这对我有用(如果您不使用风味,只需将resValue放入defaultConfig中):
1 2 3 4 5 6 7 8 9 10 11 | productFlavors { production { resValue 'string', 'facebookAppId', '22222222222' resValue 'string', 'facebookSchemeId', 'fb22222222222' } development { resValue 'string', 'facebookAppId', '11111111111' resValue 'string', 'facebookSchemeId', 'fb11111111111' } } |
然后在清单中:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebookAppId" /> <activity android:name="com.facebook.CustomTabActivity" android:exported="true"> <intent-filter> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="@string/facebookSchemeId" /> </intent-filter> </activity> |