cocos2d-x 3.X eclipse gradle 多渠道多SDK打包配置教程(二)

根据上一篇的指导,应该已经可以出一个同资源同SDK的包了,现在看下在eclipse gradle下如何像Android studio一样一键打出不同SDK接入的渠道包吧

首先一个项目一个项目的复制粘贴到工程下,大概是这样的

每个渠道都创建好build.gradle,里面的配置信息是这样的

apply plugin: 'android'

//获取当前时间的函数(年月日)
def releaseTime() {
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}

//包入的jar包和libs
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':cocos2d-x:cocos:platform:android:java')
}

android {
    //签名信息
	signingConfigs{
		myConfig{
			keyAlias 'xxxx'
			keyPassword 'xxxx'
			storeFile file('xxxx')
			storePassword 'xxxx'
		}
	}
    
    //签名和输出包的目录和格式,这里输出的是test_v1_2018_10_29_test.apk到D:/xxxx/package目录下
	buildTypes{
		release {
			signingConfig  signingConfigs.myConfig
			applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                        def fileName = "test_v${defaultConfig.versionName}_${releaseTime()}_test.apk"
                        output.outputFile = new File("D:/xxxx/package", fileName)
                    }
                }
            }
		}
	}
	
    compileSdkVersion 20
    buildToolsVersion "25.0.0"
    enforceUniquePackageName = false
	
    //配置在公共部分的包版本信息
	defaultConfig {
    	versionCode project.VERSION_CODE as int
        versionName project.VERSION_NAME
    }
    
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
	
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            //这个很重要哦
            main.jniLibs.srcDirs = ['libs'] 
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

就这样每个包都做这个操作。

如果要配置比如友盟的渠道信息

在AndroidManifest.xml中

<meta-data
            android:name="UMENG_CHANNEL"
            android:value="${CHANNEL_VALUE}" />

替换,这里CHANNEL_VALUE就是一个变量,在打包时候赋值,想要什么渠道号就是什么渠道号了

使用的话也简单

android {
	productFlavors {
		_360Extend{}
		baiduExtend{}
    }
    productFlavors.all { flavor ->
    	flavor.manifestPlaceholders = [CHANNEL_VALUE: name]
    }

或者

android {
	productFlavors {
        //这里渠道名不能是数字开头,所以只能加一个下划线了
		_360Extend{
			manifestPlaceholders = [CHANNEL_VALUE: "_360Extend"]
		}
		baiduExtend{
			manifestPlaceholders = [CHANNEL_VALUE: "baiduExtend"]
		}
    }

打包出来就行了

然后刚才公共部分的版本信息是配置在这的

自己创建一个gradle.properties

里面添加

就可以使用啦!

编译的话,如果是所有项目一起编译出apk的话,在根目录也就是framework目录下的settings.gradle 修改为

!!!这里很重要!!!!

是settings.gradle!!!!

这个文件是你编译的配置信息,你include的所有项目全在里面,我也研究了好半天

我的是这样的:

一个项目和一个项目用逗号隔开,然后最下面2个是cocos2d-x java的公共部分,每次编译都需要的

腾讯应用宝有额外的library,我没什么办法就一起逗号隔开进去了,坏处就是会多编译一次library但是不会再apk目录下有输出

如果有什么好的方法的话可以告诉我,谢谢

然后在根目录framwork下,打开命令行,执行gradle build

就会开始漫长的编译过程了,结束就会这样啦

大功告成!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值