cocoscreator src,res 需要整改
整改步骤如下
一,在app目录下创建src,新建main->java文件夹(存放代码),src->main->res(存放资源),Manifest.xml
main 文件夹是默认的variants环境
二,copy 原src 文件到app main->java 文件夹下,res copy到app->src->main->res 下。删除原来的res,src,以及Manifest.xml 文件。
三,修改app(或者标记项目名称)下的build.gradle 文件。注释掉
// sourceSets {
...
// }
四,添加productFlavors,在build.gradle 里添加productFlavors 模块
productFlavors {
// main{}
nomal{}
platform_4399{
applicationId 'com.zmyfun.aqdzt.m4399'
versionCode 2
versionName "2.0"
}
vivo{
applicationId 'com.zmyfun.aqdzt.vivo'
versionCode 1
versionName "1.0"
}
}
如不同渠道包名不同可以在productFlavors 对应的渠道里直接重写applicationId 来重置包名。
添加对应的编译环境后就可以在src里添加,参考下图
image.png
根据不同的要替换的内容来放置到对应的渠道包里
配置打包的输出路径,继续在build.gradle 里配置android.applicationVariants.all模块
android.applicationVariants.all { variant ->
// delete previous files first
delete "${buildDir}/intermediates/merged_assets/${variant.dirName}"
variant.mergeAssets.doLast {
def sourceDir = "${buildDir}/../../../../.."
copy {
from "${sourceDir}/assets"
into "${outputDir}/assets"
}
copy {
from "${sourceDir}/src"
into "${outputDir}/src"
}
copy {
from "${sourceDir}/jsb-adapter"
into "${outputDir}/jsb-adapter"
}
copy {
from "${sourceDir}/main.js"
from "${sourceDir}/project.json"
into outputDir
}
//后加
variant.outputs.all {
def outputFile = outputFileName
if (outputFile != null && outputFile.endsWith('.apk')) {
// def dirName = outputFile.parent // 输出文件夹所在的位置
// 文件名修改
// def fileName = "app-${output.processResources.variantName}-${defaultConfig.versionName}-${variant.flavorName}.apk"
// def fileName = "app-${output.processResources.variantName}-${variant.flavorName}.apk"
def fileName = "NYTalk_" + buildType.name + "_" + new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC")) + ".apk"
// 比如不想这么麻烦,直接在后面加上版本号也行:
// def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
// output.outputFile = new File(dirName, fileName)
outputFileName = fileName
}
}
}
配置依赖方式
dependencies {
implementation fileTree(dir: '../libs', include: ['*.jar','*.aar'])
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
implementation fileTree(dir: "/Applications/CocosCreator/Creator/2.4.2/CocosCreator.app/Contents/Resources/cocos2d-x/cocos/platform/android/java/libs", include: ['*.jar'])
implementation project(':libcocos2dx')
// implementation project(':lib_au4399_sdk')
// implementation project('')
platform_4399Implementation project(':lib_au4399_sdk')
}
xxxImplementation xxx代表渠道名称。会自动根据渠道环境来动态添加依赖
网友评论