由于第三方sdk 接入要求或增强版本稳定性等原因,需要对cocos creator 2.4.6 android 编译环境进行升级。
现记录下升级过程,以备有需要的同学做参考。
原环境:
- jdk version: 1.8.0_251
- sdk version: 28
- ndk version:android-ndk-r21d
- android grade plugin version:3.2.0
- gradle version :4.10.3
新环境:
- jdk version: 1.8.0_251
- sdk version: 30
- ndk version:android-ndk-r21d
- android grade plugin version:4.1.0
- gradle version 6.5.1
升级调整内容:
1、调整 gradle 及插件版本
(1)、菜单 File->Project Structure
(2)、修改 Gradle Plugin Version 为4.1.0 、 Gradle Version 为 6.5.1 并保存
2、修改CocosAndroid.mk 文件
解决:构建成功后 运行apk 找不到 libcocos2djs.so 错误
jsb-default/frameworks/runtime-src/proj.android-studio/jni/CocosAndroid.mk
修改之前
LOCAL_MODULE := cocos2djs_shared
修改之后
LOCAL_MODULE := cocos2djs
3、修改 app 目录层级 build.gradle
解决:运行apk 后找不到资源,黑屏或闪退问题
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}"
include "assets/**"
include "manifest/**"
include "src/**"
include "jsb-adapter/**"
include "main.js"
include "project.json"
into outputDir
}
}
}