环境
- Cocos Creator 2.4.3
- Android Studio 4.1.3
- Gradle 6.5(插件4.1.3)
步骤
1. 原始版本
Cocos Creator 2.4.3打包的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")