項目需求:一個項目相同的業務邏輯,要求打出不同版本的包,每個包的包名不相同。 經過資料查詢,需要在Gradle中完成一些配置即可。 1、在src目錄下添加不同版本對應的文件,以及在各個文件下面配置不同的資源文件。
2、在gradle中進行相關配置。 在PRoductFlavors下配置不同需求的包,在src下配置的文件和productFlavors下的文件需要一一對應。
3、AndroidManiFest.xml中配置極光和百度key的引用
<meta-data android:name="JPUSH_APPKEY" android:value="${JPUSH_APPKEY_VALUE}" />//極光推送<meta-data android:name="com.baidu.lbsapi.API_KEY" android:value="${BAIDU_APPKEY_VALUE}" />//百度地圖4、gradle配置的一些解釋說明
apply plugin: 'com.android.application'def releaseTime(){ return new Date().format("YYYY-MM-dd",TimeZone.getTimeZone("GMT+8"));//生成當前時間}//基礎配置android { compileSdkVersion 24//SDK編譯版本版本 buildToolsVersion "24.0.3"http://SDK編譯工具版本 defaultConfig { applicationId "com.yongnuo.mccms"http://包名,和AndroidManiFest.xml中的包名配置相同 minSdkVersion 15//最小支持版本 targetSdkVersion 21//最大支持版本 versionCode 1//版本號 versionName "1.0.0"http://版本名 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false buildConfigField "String", "RELEASETIME", "/"${releaseTime()}/""http://打包時生成的時間 } //資源文件位置配置 sourceSets { main { jniLibs.srcDirs = ['libs'] assets.srcDirs = ['assets'] } } //編譯類型 buildTypes { release {//release版本 minifyEnabled false//不混淆代碼 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug{//debug版本 minifyEnabled false//不混淆代碼 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } //不同需求的包配置 productFlavors { flavors_dev { applicationId "com.yongnuo.mccmsdev"http://不同需求的包名 manifestPlaceholders = [JPUSH_APPKEY_VALUE: "bb7dasdfd6a6c404", BAIDU_APPKEY_VALUE: "0FpzYafLyb27ZAdYiHYVj"]//第三方秘鑰配置 buildConfigField "String", "URL", "/"http://192.168.……/""http://URL地址 } flavors_prod { applicationId "com.yongnuo.mccmsprod" manifestPlaceholders = [JPUSH_APPKEY_VALUE: "1e63a8753131b78c", BAIDU_APPKEY_VALUE: "RlrA400bi0KUi"] buildConfigField "String", "URL", "/"http://192.34.……/"" } } //關閉一些編譯時的監測,防止報錯 lintOptions { abortOnError false checkReleaseBuilds false disable 'MissingTranslation' }}//jar包的依賴配置dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:24.2.1' testCompile 'junit:junit:4.12' compile 'io.reactivex:rxjava:1.2.3' compile 'io.reactivex:rxandroid:1.2.1' compile 'com.alibaba:fastjson:1.2.21' compile 'com.jakewharton:butterknife:8.4.0' compile 'com.jakewharton:butterknife-compiler:8.4.0' compile files('libs/ynksoap2.jar') compile files('libs/BaiduLBS_Android.jar') compile files('libs/tiandituapi2.2.2.jar') compile files('libs/universal-image-loader-1.9.3.jar') compile files('libs/hellocharts-library-1.5.8.jar') compile project(':MPChartLib') compile 'com.android.support:design:24.2.1'}新聞熱點
疑難解答