Gradle Build Error: Cannot cast object '[ ]' with class 'java.util.Hashset'


(Mann Kaur) #1

Hi All,

I downloaded a game off CodeCanyon to reskin it. But I am having trouble trying to build it on my Android Studio.

I am getting this error

Cannot cast object ‘[]’ with class ‘java.util.HashSet’ to class ‘org.gradle.api.file.FileCollection’ due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.gradle.api.file.FileCollection()

And this is my line of code in which it points the error at:

// needed to add JNI shared libraries to APK when compiling on CLI
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet()
pkgTask.jniFolders.add(new File(projectDir, ‘libs’))
}

Does anybody know what this could mean or how I can resolve it?
I know very little programming. Any help would be really appreciated.

Kind regards,
Mann


(Bo Zhang) #2

Seems the version of PackageApplication you’re using has a FileCollection member jniFolders, but you’re trying to assign a HashSet to it. I guess you’re copying some code from somewhere else, but that might be out-of-date.

My suggestion: query the PackageApplication version you’re using, find out which APIs it provides, then use the correct method. In your case, I think you should use project.file() or project.files() API.