manifestPlaceholders value is not string

别说谁变了你拦得住时间么 提交于 2019-12-04 15:38:10
Rolf ツ

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'

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).

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"

Edit:

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"/>
Taib Lokman

I use manifestPlaceholders and force gradle to recognize the string by escaping the quotes like so: manifestPlaceholders = [facebook_app_id:"\"9999000099990000\"", fb_login_protocol_scheme:"fb9999000099990000"]

You don't need to it for the second param since it has the string fb in front.

This is working for me (if you do not use flavors, just put resValue into defaultConfig):

productFlavors {
    production {
        resValue 'string', 'facebookAppId', '22222222222'
        resValue 'string', 'facebookSchemeId', 'fb22222222222'
    }

    development {
        resValue 'string', 'facebookAppId', '11111111111'
        resValue 'string', 'facebookSchemeId', 'fb11111111111'
    }
}

Then in manifest:

    <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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!