Jack Wang
Jack Wang

Reputation: 144

About productFlavors with gradle

I have some problem with productFlavors. For example in AndroidManifest.xml:

<meta-data android:name="UMENG_APPKEY" android:value="51a5692756240bfa33032a55" />
<meta-data android:name="UMENG_CHANNEL" android:value="Authority" />

I want to change the Authority value through productFlavors, anyone can help me?
I try to set like this but it doesn't work.

    productFlavors {
    playstore {
        packageName='com.android.newsp.playstore'
        versionCode 15
        UMENG_CHANNEL="Authority"
    }
    hiapk {
        packageName='com.android.newsp.hiapk'
        versionCode 100
        UMENG_CHANNEL="ChannelA"
    }
}

I try it, I found the mainfests don't merged as I hope. I copy two AndroidManifest.xml and change the UMENG_CHANNEL value. Then I put them in the folder:

    productFlavors {
    playstore {
        packageName='com.android.newsp.playstore'
        versionCode 15
    }
    hiapk {
        packageName='com.android.newsp.hiapk'
        versionCode 100
    }
}

sourceSets {
    hiapk {
        manifest.srcFile 'hiapk/AndroidManifest.xml'
    }
    playstore {
        manifest.srcFile 'playstore/AndroidManifest.xml'
    }
    instrumentTest.setRoot('tests')
}

Upvotes: 4

Views: 1829

Answers (1)

ligi
ligi

Reputation: 39519

manifests are merged so you could put your manifest differences in the flavors manifests

src/playstore/AndroidManifest.xml contains

 <meta-data android:name="UMENG_CHANNEL" android:value="Authority" />

and src/hiapk/AndroidManifest.xml

 <meta-data android:name="UMENG_CHANNEL" android:value="ChannelA" />

Upvotes: 1

Related Questions