build.gradle 15.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */
project.ext.react = [
        nodeExecutableAndArgs : ["/usr/local/bin/node"]
];

//project.ext.react = [
//    entryFile: "index.js"
//]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 26
    buildToolsVersion "25.0.0"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 20034
        versionName "3.3.4"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        multiDexEnabled true
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    signingConfigs {
        main {
            storeFile file('../keystores/peacemetro.jks')
            storePassword 'jfie258fkdfd'
            keyAlias 'peacemetro'
            keyPassword 'K258jfiejfj'
        }
        debug {
            storeFile file('../keystores/debug.jks')
            storePassword '123456'
            keyAlias 'key0'
            keyPassword '123456'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
        jumboMode = true
        preDexLibraries = false
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.main
        }
        debug {
            debuggable true
            minifyEnabled false  //不启用Proguard
            shrinkResources false //是否清理无用资源,依赖于minifyEnabled
            zipAlignEnabled false //是否启用zipAlign压缩
            signingConfig signingConfigs.debug
        }
    }

    // 渠道配置
    Properties pro = new Properties()
    pro.load(new FileInputStream(file("../app/sysconfig.properties")))
    productFlavors {
        //生产
        envPrd {
            applicationId = "com.douwan.peacemetro"
            manifestPlaceholders = [
                    app_name                    : "平安地铁",
                    map_key                     : "\"" +pro['MAP_KEY'] + "\""

            ]
            buildConfigField "String", "API_BASE_URL",  "\"" +pro['API_BASE_URL'] + "\""
            buildConfigField "String", "API_UPLAOD_URL",  "\"" +pro['API_UPLAOD_URL'] + "\""
            buildConfigField "String", "API_APP_KEY",  "\"" +pro['API_APP_KEY'] + "\""
            buildConfigField "String", "API_SECRET",  "\"" +pro['API_SECRET'] + "\""
            buildConfigField "String", "APP_VERSION_URL",  "\"" +pro['APP_VERSION_URL'] + "\""
            buildConfigField "String", "API_MODE",  "\"" +pro['API_MODE'] + "\""



        }
      //生产内测版
        envPrdPrivate {
            applicationId = "com.douwan.peacemetro.private"
            manifestPlaceholders = [
                    app_name                    : "平安地铁",
                    map_key                     : "\"" +pro['MAP_KEY_PRIVATE'] + "\""

            ]
            buildConfigField "String", "API_BASE_URL",  "\"" +pro['API_BASE_URL'] + "\""
            buildConfigField "String", "API_UPLAOD_URL",  "\"" +pro['API_UPLAOD_URL'] + "\""
            buildConfigField "String", "API_APP_KEY",  "\"" +pro['API_APP_KEY'] + "\""
            buildConfigField "String", "API_SECRET",  "\"" +pro['API_SECRET'] + "\""
            buildConfigField "String", "APP_VERSION_URL",  "\"" +pro['APP_VERSION_URL'] + "\""
            buildConfigField "String", "API_MODE",  "\"" +pro['API_MODE'] + "\""



        }

        //开发环境
        envDev {
            applicationId = "com.douwan.peacemetro.dev"
            versionCode getVersionCodeString("DEV").toInteger()
            versionName getVersionString("DEV").toString()
            manifestPlaceholders = [
                    app_name                    : "平安地铁",
                    map_key                     : "\"" +pro['MAP_KEY_DEV'] + "\""
            ]
            buildConfigField "String", "API_BASE_URL",  "\"" +pro['API_BASE_URL_DEV'] + "\""
            buildConfigField "String", "API_UPLAOD_URL",  "\"" +pro['API_UPLAOD_URL_DEV'] + "\""
            buildConfigField "String", "API_APP_KEY",  "\"" +pro['API_APP_KEY_DEV'] + "\""
            buildConfigField "String", "API_SECRET",  "\"" +pro['API_SECRET_DEV'] + "\""
            buildConfigField "String", "APP_VERSION_URL",  "\"" +pro['APP_VERSION_URL_DEV'] + "\""
            buildConfigField "String", "API_MODE",  "\"" +pro['API_MODE_DEV'] + "\""



        }

        //测试环境
        envTest {
            applicationId = "com.douwan.peacemetro.test"
            manifestPlaceholders = [
                    app_name                    : "平安地铁",
                    map_key                     : "\"" +pro['MAP_KEY_TEST'] + "\""

            ]
            buildConfigField "String", "API_BASE_URL",  "\"" +pro['API_BASE_URL_TEST'] + "\""
            buildConfigField "String", "API_UPLAOD_URL",  "\"" +pro['API_UPLAOD_URL_TEST'] + "\""
            buildConfigField "String", "API_APP_KEY",  "\"" +pro['API_APP_KEY_TEST'] + "\""
            buildConfigField "String", "API_SECRET",  "\"" +pro['API_SECRET_TEST'] + "\""
            buildConfigField "String", "APP_VERSION_URL",  "\"" +pro['APP_VERSION_URL_TEST'] + "\""
            buildConfigField "String", "API_MODE",  "\"" +pro['API_MODE_TEST'] + "\""



        }

        //uat环境
        envUat {
            applicationId = "com.douwan.peacemetro.uat"
            manifestPlaceholders = [
                    app_name                    : "平安地铁",
                    map_key                     : "\"" +pro['MAP_KEY_UAT'] + "\""

            ]
            buildConfigField "String", "API_BASE_URL",  "\"" +pro['API_BASE_URL_UAT'] + "\""
            buildConfigField "String", "API_UPLAOD_URL",  "\"" +pro['API_UPLAOD_URL_UAT'] + "\""
            buildConfigField "String", "API_APP_KEY",  "\"" +pro['API_APP_KEY_UAT'] + "\""
            buildConfigField "String", "API_SECRET",  "\"" +pro['API_SECRET_UAT'] + "\""
            buildConfigField "String", "APP_VERSION_URL",  "\"" +pro['APP_VERSION_URL_UAT'] + "\""
            buildConfigField "String", "API_MODE",  "\"" +pro['API_MODE_UAT'] + "\""



        }

    }


    //修改生成的apk名字,格式为 app名_版本号_打包时间_渠道名_release.apk
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def oldFile = output.outputFile
            def releaseApkName = variant.productFlavors[0].name + "_${defaultConfig.versionCode}_v${defaultConfig.versionName}_${releaseTime()}_" + variant.buildType.name + '.apk'
            output.outputFile = new File(oldFile.parent, releaseApkName)
        }
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
}
dependencies {
//    compile project(':rn-splash-screen')
//    compile project(':react-native-video')
//    compile project(':react-native-picker')
    compile(project(':react-native-picker')) {
        exclude group: 'com.facebook.react', module: 'react-native'
    }

//    compile project(':react-native-image-picker')
    compile project(':react-native-camera')
    compile project(':react-native-autoheight-webview')
    compile project(':react-native-linear-gradient')
    compile(project(':react-native-camera')) {
        exclude group: 'com.facebook.react', module: 'react-native'
    }
    compile(project(':rn-splash-screen')) {
        exclude group: 'com.facebook.react', module: 'react-native'
    }
    compile(project(':react-native-video')) {
        exclude group: 'com.facebook.react', module: 'react-native'
    }
    compile(project(':react-native-image-picker')) {
        exclude group: 'com.facebook.react', module: 'react-native'
    }
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile('com.facebook.react:react-native:0.55.4') { force = true }
    // From node_modules
    compile 'com.elvishew:xlog:1.4.0'
    // 高德定位SDK
    compile 'com.amap.api:location:latest.integration'
    // 高德2D地图SDK(目前使用距离计算)
    compile 'com.amap.api:map2d:latest.integration'
    //阿里云上传
    compile 'com.aliyun.dpa:oss-android-sdk:2.7.0'
    compile project(':camera')
    //组件间通信 eventbus
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.alibaba:fastjson:1.1.46.android'
    compile files('libs/xntalk-android-sdk-1.4.0-SNAPSHOT.jar')
    compile files('libs/xntalk-android-sdk-1.4.0-SNAPSHOT-sources.jar')
    compile 'pub.devrel:easypermissions:0.1.5'
    //版本更新
    compile 'com.allenliu.versionchecklib:library:1.8.2'
    compile 'com.alibaba:fastjson:1.1.46.android'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    //友盟推送
    compile 'com.umeng.umsdk:analytics:8.0.0'
    //友盟统计
    compile 'com.umeng.umsdk:common:2.0.0'
    //PushSDK必须依赖utdid库,所以需要加入对应依赖
    compile 'com.umeng.umsdk:utdid:1.1.5.3'
    //PushSDK
    compile 'com.umeng.umsdk:push:6.0.1'
    //解决方法数超标
    compile 'com.android.support:multidex:1.0.1'
    compile files('libs/minewBeaconScan.jar')
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

/**
 * 发布时间
 * @return
 */
def releaseTime() {
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}

//获取产品的名字
def getProductName() {
    return "xntalk"
}

def getInfoPlistDic(appTarget){
    def xml=new XmlSlurper()
    xml.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false)
    xml.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
    // projectDir.getAbsolutePath()在gradle中可以获取到app层绝对路径
    def result = xml.parse(new File(projectDir.getAbsolutePath() + "/infoPlist/${appTarget}.plist"))
    def dict = result.dict
    //这里我比较取巧,因为plist文件跟XML不太一样,取到key的字符串时,找value的字符串不太好找,groovy解析两者关系不太大,这里直接去下标
    def version = dict.string[2]
    return dict
}

/**
 * 获得发布分支的plist文件中更新内容的设置
 */
def getUpdateInfoString(appTarget){
    def dict = getInfoPlistDic(appTarget)
    def updateInfo = dict.string[0]
    return updateInfo
}

/**
 * 获得发布分支的plist文件中应用显示名称设置
 */
def getAppName(appTarget){
    def dict = getInfoPlistDic(appTarget)
    def appName = dict.string[1]
    return appName
}

/**
 * 获得发布分支的plist文件中版本号的设置
 */
def getVersionString(appTarget){
    def dict = getInfoPlistDic(appTarget)
    def versionString = dict.string[2]
    return versionString
}

/**
 * 获得发布分支的plist文件中buildversion的设置
 */
def getBuildVersionString(appTarget){
    def dict = getInfoPlistDic(appTarget)
    def buildVersionString = dict.string[3]
    return buildVersionString
}

/**
 * 获得发布分支的plist文件中version的设置
 */
def getVersionCodeString(appTarget){
    def dict = getInfoPlistDic(appTarget)
    def versionCodeString = dict.string[4]
    return versionCodeString
}

/**
 * 获得发布分支的plist文件中LoganAppName的设置
 */
def getLoganAppName(appTarget){
    def dict = getInfoPlistDic(appTarget)
    def versionCodeString = dict.string[8]
    return versionCodeString
}