cocos creator 导出Android工程 升级gradle

1.项目的build.gradle中 修改cocos 导出自带的gradle版本

buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
    }
}

2.app/gradle/wrapper/gradle-wrapper.properties中 修改

distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

3.项目的setting.gradle里面设置

include ':libcocos2dx'
project(':libcocos2dx').projectDir = new File('D:/CocosDashboard/resources/.editors/Creator/2.4.3/resources/cocos2d-x/cocos/platform/android/libcocos2dx')
include ':app'
project(':app').projectDir = new File(settingsDir, 'app')

4 app/build.gradle 中替换

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
        }
    }
}

你可能感兴趣的:(cocos creator 导出Android工程 升级gradle)