項(xiàng)目需求:一個(gè)項(xiàng)目相同的業(yè)務(wù)邏輯,要求打出不同版本的包,每個(gè)包的包名不相同。 經(jīng)過(guò)資料查詢(xún),需要在Gradle中完成一些配置即可。 1、在src目錄下添加不同版本對(duì)應(yīng)的文件,以及在各個(gè)文件下面配置不同的資源文件。
2、在gradle中進(jìn)行相關(guān)配置。 在PRoductFlavors下配置不同需求的包,在src下配置的文件和productFlavors下的文件需要一一對(duì)應(yīng)。
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配置的一些解釋說(shuō)明
apply plugin: 'com.android.application'def releaseTime(){ return new Date().format("YYYY-MM-dd",TimeZone.getTimeZone("GMT+8"));//生成當(dāng)前時(shí)間}//基礎(chǔ)配置android { compileSdkVersion 24//SDK編譯版本版本 buildToolsVersion "24.0.3"http://SDK編譯工具版本 defaultConfig { applicationId "com.yongnuo.mccms"http://包名,和AndroidManiFest.xml中的包名配置相同 minSdkVersion 15//最小支持版本 targetSdkVersion 21//最大支持版本 versionCode 1//版本號(hào) versionName "1.0.0"http://版本名 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false buildConfigField "String", "RELEASETIME", "/"${releaseTime()}/""http://打包時(shí)生成的時(shí)間 } //資源文件位置配置 sourceSets { main { jniLibs.srcDirs = ['libs'] assets.srcDirs = ['assets'] } } //編譯類(lèi)型 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.……/"" } } //關(guān)閉一些編譯時(shí)的監(jiān)測(cè),防止報(bào)錯(cuò) lintOptions { abortOnError false checkReleaseBuilds false disable 'MissingTranslation' }}//jar包的依賴(lài)配置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'}新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注