本文介绍了我如何可以访问我的Andr​​oidManifest.xml文件一BuildConfig价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能从AndroidManifest.xml中访问BuildConfig值?

Is it possible to access a BuildConfig value from AndroidManifest.xml?

在我build.gradle文件,我有:

In my build.gradle file, I have:

defaultConfig {
    applicationId "com.compagny.product"
    minSdkVersion 16
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"

    // Facebook app id
    buildConfigField "long", "FACEBOOK_APP_ID", FACEBOOK_APP_ID
}

FACEBOOK_APP_ID 在我gradle.properties文件中定义:

FACEBOOK_APP_ID is defined in my gradle.properties files:

# Facebook identifier (app ID)
FACEBOOK_APP_ID=XXXXXXXXXX

要使用Facebook Connect在我的应用程序,我必须将此行添加到我的Andr​​oidManifest.xml:

To use Facebook connect in my app, I must add this line to my AndroidManifest.xml:

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/applicationId"/> 

我要替换的摇篮 @字符串/的applicationID 由BuildConfig领域 FACEBOOK_APP_ID 定义的,就像这样:

I want to replace @string/applicationId by the BuildConfig field FACEBOOK_APP_ID defined in gradle, like this:

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="FACEBOOK_APP_ID"/> 

这是可能的使用BuildConfig?如果没有,我怎么能做到这一点?

Is that possible using BuildConfig? If not, how can I achieve this?

推荐答案

替换

buildConfigField "long", "FACEBOOK_APP_ID", FACEBOOK_APP_ID

resValue "string", "FACEBOOK_APP_ID", FACEBOOK_APP_ID

这两个命令都产生生成的类 - 包括Java的常数在第一种情况下,在第二Android的资源 - 但第二个方法将生成一个字符串资源价值可以使用 @字符串/ FACEBOOK_APP_ID 语法来访问。这意味着它可以在清单以及在code可以使用

The two commands both produce generated classes - consisting of Java constants in the first case, and Android resources in the second - but the second method will generate a string resource value that can be accessed using the @string/FACEBOOK_APP_ID syntax. This means it can be used in the manifest as well as in code.

这篇关于我如何可以访问我的Andr​​oidManifest.xml文件一BuildConfig价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 18:54