Cocos2d JS 3.17 Android Black Screen

Cocos2d JS 3.17 Android Black Screen
0

Hello Everyone!
I create new project JS, then i build and run project Android by Android Studio, but my devices display black screen.

cocos2d: 3.17
Android Studio: 3.2.1
PROP_COMPILE_SDK_VERSION=27
PROP_MIN_SDK_VERSION=14
PROP_TARGET_SDK_VERSION=27
PROP_BUILD_TOOLS_VERSION=28.0.3

Some log:
Choreographer: Skipped 11 frames! The application may be doing too much work on its main thread.
WindowManager: Failed looking up window
cocos2d-x debug info: cocos2d: fullPathForFilename: No file found at script/jsb_prepare.js. Possible missing file.
cocos2d-x debug info: cocos2d: fullPathForFilename: No file found at script/jsb_prepare.jsc. Possible missing file.
cocos2d-x debug info: cocos2d: fullPathForFilename: No file found at script/jsb_prepare.js. Possible missing file.
ScriptingCore.cpp: ScriptingCore:: compileScript fail:script/jsb_prepare.js
cocos2d-x debug info: JS: (string):1:TypeError: cc.Class is undefined

Thanks!

Hi

Did you make any changes in the project?
Please try on cocos 3.17.1

Hi all!
I have same problem with cocos2d JS 3.17.1
android studio 3.2.1
anyone has suggestion?
Thanks!

Use classpath ; ‘com.android.tools.build:gradle:3.1.4’ . in gradle setting dependency
and
distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip . in gradle-wrapper-properties

when you use above property your “buildToolsVersion” will be set to ‘27.0.3’

This fixed issue for me

3.2.1 version has some issues

Run your project in browser and inspect the project if any error in the web build it gives blank screen in ios and android.

Thanks Yathiraj_karkera!
I got it!
But when i import sdkbox to my project and build:

Bug Log:
AGPBI: {“kind”:“error”,“text”:“Program type already present: com.sdkbox.plugin.SDKBoxIABBillingClient$3”,“sources”:[{}],“tool”:“D8”}
:MyGame:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
:MyGame:buildInfoGeneratorDebug
FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:MyGame:transformDexArchiveWithExternalLibsDexMergerForDebug’.

Can You help me find bug?
Thank you very much!

I fixed it with modify sth in build.gradle like this picture


Another copy {} lines, you can fix similarly.
Reason: in gradle 4.6 – merge Assets folder change to merged_assets folder

1 Like

@vanminh thank you for solution.

I’m using cocos2d 3.17.1
I fixed it using your solution and added two variables to reduce copy-paste code.

android.applicationVariants.all { variant ->
    def project_root_folder = "${buildDir}/../../../../.."
    def dest_assets_folder = "${buildDir}/intermediates/merged_assets/${variant.dirName}/merge${variant.dirName}Assets/out"

    // delete previous files first
    delete dest_assets_folder

    variant.mergeAssets.doLast {
        copy {
           from project_root_folder + "/res"
           into dest_assets_folder + "/res"
        }

        copy {
            from project_root_folder + "/src"
            into dest_assets_folder + "/src"
        }

        copy {
            from project_root_folder + "/frameworks/cocos2d-x/cocos/scripting/js-bindings/script"
            into dest_assets_folder + "/script"
        }

        copy {
            from project_root_folder + "/main.js"
            from project_root_folder + "/project.json"
            into dest_assets_folder
        }

        // compile the scripts if necessary
        def compileScript = (variant.name.compareTo('release') == 0)
        if (project.hasProperty('PROP_COMPILE_SCRIPT')) {
            compileScript = (PROP_COMPILE_SCRIPT.compareTo('1') == 0)
        }

        if (compileScript) {
            compileJS(dest_assets_folder, dest_assets_folder)
        }
    }
}

I was not able to solve warning:

WARNING: API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
1 Like

Thanks vanminh and dimon4eg!

i changed mergedAssets.doLast to mergedAssetsProvider.doLast and it is saying could not find method doLast, did anyone else get this when trying to change it ?

3 Likes

fix dest_assets_folder, not

def dest_assets_folder = "${buildDir}/intermediates/merged_assets/${variant.dirName}/merge${variant.dirName}Assets/out"

===>

def dest_assets_folder = "${buildDir}/intermediates/merged_assets/${variant.dirName}/out"

solution

android.applicationVariants.all { variant ->
    def project_root_folder = "${buildDir}/../../../../.."
    def dest_assets_folder = "${buildDir}/intermediates/merged_assets/${variant.dirName}/out"

    // delete previous files first
    delete dest_assets_folder

    variant.mergeAssets.doLast {
        copy {
           from project_root_folder + "/res"
           into dest_assets_folder + "/res"
        }

        copy {
            from project_root_folder + "/src"
            into dest_assets_folder + "/src"
        }

        copy {
            from project_root_folder + "/frameworks/cocos2d-x/cocos/scripting/js-bindings/script"
            into dest_assets_folder + "/script"
        }

        copy {
            from project_root_folder + "/main.js"
            from project_root_folder + "/project.json"
            into dest_assets_folder
        }

        // compile the scripts if necessary
        def compileScript = (variant.name.compareTo('release') == 0)
        if (project.hasProperty('PROP_COMPILE_SCRIPT')) {
            compileScript = (PROP_COMPILE_SCRIPT.compareTo('1') == 0)
        }

        if (compileScript) {
            compileJS(dest_assets_folder, dest_assets_folder)
        }
    }
}
2 Likes

https://github.com/cocos2d/cocos2d-x/pull/19679 should be included with 3.17.2