Android cpp-tests - missing Resources

I tried to run on a device (Vivo X20) and I get a dialog on the phone that says:

parse error: there was a problem parsing the package

and Android Studio:

@zhangxm @coulsonwang any thoughts?

As the message says, you should uninstall it first.

I don’t have it in my phone any place I can find…

Hey all - thank you for the continued efforts. I’ve had to travel for work thus did not have time to reply earlier.

I am eager to see the resolution of this!

Thanks again
Greg

So I was able to use a tablet I have and try the instructions and it works:

I did make a few small adjustments to the doc: Q2 - 13 by slackmoehrle · Pull Request #230 · cocos2d/cocos2d-x-docs · GitHub

@slackmoehrle there was nothing you changed in any of the build scripts for cpp-tests, to get the Resources to copy?

I didn’t change anything. I just let Android Studio do all the work when I opened cpp-tests. It took several hours (mostly due to my slow internet). It just keep updating. When I tried to run cpp-tests it also needed SDK updates.
I did make some small edits to the docs in the PR I mentioned but they were just language and some new images. No technical errors, etc.

Ok, thanks for the info.
I’ll have another look at it as soon as I can. The good thing is, like I said, a new project created with the cmdline tool works properly!

@gmayer @r101 can also re-produce your issue. So something is wrong.

This section of the build.gradle file is not working, since it’s not excluding the *.gz files as it should (EDIT: turns out it is working, but not quite how it should because of changes in newer versions of Gradle)

android.applicationVariants.all { variant ->
    // delete previous files first
    delete "${buildDir}/intermediates/assets/${variant.dirName}"

    variant.mergeAssets.doLast {
        copy {
           from "${buildDir}/../../../Resources"
           into "${buildDir}/intermediates/assets/${variant.dirName}"
           exclude "**/*.gz"
        }
    }
}

Also, it seems to be marked as obsolete, so it needs to be updated to whatever is the new method now.

WARNING: API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'.
It will be removed at the end of 2019.
1 Like

@zhangxm @coulsonwang thoughts?

The bit that was added by @Mr_9 assets.srcDir "../../Resources" is causing the issue with the *.gz files:

sourceSets.main {
    java.srcDir "src"
    res.srcDir "res"
    manifest.srcFile "AndroidManifest.xml"
    assets.srcDir "../../Resources"  <= this cannot be used 
}

Now, if that bit is removed, to what was originally there, Gradle won’t auto-copy the resources, so no more *.gz errors, and we need to do it ourselves, which is the whole purpose of the variant.mergeAssets.doLast section:

sourceSets.main {
    java.srcDir "src"
    res.srcDir "res"
    manifest.srcFile "AndroidManifest.xml"
}

The following bit of the Gradle script does work as intended, copying the resources to the output assets folder, and does ignore *.gz files, but Gradle isn’t using that assets folder in the final APK packaging:

    variant.mergeAssets.doLast {
        copy {
           from "${buildDir}/../../../Resources"
           into "${buildDir}/intermediates/assets/${variant.dirName}"
           exclude "**/*.gz"
        }
    }
1 Like

I got it working with my setup, using Gradle 5.1.1 (this should work for Gradle3.2+, but I’m not 100% sure):

android.applicationVariants.all { variant ->

    def mergeAssetsTask = variant.mergeAssetsProvider.get()
    def resourcesDir = "${projectDir}/../../Resources"
    def assetsDir = mergeAssetsTask.outputDir.get()

    mergeAssetsTask.doFirst {
        // delete previous files first
        delete "${assetsDir}/*"
    }

    mergeAssetsTask.doLast {
        copy {
            from("${resourcesDir}") {
                exclude "**/*.gz"
            }
            into("${assetsDir}")
        }
    }
}

Just make sure that you do not add assets.srcDir "../../Resources" to the following section:

sourceSets.main {
    java.srcDir "src"
    res.srcDir "res"
    manifest.srcFile "AndroidManifest.xml"
}

@R101 I tried the above and it works!!! THANK YOU SO MUCH!!
I now have working cpp tests on my android device :slight_smile:
This will help me troubleshoot why the EditBox in my game is not working properly…

thanks again!
Greg

This issue seems to be fixed in the github cocos2d-x repository, specifically in this PR. The fix is different to the one I posted, but the end result is the same.

@coulsonwang thanks for helping with this

Is this solved now?

@gmayer May want to see this.

The already merged fix in this PR is the one that should be used, since apparently mergeAssetsTask.doLast cannot be relied on. I’m not entirely sure why, but regardless, the already merged fix works perfectly fine.

@R101 great job working on this to help get a resolution. I appreciate it and I know our users appreciate it as well. This is what helps a community grow.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.