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

时间:2018-08-08 06:58:03

标签: android facebook android-manifest

我在Facebook中定义了我的App的2个版本(产品版本和登台版本):

enter image description here

在清单中,我具有以下官方设置:

<!-- 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" />

在我的Gradle中:

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

在我的Gradle.properties中:

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

因此,在项目构建期间,如何才能轻松切换到facebook App prod <->暂存阶段,因为当前它已固定为总是prod版本(请参见清单摘录)。

非常感谢你们!

1 个答案:

答案 0 :(得分:2)

您可以通过这种方式在应用enum文件中移动属性。

// my custom class
class BoolOption {
public:
    BoolOption(bool initialState = false) : state(initialState) {}
    bool getState() const {return state;}
    void switchState() {state = !state;}
private:
    bool state;
};

// two variables
BoolOption test1;
BoolOption test2;

// validate
void validate(boost::any &v, std::vector<std::string> const &xs, BoolOption*, long)
{
    if (v.empty()) {
        v = BoolOption(true); // I don't know how to assign default here so this works only when default is false
    } else {
        boost::any_cast<BoolOption&>(v).switchState();
    }
}

optionsDescription->add_options()
        ("test1,t", po::value<BoolOption>(&test1)->default_value(BoolOption(true), "true")->zero_tokens(), "")
        ("test2,T", po::value<BoolOption>(&test2)->default_value(BoolOption(false), "false")->zero_tokens(), "")
;

// output result
cout << test1.getState() << endl;
cout << test2.getState() << endl;

然后在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"]
    }
}

如果您想执行更多高级配置,则可以阅读更多here有关配置构建变体的信息。