Jenkins 通過Gradle對Android實現持續整合
阿新 • • 發佈:2018-11-15
Gradle 編譯打包越來越受歡迎,特別是在安卓端,如何實現GitLab、Jenkins 、Gradle、fir工具完成版本、編譯、打包、釋出流程。
Jenkins配置 Git
Gradle構建環境配置
Gradle build.gradle配置檔案
apply plugin: 'com.android.application' Properties properties = new Properties() properties.load(project.rootProject.file('gradle.properties').newDataInputStream()) android { signingConfigs { config { keyAlias 'androiddebugkey' keyPassword 'android' storeFile file('../debug.keystore') storePassword 'android' } } compileSdkVersion COMPILE_SDK_VERSION buildToolsVersion BUILD_TOOLS_VERSION defaultConfig { applicationId "com.xgj.android" minSdkVersion MIN_SDK targetSdkVersion TARGET_SDK_VERSION versionCode PUBLISH_VERSION_CODE versionName PUBLISH_VERSION compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } // 刪除無用的語言資源 resConfigs "zh" multiDexEnabled true } buildTypes { release { // 是否開啟混淆 minifyEnabled false // 是否優化apk檔案,將apk檔案中未壓縮的資料在4個位元組邊界上對齊 zipAlignEnabled true // 是否去除無用資源,任何在編譯過程中沒有用到的資源或者程式碼都會被刪除,可以有效減小apk體積 shrinkResources false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-xgj.pro' signingConfig signingConfigs.config } debug { minifyEnabled false zipAlignEnabled true shrinkResources false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-xgj.pro' signingConfig signingConfigs.config } // 修改包名 applicationVariants.all { variant -> variant.outputs.all { output -> def newApkName = versionTag() + "_" + variant.productFlavors[0].name + ".apk" outputFileName = new File(newApkName) } } } dexOptions { javaMaxHeapSize "4g" } packagingOptions { exclude 'META-INF/MANIFEST.MF' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' exclude 'META-INF/DEPENDENCIES' } lintOptions { abortOnError false disable 'MissingTranslation' checkReleaseBuilds false ignoreWarnings true } flavorDimensions 'debug' productFlavors { xgj_debug { dimension "debug" versionName = PUBLISH_VERSION + "_debug" System.out.println("debug " + versionName) //配置資訊 manifestPlaceholders = [RONG_CLOUD_APP_KEY_VALUE: properties.getProperty("rongcloudappkey.debug"), JPUSH_KEY_VALUE : properties.getProperty("jpushkey.debug"), UMENG_KEY_VALUE : properties.getProperty("umengkey.debug"), BAIDU_KEY_VALUE : properties.getProperty("baidumap.debug") ] buildConfigField "String", "SERVER_URL", properties.getProperty("serverurl.debug") buildConfigField "String", "CUSTOM_ID", properties.getProperty("custom.debug") buildConfigField "String", "ENCODE_KEY", properties.getProperty("encode.key") buildConfigField "String", "ZHICHI_CUSTOM_ID", properties.getProperty("zhichi_custom.debug") buildConfigField "String", "RYKEY", properties.getProperty("rongyunappkey.debug") buildConfigField "String", "RYSecret", properties.getProperty("rongyunSecret.debug") } xgj_release { dimension "debug" versionName = PUBLISH_VERSION + "_release" System.out.println("dev " + versionName) //配置資訊 manifestPlaceholders = [RONG_CLOUD_APP_KEY_VALUE: properties.getProperty("rongcloudappkey.release"), JPUSH_KEY_VALUE : properties.getProperty("jpushkey.release"), UMENG_KEY_VALUE : properties.getProperty("umengkey.release"), BAIDU_KEY_VALUE : properties.getProperty("baidumap.release") ] buildConfigField "String", "SERVER_URL", properties.getProperty("serverurl.release") buildConfigField "String", "ENCODE_KEY", properties.getProperty("encode.key") buildConfigField "String", "CUSTOM_ID", properties.getProperty("custom.release") buildConfigField "String", "ZHICHI_CUSTOM_ID", properties.getProperty("zhichi_custom.release") buildConfigField "String", "RYKEY", properties.getProperty("rongyunappkey.release") buildConfigField "String", "RYSecret", properties.getProperty("rongyunSecret.release") } } } //按日期生成的包名 def versionTag() { return PUBLISH_VERSION_CODE + "_xgj3.0.3" } dependencies { implementation 'com.android.support.constraint:constraint-layout:1.0.2' compile fileTree(include: '*.jar', dir: 'libs') //依賴專案 compile project(':Rong_Cloud_v2_6_10') compile project(':RecordVideo') compile project(':swipebackhelper') compile project(':PLDroidStreaming') compile project(':vitamio') //支援庫 //三方sdk compile files('libs/alipaySingle-20161222.jar') compile files('libs/baidumapapi_base_v3_6_1.jar') compile files('libs/baidumapapi_cloud_v3_6_1.jar') compile files('libs/baidumapapi_map_v3_6_1.jar') compile files('libs/baidumapapi_radar_v3_6_1.jar') compile files('libs/baidumapapi_search_v3_6_1.jar') compile files('libs/baidumapapi_util_v3_6_1.jar') compile files('libs/locSDK_6.13.jar') compile files('libs/jpush-android-2.1.7.jar') compile files('libs/zxing.jar') compile files('libs/SocialSDK_QQ_Full.jar') compile files('libs/SocialSDK_Sina_Simplify.jar') compile files('libs/SocialSDK_WeiXin_Full.jar') compile files('libs/umeng_shareboard_widget.jar') compile files('libs/umeng_social_api.jar') compile files('libs/umeng_social_net.jar') compile files('libs/umeng_social_shareboard.jar') compile files('libs/umeng_social_shareview.jar') compile files('libs/mta-sdk-1.6.2.jar') compile files('libs/open_sdk_r5756_lite.jar') compile files('libs/libammsdk.jar') compile files('libs/umeng-analytics-v5.6.7.jar') //http 補充包 compile files('libs/httpmime-4.1.3.jar') compile files('libs/httpclient-4.5.2.jar') compile files('libs/httpclient-cache-4.5.2.jar') compile files('libs/httpclient-win-4.5.2.jar') compile files('libs/httpcore-4.4.4.jar') //資料庫 compile files('libs/greendao-1.3.7.jar') //json解析 // compile project(':netty') compile "com.android.support:recyclerview-v7:$SUPPORT_LIB_VERSION" compile "com.android.support:design:$SUPPORT_LIB_VERSION" compile "com.github.bumptech.glide:glide:$GLIDE" compile 'com.commit451:PhotoView:1.2.4' compile "com.google.code.gson:gson:$GSON" compile 'joda-time:joda-time:2.9.4' compile 'com.qiniu:qiniu-android-sdk:7.2.3' compile 'org.greenrobot:eventbus:3.0.0' compile 'org.xutils:xutils:3.3.38' compile 'com.android.support:multidex:1.0.1' compile 'com.lcodecorex:tkrefreshlayout:1.0.7' compile 'com.youth.banner:banner:1.4.9' compile 'io.reactivex.rxjava2:rxjava:2.0.7' compile 'io.reactivex.rxjava2:rxandroid:2.0.1' }
釋出Fir