Cosos生成的Android原生项目,由于gradle版本比较低,导致firebase引入失败。
- Cocos Creator 2.4.2
- Gradle 6.7.1(插件4.2.1)
cocos发布原生版本,不添加其他的包引用,一般是不需要升级gradle的,但是部分渠道的sdk包使用了更高级版本gradle的功能,导致我们自己的工程项目gradle版本太低,不得不进行兼容性升级。
1. 原始版本
Cocos Creator 2.4.2打包的Android工程中gradle版本是4.10.3(插件3.2.0)
2. 修改gradle版本号
用Android Studio打开Cocos Creator生成的Android工程,点文件->Project Structure , 在Project Structure面板中选择Project。在右侧直接输入 Gradle和插件的版本号。确定后Android Studio会自为下载对应的版本。
3. 修改setting.gradle配置
文件路径:
jsb-default/frameworks/runtime-src/proj.android-studio/setting.gradle
修改前 :
include ':libcocos2dx',':game', ':instantapp'
修改后:
include ':libcocos2dx'
修改原因:不需要game,用不到 这个模块是给Google Instant使用的,也可以直接屏蔽对应模块。
4. 修改 CocosAndroid.mk
文件路径:
jsb-default/frameworks/runtime-src/proj.android-studio/jni/CocosAndroid.mk
修改前 :
LOCAL_MODULE := cocos2djs_shared
修改后:
LOCAL_MODULE := cocos2djs
修改原因:Android Studio Build的时候报错,找不到target “cocos2djs”
5. 修改app/build.gradle
文件路径:
jsb-default/frameworks/runtime-src/proj.android-studio/app/build.gradle
修改前 :
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 } } }
修改后:
android.applicationVariants.all { variant -> // delete previous files first delete "${buildDir}/intermediates/merged_assets/${variant.dirName}" //修改 报警错误 API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'.It will be removed at the end of 2019. // variant.mergeAssets.doLast { variant.mergeAssetsProvider.get().doLast{ def sourceDir = "${buildDir}/../../../../.." copy { from "${sourceDir}/assets" into "${outputDir}/assets" into outputDir.dir("assets") } copy { from "${sourceDir}/src" into "${outputDir}/src" into outputDir.dir("src") } copy { from "${sourceDir}/jsb-adapter" into "${outputDir}/jsb-adapter" into outputDir.dir("jsb-adapter") } copy { from "${sourceDir}/main.js" from "${sourceDir}/project.json" into outputDir } } }
修改原因:资源复制丢失。基本上就是把 into "${outputDir}/x"
改成 into outputDir.dir("x")
以上就是升级完毕。
标签:CososCreator,sourceDir,..,into,variant,gradle,版本,outputDir From: https://www.cnblogs.com/lixiangyang521/p/17196629.html