import org.apache.tools.ant.taskdefs.condition.Os apply plugin: 'com.android.application' apply plugin: 'com.tencent.vasdolly' android { compileSdkVersion = PROP_COMPILE_SDK_VERSION.toInteger() buildToolsVersion = PROP_BUILD_TOOLS_VERSION namespace "com.blackart.b22" repositories { mavenCentral() } defaultConfig { minSdkVersion PROP_MIN_SDK_VERSION targetSdkVersion PROP_TARGET_SDK_VERSION versionCode 7 versionName "1.0" externalNativeBuild { ndkBuild { if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) { // skip the NDK Build step if PROP_NDK_MODE is none targets 'cocos2djs' arguments 'NDK_TOOLCHAIN_VERSION=clang' def module_paths = [project.file("D:/CocosEditors/Creator/2.4.12/resources/cocos2d-x"), project.file("D:/CocosEditors/Creator/2.4.12/resources/cocos2d-x/cocos"), project.file("D:/CocosEditors/Creator/2.4.12/resources/cocos2d-x/external")] if (Os.isFamily(Os.FAMILY_WINDOWS)) { arguments 'NDK_MODULE_PATH=' + module_paths.join(";") } else { arguments 'NDK_MODULE_PATH=' + module_paths.join(':') } arguments '-j' + Runtime.runtime.availableProcessors() } } ndk { abiFilters PROP_APP_ABI.split(':') } } } sourceSets.main { java.srcDirs "../src", "src" res.srcDirs "../res", 'res' jniLibs.srcDirs "../libs", 'libs' manifest.srcFile "AndroidManifest.xml" } externalNativeBuild { ndkBuild { if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) { // skip the NDK Build step if PROP_NDK_MODE is none path "jni/Android.mk" } } } signingConfigs { release { if (project.hasProperty("RELEASE_STORE_FILE")) { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } } buildTypes { release { debuggable false jniDebuggable false renderscriptDebuggable false minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' if (project.hasProperty("RELEASE_STORE_FILE")) { signingConfig signingConfigs.release } externalNativeBuild { ndkBuild { arguments 'NDK_DEBUG=0' } } } debug { debuggable true jniDebuggable true renderscriptDebuggable true if (project.hasProperty("RELEASE_STORE_FILE")) { signingConfig signingConfigs.release } externalNativeBuild { ndkBuild { arguments 'NDK_DEBUG=1' } } } } } android.applicationVariants.all { variant -> // delete previous files first delete "${buildDir}/intermediates/merged_assets/${variant.dirName}" variant.mergeAssets.doLast { def sourceDir = "${buildDir}/../../../../.." copy { from "${sourceDir}" include "assets/**" include "src/**" include "jsb-adapter/**" into outputDir } copy { from "${sourceDir}/main.js" from "${sourceDir}/project.json" into outputDir } } def outputFileDir = "D:\\b22_client\\apk\\${variant.name}" println "copy cocos assets" //variant.getPackageApplicationProvider().get().outputDirectory = new File(outputFileDir) variant.outputs.all { output -> def packageLastName = applicationId.substring(applicationId.lastIndexOf(".") + 1, applicationId.length()) if (variant.buildType.name == "debug") { outputFileName = "${packageLastName}_debug.apk" } else { outputFileName = "${packageLastName}_${variant.versionCode}.apk" } } } tasks.whenTaskAdded { task -> if (task.name == 'assembleDebug' || task.name == 'assembleRelease') { task.finalizedBy(copyApkTask, copyApkTaskDest) } } task copyApkTask(type: Copy) { def buildType = project.gradle.startParameter.taskNames.any { it.toLowerCase().contains('release') } ? 'release' : 'debug' def sourceDir = "${buildDir}/outputs/apk/${buildType}" def uploadDir = "D:\\b22_client\\apk\\upload" doFirst { delete uploadDir file(uploadDir).mkdirs() } include '**/*.apk' from sourceDir into uploadDir } task copyApkTaskDest(type: Copy) { def buildType = project.gradle.startParameter.taskNames.any { it.toLowerCase().contains('release') } ? 'release' : 'debug' def sourceDir = "${buildDir}/outputs/apk/${buildType}" def destDir = "D:\\b22_client\\apk" include '**/*.apk' from sourceDir into destDir } // gradle rebuildChannel 配置此任务用于不希望重新构建apk,直接根据指定的apk生成渠道包 rebuildChannel { channelFile = file("channel.txt") //指定的apk生成渠道包,文件名中如果有base将被替换为渠道名,否则渠道名将作为前缀 baseApk = new File("D:\\b22_client\\apk\\b22_${android.defaultConfig.versionCode}.apk") //默认为new File(project.buildDir, "rebuildChannel") outputDir = new File("D:\\b22_client\\apk\\channel\\") //快速模式:生成渠道包时不进行校验(速度可以提升10倍以上,默认为false) fastMode = false //低内存模式(仅针对V2签名,默认为false):只把签名块、中央目录和EOCD读取到内存,不把最大头的内容块读取到内存,在手机上合成APK时,可以使用该模式 lowMemory = false } dependencies { implementation fileTree(dir: '../libs', include: ['*.jar', '*.aar']) implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) implementation fileTree(dir: "D:/CocosEditors/Creator/2.4.12/resources/cocos2d-x/cocos/platform/android/java/libs", include: ['*.jar']) implementation project(':libcocos2dx') // git https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/README-CN.md implementation 'com.blankj:utilcodex:1.31.0' // facebook-login implementation 'com.facebook.android:facebook-login:17.0.1' implementation 'com.facebook.android:audience-network-sdk:6.17.0' // google-login implementation 'com.google.android.gms:play-services-auth:19.2.0' // google-ads implementation 'com.google.android.gms:play-services-ads:23.3.0' // google-plasy-bill def billing_version = "7.0.0" implementation "com.android.billingclient:billing:$billing_version" // git https://github.com/Tencent/VasDolly api 'com.tencent.vasdolly:helper:3.0.6' }