在渠道打包中,常常有這種需要不同渠道使用不同的啟動Activity的需求
這里有兩種方案,其中第二種是工作中使用的最佳方案
第一種方案
先說明下出現(xiàn)的問題,如果在flavor中再建一個(gè)目錄,配置Manifest.xml,設(shè)置為下面的話
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
測試發(fā)現(xiàn),安裝一個(gè)app會出現(xiàn)兩個(gè)啟動Activity在桌面(用戶也是一下安裝兩個(gè)不同App哎)
但是我們只需要一個(gè),且合并時(shí)候是根據(jù)Activity的name合并的,flavor和main定義同包同類 工具會報(bào)錯(cuò),定義不同類合并后又出現(xiàn)了兩個(gè),而我試過 tools:replace又是各種不行,最后只能想到用此方法,雖然name里面配置占位符 工具顯示紅叉,但是不影響運(yùn)行。
<activity
android:name="${XX}"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
signingConfigs {
debug {
storeFile file("../syntc-debug.jks")
storePassword 'syntcstudio'
keyAlias 'ruulaitv'
keyPassword 'ruulaitv'
}
release {
storeFile file("../syntc-debug.jks")
storePassword 'syntcstudio'
keyAlias 'ruulaitv'
keyPassword 'ruulaitv'
}
}
defaultConfig {
applicationId "com.example.ruulai.test"
minSdkVersion 11
targetSdkVersion 18
versionCode 1
versionName "1.0"
manifestPlaceholders = [
UMENG_CHANNEL_VALUE: "abcd",
XX : "com.example.ruulai.test.MainActivity"
]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.debug
}
}
// lintOptions {
// checkReleaseBuilds false
// // Or, if you prefer, you can continue to check for errors in release builds,
// // but continue the build even when errors are found:
// abortOnError false
// }
// productFlavors {
//
// wandoujia {}
// baidu {}
// c360 {}
// uc {}
//
// productFlavors.all { flavor ->
// flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
// }
//
// }
productFlavors {
wandoujia {
applicationIdSuffix ".wandoujia"
manifestPlaceholders = [
UMENG_CHANNEL_VALUE: "wandoujia",
XX : "com.example.ruulai.test.MainActivity"
]
}
baidu {
applicationIdSuffix ".baidu"
manifestPlaceholders = [
UMENG_CHANNEL_VALUE: "baidu",
XX : "com.ext.ruu.BaiduActivity"
]
}
uc {
applicationIdSuffix ".uc"
manifestPlaceholders = [
UMENG_CHANNEL_VALUE: "uc",
XX : "com.ext.ruu.BaiduActivity"
]
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.packetzoom:pz-okhttp3-interceptor:3.2.7'
}
第二種方案(給個(gè)贊哦)
<activity
android:name=".activity.MainActivity"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
tools:node="merge">
<intent-filter tools:node="remove">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
然后使用新的Activity作為 啟動Activity(類名隨意)
<activity android:name=".NewActicity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
是不是簡單的粗暴