CososCreator upgrades the gradle version

This article reference: https://forum.cocos.org/t/topic/103837    (directly refer to this link for more details.)

  • Cocos Creator 2.4.2
  • Gradle 6.7.1 (plugin 4.2.1)

Cocos releases the native version without adding other package references. Generally, there is no need to upgrade gradle. However, the sdk packages of some channels use the functions of a more advanced version of gradle, resulting in the gradle version of our own projects being too low and having to be compatible. sex upgrade.

step

1. Original version

The gradle version in the Android project packaged by Cocos Creator 2.4.2 is 4.10.3 (plugin 3.2.0)

2. Modify the gradle version number

Use Android Studio to open the Android project generated by Cocos Creator, click File -> Project Structure, and select Project in the Project Structure panel. Enter the version numbers of Gradle and plugins directly on the right. After confirmation, Android Studio will automatically download the corresponding version.

3. Modify setting.gradle configuration

file path:

jsb-default/frameworks/runtime-src/proj.android-studio/setting.gradle

before fixing:

include ':libcocos2dx',':game', ':instantapp'

After modification:

include ':libcocos2dx'

Reason for modification: No game is needed, this module is for Google Instant, and the corresponding module can also be blocked directly.

4. Modify CocosAndroid.mk

file path:

jsb-default/frameworks/runtime-src/proj.android-studio/jni/CocosAndroid.mk

before fixing:

LOCAL_MODULE := cocos2djs_shared

After modification:

LOCAL_MODULE := cocos2djs

Reason for modification: An error was reported during Android Studio Build, and the target "cocos2djs" could not be found

5. Modify app/build.gradle

file path:

jsb-default/frameworks/runtime-src/proj.android-studio/app/build.gradle

before fixing:

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

After modification:

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

Reason for modification: Resource replication is lost. Basically just into "${outputDir}/x"change theinto outputDir.dir("x")

Guess you like

Origin blog.csdn.net/sirria1/article/details/125378044