简体   繁体   中英

"Unable to find method ''void org.apache.commons.compress.archivers.zip.ZipFile.<init>(java.nio.channels.SeekableByteChannel)''"

The problem: I'm currently using Android Studio and Gradle to compile code from a github repository ( 00-Evan/shattered-pixel-dungeon ) and while I can run some tasks (tried 'desktop:release', 'desktop:debug'), gradle refuses to sync properly and every time I try to do it, an error log pops up:

FAILURE: Build failed with an exception.

* What went wrong:
'void org.apache.commons.compress.archivers.zip.ZipFile.<init>(java.nio.channels.SeekableByteChannel)'

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
java.lang.NoSuchMethodError: 'void org.apache.commons.compress.archivers.zip.ZipFile.<init>(java.nio.channels.SeekableByteChannel)'
    at com.android.repository.util.InstallerUtil.unzip(InstallerUtil.java:99)

Important: I've had this issue before (while compiling previous version of this code) and back then downloading a specific version of SDK build tools (30.0.0 and 26.0.0 if I recall correctly) helped, however this doesn't help anymore.
Other people using this code don't report the same issue and I seem to be the only one.

Also for some reason android tasks also don't seem to work, as if the android studio didn't recognize them:

Task 'release' not found in project ':android'.

 * Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

What I've tried:

  • Clearing cache and restarting Android Studio/my PC
  • Enabling/disabling different build tools versions (see the "Important" section). At the moment I have tried enabling all 30.0.X and 26.0.X versions and disabling any newer versions that were enabled
  • Browsed similar Stackoverflow threads, however they either didn't seem to apply to my situation or didn't include enough information. Link , link and link .
  • Uninstalling Android Studio and re-downloading it from scratch.

Additional info:

  • Android Studio version: Android Studio Arctic Fox | 2020.3.1 Patch 4 (Currently latest)
  • Gradle version: 7.2 (I tried using 7.1.1, but that didn't solve the issue)

Generally, when you install android studio it will install the latest SDK and latest build tool version which is not compatible with the existing projects.

According to the build.gradle present in 00-Evan/shattered-pixel-dungeon

You should try installing the SDK version 30. And the SDK build tool version: 30.0.X. It should work.

For me, it is working with SDK version 30 and build tool version 30.0.3.

And just make sure you have java version 8 as mentioned in build.gradle.

Try to install Android 11.0 (R) or Android 12.00 (S) on the SDK Platform tab on the Android SDK. That fixed the issue for me

For anyone looking for more information, this specific issue has been covered in Google's issue tracker . In short, the problem stems from mismatched dependency resolution of Apache's commons-compress between robovm-gradle-plugin and Gradle itself. As for Shattered Pixel Dungeon, the fix is present in this commit .

I just had the same issue after I switched to an Apple Silicon Mac, which I could solve specifying the compileSdkVersion at my root project build.gradle file:

buildscript {
    ext {
        // Specification needed to avoid Gradle NoSuchMethodError at org.apache.commons.compress.archivers.zip.ZipFile
        compileSdkVersion = 30
    }
}

After fresh Android Studio installation I've downloaded proposed Android SDK and build tools , but my project was configured for the older Android SDK and build tools . Then issue happened. I fixed it by downloading appropriate Android SDK and build tools .

For example, if your project has compileSdkVersion 31 value, then download Android SDK 31 and build tools 31.0.0 . In Tools/SDK Manager/Show Package Details you can find appropriate versions for your case.

In my case it was error with robovm, I was trying build libGDX for iOS on Windows PC, when I remove iOS project, error gone too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM