gradle 版本
原来版本 :4.10.3
(插件3.2.0
)
升级后版本: 5.6.4
(插件3.6.3
)
gradle路径:jsb-default/frameworks/runtime-src/proj.android-studio/gradle/wrapper/gradle-wrapper.properties
插件路径:jsb-default/frameworks/runtime-src/proj.android-studio/build.gradle
#Fri Oct 27 10:18:28 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
插件路径:jsb-default/frameworks/runtime-src/proj.android-studio/build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
修改后 可以通过 File–>Project Structure 查看
![image-20210106182021197](Cocos Creator Android原生项目升级gradle版本/image-20210106182021197.png)
![image-20210106182038185](Cocos Creator Android原生项目升级gradle版本/image-20210106182038185.png)
修改文件
setting.gradle 修改
原因:构建失败
路径:
jsb-default/frameworks/runtime-src/proj.android-studio/setting.gradle
修改前 :
include ':libcocos2dx',':game', ':instantapp'
修改后:
include ':libcocos2dx'
修改原因:不需要game,用不到 这个模块是给Google Instant使用的,也可以直接屏蔽对应模块
CocosAndroid.mk 修改
原因:构建失败
路径:
jsb-default/frameworks/runtime-src/proj.android-studio/jni/CocosAndroid.mk
修改前 :
LOCAL_MODULE := cocos2djs_shared
修改后:
LOCAL_MODULE := cocos2djs
修改原因:构架报错,找不到target “cocos2djs”
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.dir("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”)
PS 如果 gradle 下载失败 可以参考我的另外一篇博客:CocosCreator导出Android项目采坑指南
- Cocos Creator 原生项目升级gradle版本 - 简书
- Android Gradle 插件版本说明-官网
- 原生安卓gradle plugin版本问题-cocos论坛
- cocos creator 编译android失败-cocos论坛
- Error: Invoke-customs are only supported starting with Android O (–min-api 26)- CSDN
- Execution failed for task ‘:app:lintVitalRelease’. Invalid main APK outputs- CSDN
- Android studio error : API ‘variant.getMergeAssets()’ is obsolete-cocos论坛
-
Caused by: java.lang.reflect.InvocationTargetException
本文博客地址
http://blog.asroads.com/post/d184577c.html
Cocos Creator Android原生项目升级gradle版本