0

Gradle ビルド Android を使用したい。すべての appStores にほぼ 100 個の apk があります。唯一の違いは、assets/config.properties ファイルです。

Ant スクリプト:

<target name="makechannelidapk">
    <propertyregex property="channel_id" input="${line_content}" regexp="(.*)," select="\1"/>
    <delete file="${asset-dir}/config.properties" />
    <echo file="${asset-dir}/config.properties"CHANNEL_ID=${channel_id}</echo>

    <antcall target="finalmake" >
        <param name="id" value="${client_source}"/>
    </antcall>
</target>
4

1 に答える 1

0

メタデータを使用する

AndroidManifest.xml

<meta-data android:value="${CHANNEL_VALUE}" android:name="CHANNEL"/>

build.gradle

    android {
    defaultConfig {
        ...
        // default CHANNEL_VALUE
        manifestPlaceholders = [CHANNEL_VALUE: "default"]
    }
    productFlavors {
        fir{}
        wandoujia{}
        qihu360{}
        baidu{}
        xiaomi{}
        uc{}
        productFlavors.all{
            flavor->flavor.manifestPlaceholders = [CHANNEL_VALUE: name]
        }
    }
}

メタデータを取得する

try {
    ApplicationInfo ai = getPackageManager().getApplicationInfo(activity.getPackageName(), PackageManager.GET_META_DATA);
    Bundle bundle = ai.metaData;
    String myApiKey = bundle.getString("CHANNEL");
} catch (NameNotFoundException e) {
    Log.e(TAG, "Failed to load meta-data, NameNotFound: " + e.getMessage());
} catch (NullPointerException e) {
    Log.e(TAG, "Failed to load meta-data, NullPointer: " + e.getMessage());         
}
于 2015-10-22T09:35:53.483 に答える