简体   繁体   English

我的Android项目中具有暂存和产品版本的Facebook设置

[英]Facebook setup with staging and prod version in my Android project

I have 2 versions of my App defined into Facebook (a prod version and a staging version): 我在Facebook中定义了我的App的2个版本(prod版本和staging版本):

在此处输入图片说明

In the manifest I have this official setup: 在清单中,我具有以下官方设置:

<!-- https://developers.facebook.com/docs/android/getting-started -->
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            tools:replace="android:value"
            android:value="@string/facebook_app_id" />

In my Gradle: 在我的Gradle中:

// Facebook app id
        resValue "string", "facebook_app_id", FACEBOOK_APP_ID
        resValue "string", "facebook_app_id_staging", FACEBOOK_APP_ID_STAGING

In my Gradle.properties: 在我的Gradle.properties中:

# Facebook identifier (app ID)
FACEBOOK_APP_ID="XXXXXXXX"
FACEBOOK_APP_ID_STAGING="YYYYYYYY"

So how can I switch to facebook App prod <-> staging easily during the project building, because currently it's fixed to always prod version (see the manifest extract). 因此,如何在项目构建过程中轻松切换到facebook App prod <->暂存,因为当前它已固定为总是prod版本(请参见清单摘录)。

Thank you very much guys! 非常感谢你们!

You can move the properties inside the app build.gradle file in this way. 您可以通过这种方式在应用程序build.gradle文件内移动属性。

defaultConfig {
    //this will be valid for release and debug buildTypes
    manifestPlaceholders = [facebook_app_id:"RELEASE_KEY_XXXX"]
    ...
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    staging {
        initWith debug
        manifestPlaceholders = [facebook_app_id:"STAGING_KEY_XXXX"]
    }
}

In the AndroidManifest.xml then you can use the placeholder: AndroidManifest.xml您可以使用占位符:

<meta-data
     android:name="com.facebook.sdk.ApplicationId"
     tools:replace="android:value"
     android:value="${facebook_app_id}" />

You can read more here about configuring build variants if you want to perform more advanced configurations 如果要执行更高级的配置,可以在此处阅读有关配置构建变体的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM