• cocos2dLua3.17.2 + AS3.5.2 创建工程成功 qd


      最近一个童鞋问我,他用的是cocoslua3.17.2 创建新工程,各种问题出现,不知道怎么办了,希望我能协助一下,然后,我就把我在线跑的工程所用到的一些版本告诉他,没想到,被鄙视了: 你还用AS3.2呀,太早了呀,我现在用的3.5.2,我不想用太老的呀。能帮我搞一下不? 

      就这样,我就被鄙视了。好吧,也闲着,看一下,自己跑去下了个(你这也不是新的啊,还鄙视我,只比我用的新了那么一捏捏而已嘛)

      既然用新的AS了,那么Gradle也要升级了,事实证明,gradle也不能随便想升到几就是几,遇到一些问题后,最终确定一个版本

    classpath 'com.android.tools.build:gradle:3.4.0'
    distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
    

     NDK版本:  android-ndk-r19c

       由于google上架要求android api版本必须在30以上,也改了吧

    # Android SDK version that will be used as the compile project
    PROP_COMPILE_SDK_VERSION=30
    
    # Android SDK version that will be used as the earliest version of android this application can run on
    PROP_MIN_SDK_VERSION=16
    
    # Android SDK version that will be used as the latest version of android this application has been tested on
    PROP_TARGET_SDK_VERSION=30
    

      编译时还要更改项目级build.gradle    文件  variant.mergeAssets.doLast  替换为  variant.mergeAssetsProvider.get().doLast

    编译成功了,找个android手机,跑一下。

    很好,不出所料,黑屏。gradle升级后,assets文件夹无法拷贝了。继续修改项目级 build.gradle文件

    修改后的代码

    android.applicationVariants.all { variant ->
        // delete previous files first
        delete "${buildDir}/intermediates/assets/${variant.dirName}"
        delete "${buildDir}/intermediates/merged_assets/${variant.dirName}"
        variant.mergeAssetsProvider.get().doLast {
            copy {
                from "${buildDir}/../../../../../res"
                into "${buildDir}/intermediates/assets/${variant.dirName}/res"
            }
    
            copy {
                from "${buildDir}/../../../../../src"
                into "${buildDir}/intermediates/assets/${variant.dirName}/src"
            }
            if (variant.name.compareTo('release') == 0) {
                copy {
                    from "${buildDir}/../../../../../res"
                    into "${buildDir}/intermediates/merged_assets/release/out/res"
                }
    
                copy {
                    from "${buildDir}/../../../../../src"
                    into "${buildDir}/intermediates/merged_assets/release/out/src"
                }
    
            }else{
                copy {
                    from "${buildDir}/../../../../../res"
                    into "${buildDir}/intermediates/merged_assets/debug/out/res"
                }
    
                copy {
                    from "${buildDir}/../../../../../src"
                    into "${buildDir}/intermediates/merged_assets/debug/out/src"
                }
            }
            // copy {
            //     from "${buildDir}/../../../../cocos2d-x/cocos/scripting/lua-bindings/script"
            //     into  "${buildDir}/intermediates/assets/${variant.dirName}/src/cocos"
            // }
            def compileScript = false
            // compile & encrypt the scripts if necessary
            //def compileScript = (variant.name.compareTo('release') == 0)
            if (project.hasProperty('PROP_COMPILE_SCRIPT')) {
                compileScript = (PROP_COMPILE_SCRIPT.compareTo('1') == 0)
            }
    
            def encryptLua = project.hasProperty('PROP_LUA_ENCRYPT') && (PROP_LUA_ENCRYPT.compareTo('1') == 0)
            if (compileScript || encryptLua) {
                // -1 means not build bytecode
                // 0 means build 32bit only
                // 1 means build 64bit only
                // 2 means build both 32bit & 64bit
                def buildType = -1
                if (compileScript) {
                    def need64 = false
                    def need32 = false
                    def abis = PROP_APP_ABI.split(':').collect{it as String}
                    abis.each{ abi->
                        if (abi.compareTo('arm64-v8a') == 0) {
                            need64 = true
                        }
                        else
                        {
                            need32 = true
                        }
                    }
    
                    if (need64 && need32) {
                        buildType = 2
                    }
                    else if (need64) {
                        buildType = 1
                    }
                    else {
                        buildType = 0
                    }
                }
    
                // invoke cocos command to compile & encrypt the lua files
                switch (buildType) {
                    case -1:
                        compileLua("${buildDir}/intermediates/merged_assets/${dirName}/${mergeAssets}/out/src",
                                "${buildDir}/intermediates/merged_assets/${dirName}/${mergeAssets}/out/src",
                                false, false, encryptLua)
                        break
                    case 0:
                        compileLua("${buildDir}/intermediates/merged_assets/${dirName}/${mergeAssets}/out/src",
                                "${buildDir}/intermediates/merged_assets/${dirName}/${mergeAssets}/out/src",
                                true, false, encryptLua)
                        break
                    case 1:
                        compileLua("${buildDir}/intermediates/merged_assets/${dirName}/${mergeAssets}/out/src",
                                "${buildDir}/intermediates/merged_assets/${dirName}/${mergeAssets}/out/src/64bit",
                                true, true, encryptLua)
    
                        // remove the lua files in src dir
                        delete fileTree("${buildDir}/intermediates/merged_assets/${dirName}/${mergeAssets}/out/src") {
                            include '**/*.lua'
                        }
                        delete "${buildDir}/intermediates/merged_assets/${dirName}/${mergeAssets}/out/src/cocos"
                        break
                    case 2:
                        compileLua("${buildDir}/intermediates/merged_assets/${dirName}/${mergeAssets}/out/src",
                                "${buildDir}/intermediates/merged_assets/${dirName}/${mergeAssets}/out/src/64bit",
                                true, true, encryptLua)
                        compileLua("${buildDir}/intermediates/merged_assets/${dirName}/${mergeAssets}/out/src",
                                "${buildDir}/intermediates/merged_assets/${dirName}/${mergeAssets}/out/src",
                                true, false, encryptLua)
                        break
                }
            }
        }
    }
    

      由于我不直接用他的加密,所以加密那部分我没太留意改的对不对。

    继续跑一下,OK 了,界面就这样出来了,assets文件夹也打入到apk中了。全部完成。以上过成功遇到过很多问题,例如:Execution failed for task ':testdemo:externalNativeBuildDebug'. 这样的问题。通过更改Gradle和NDK版本,基本都解决了,如果还有问题,可以在联系我,我们一起探讨。

     

  • 相关阅读:
    磁盘相关命令
    shell $用法
    setuid setgid stick bit 特殊权限 粘滞位
    运维面试题2
    mysql 外键约束
    创建MySQL 用户
    shell 脚本定时创建月份表
    apache 配置多个虚拟主机,不同的端口
    sublime3中文乱码解决包ConvertToUTF8.zip
    yii2安装
  • 原文地址:https://www.cnblogs.com/whj0402/p/15541389.html
Copyright © 2020-2023  润新知