- Как исправить ошибку java.lang.NoSuchMethodError?
- Отладка java.lang.NoSuchMethodError
- java.lang.NoSuchMethodError: ‘void com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTests$default(com.android.build.api.extension.AndroidComponentsExtension, com.android.build.api.extension.VariantSelector, kotlin.jvm.functions.Function1, int, java.lang.Object)’ #2631
- Comments
- ColtonIdle commented May 19, 2021
- Tgo1014 commented May 19, 2021
- shakil807g commented May 19, 2021
- slavonnet commented May 19, 2021
- danysantiago commented May 19, 2021
- b95505017 commented May 19, 2021
- danysantiago commented May 19, 2021
- b95505017 commented May 19, 2021
- ColtonIdle commented May 20, 2021
- SimonMarquis commented May 20, 2021
- ColtonIdle commented May 21, 2021
- gulabsagevadiya commented Jun 8, 2021 •
- SimonMarquis commented Jun 8, 2021
- rock3r commented Jun 17, 2021 •
- mwy3055 commented Jun 17, 2021 •
- slavonnet commented Jun 17, 2021 •
- AndroidJavaException: java.lang.NoSuchMethodError #3002
- Comments
- sgeorge1970 commented Feb 10, 2021
- ososmam commented Feb 16, 2021 •
- Quawetim commented Mar 1, 2021
- hbaInfinity commented Apr 12, 2021
- MoodyMuffin commented Apr 13, 2021
- mgrogin commented Apr 14, 2021
- hbaInfinity commented Apr 15, 2021
- MoodyMuffin commented Apr 16, 2021 •
- hbaInfinity commented Apr 19, 2021 •
- MoodyMuffin commented Apr 19, 2021
- hbaInfinity commented Apr 19, 2021
- jonathanlindvall commented Apr 22, 2021 •
- mgrogin commented Apr 22, 2021 •
- mgrogin commented Apr 22, 2021
- leandersonralves commented May 19, 2021
- mgrogin commented Jun 24, 2021
- mgrogin commented Jun 24, 2021
Как исправить ошибку java.lang.NoSuchMethodError?
Ошибка java.lang.NoSuchMethodError на Java выдается, когда программа пытается вызвать метод класса, который не существует. Метод может быть статическим или также может быть методом экземпляра.
В большинстве случаев java.lang.NoSuchMethodError перехватывается компилятором, но иногда это может происходить во время выполнения. Если эта ошибка возникает во время выполнения, то единственной причиной может быть изменение структуры класса, которое сделало ее несовместимой.
Давайте разберем подробнее как исправить ошибку, у нас есть два класса Data и Temp, как показано ниже.
Давайте запустим их через командную строку. Обратите внимание, что я не использую Eclipse или какую-либо другую IDE, чтобы избежать обнаружения этой ошибки во время компиляции.
pankaj:Downloads pankaj$ javac Data.java
pankaj:Downloads pankaj$ javac Temp.java
pankaj:Downloads pankaj$ java Temp
foo
bar
pankaj:Downloads pankaj$
Итак, программа выполнена, давайте продолжим и изменим определение класса данных, как показано ниже.
Обратите внимание, что я удалил метод bar(). Теперь нам нужно будет скомпилировать только класс данных, а не основной класс.
Мы получили ошибку java.lang.NoSuchMethodError, потому что класс Data стал несовместим с классом Temp. Если бы мы попытались скомпилировать класс Data, мы получили бы ошибку, как показано ниже.
Есть две основные причины:
- Версия Jar, используемая во время компиляции, отличается от версии среды выполнения. Например, у вас мог бы быть MySQL jar в вашем приложении, имеющим другую версию от того, что присутствует в папке lib Tomcat. Поскольку Tomcat lib folder jars сначала просматривается Java Classloader, тогда возможна эта ошибка, если какой-либо метод не найден в загруженном классе.
- Конфликт из-за того же имени класса. Например, приложение использует сторонний jar-файл с таким же полным именем класса, как у вас. Поэтому, если classloader загружает класс из другого jar.
Отладка java.lang.NoSuchMethodError
Вы можете использовать java runtime option-verbose:class, чтобы получить информацию о jar, который используется для загрузки класса. Эту конфигурацию можно задать в tomcat catalina.sh или setenv.sh.
JAVA_OPTS=»$JAVA_OPTS -verbose:class»
Затем вы увидите логи, подобные приведенным ниже, которые очень полезны для выяснения фактического jar-файла, используемого при загрузке класса, и причины java.lang.NoSuchMethodError во время выполнения.
Средняя оценка / 5. Количество голосов:
Спасибо, помогите другим — напишите комментарий, добавьте информации к статье.
Или поделись статьей
Видим, что вы не нашли ответ на свой вопрос.
Источник
java.lang.NoSuchMethodError: ‘void com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTests$default(com.android.build.api.extension.AndroidComponentsExtension, com.android.build.api.extension.VariantSelector, kotlin.jvm.functions.Function1, int, java.lang.Object)’ #2631
Comments
ColtonIdle commented May 19, 2021
Studio Build: BB canary1 Version of Gradle Plugin: 7.1 alpha01 Version of Gradle: 7.0.2
I have a project that is updated and work with Arctic Fox beta01 and AGP 7.0 beta01.
I installed bumblebee and got the upgrade assistant. After hitting the accept button I can see in git that the diff is:
For reference here are my hilt dependency declarations
When I hit clean or sync I get the following error:
Originally filed here before I saw Hilt in the stacktrace: https://issuetracker.google.com/issues/188563075
The text was updated successfully, but these errors were encountered:
Tgo1014 commented May 19, 2021
I’m having the same issue. Any workaround? Is there a way to make Canary run with an old alpha version? The latest stable breaks my .kts files.
shakil807g commented May 19, 2021
Having same issue with
AGP:
classpath «com.android.tools.build:gradle:7.1.0-alpha01»
slavonnet commented May 19, 2021
I’m having the same issue. Any workaround? Is there a way to make Canary run with an old alpha version? The latest stable breaks my .kts files.
You can run beta. Its work and its like cannary 15
danysantiago commented May 19, 2021
This is a duplicate of #2618, its fixed but we haven’t made a release, if you want to get unblock you can use snapshot versions of Hilt from https://oss.sonatype.org/content/repositories/snapshots/com/google/dagger/
b95505017 commented May 19, 2021
@danysantiago I tried snapshot but get this error:
danysantiago commented May 19, 2021
@b95505017 thats not good. can you try only using the HEAD-SNAPSHOT version of the plugin and keep the rest of the dependencies as you had them?
I need to investigate why that symbol is not found, when it is here
b95505017 commented May 19, 2021
@danysantiago It works when only use snapshot of the plugin!
ColtonIdle commented May 20, 2021
@b95505017 I’m new to «snapshots». Can you let me know how you got this working?
SimonMarquis commented May 20, 2021
@ColtonIdle to use the snapshot version, add something like this to your buildsript
ColtonIdle commented May 21, 2021
Thank you @SimonMarquis that helped! Really appreciate it!
gulabsagevadiya commented Jun 8, 2021 •
@ColtonIdle to use the snapshot version, add something like this to your buildsript
i got this error while using this
A problem occurred evaluating root project ‘ComposeTrailApp’.
Could not set unknown property ‘url’ for repository container of type org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler.
Any Idea what to do
SimonMarquis commented Jun 8, 2021
@gulabsagevadiya you shouldn’t have to rely on a snapshot version anymore since version 2.36 is released: #2634 (comment)
rock3r commented Jun 17, 2021 •
I’m having the same issue with AGP 7.0 b04, Gradle 7.1, Dagger 2.37 and all dependencies to their latest versions:
EDIT: tried the snapshot, the sync completes but I’m having other issues when running, will update here when I figure it out
mwy3055 commented Jun 17, 2021 •
@rock3r Well I had same problem, solved with AGP 7.1.0-alpha02, Gradle 7.0.2, and Hilt 2.37. Try this.
slavonnet commented Jun 17, 2021 •
try kapt.use.worker.api=false
ub feadkle pro
also try commentr plugin appoly, sync, look for errors (plugin not appliex if errors in sync and sync syccess becouse its can»t find added dependencyu), uncomment, sync
I’m having the same issue with AGP 7.0 b04, Gradle 7.1, Dagger 2.37 and all dependencies to their latest versions:
EDIT: tried the snapshot, the sync completes but I’m having other issues when running, will update here when I figure it out
Источник
AndroidJavaException: java.lang.NoSuchMethodError #3002
Comments
sgeorge1970 commented Feb 10, 2021
When calling PlayGamesPlatform.Instance.LoadScores
I am getting this error:
AndroidJavaException: java.lang.NoSuchMethodError: no non-static method with name=’getStatusCode’ signature='()I’ in class Ljava.lang.Object;
I’m using 0.10.12 GPS unity package
this does not occur if I go to 0.9.64 GPS unity package
Any guidance would be great!
Steve
The text was updated successfully, but these errors were encountered:
ososmam commented Feb 16, 2021 •
Same with PlayGamesPlatform.Instance.SavedGame.OpenWithAutomaticConflictResolution using 0.10.12
Quawetim commented Mar 1, 2021
Same with PlayGamesPlatform.Instance.SavedGame.OpenWithAutomaticConflictResolution using 0.10.12
hbaInfinity commented Apr 12, 2021
I can confirm the exact same message as the above people using 0.10.12. This was not happening in previous versions. This is also failing on the PlayGamesPlatform.Instance.SavedGame.OpenWithAutomaticConflictResolution call above.
The weird thing is that it is only happening on some devices. I am currently testing on a Samsung A30 on Android 10 (security patch 1st March 2021) where it all works perfectly, but another phone using the exact same Google Play log in, which is the Oppo AX5s on Android 8.1.0 (security patch 5th Feburary 2021) is failing with the issue above.
MoodyMuffin commented Apr 13, 2021
When calling PlayGamesPlatform.Instance.LoadScores
I am getting this error:
AndroidJavaException: java.lang.NoSuchMethodError: no non-static method with name=’getStatusCode’ signature='()I’ in class Ljava.lang.Object;
I’m using 0.10.12 GPS unity package
this does not occur if I go to 0.9.64 GPS unity package
Any guidance would be great!
Steve
mgrogin commented Apr 14, 2021
hbaInfinity commented Apr 15, 2021
Just as something else I have seen with this issue, it seems like it is affecting logging into the Google Play Games account on the device that it affects. Here is the current flow of what I am observing:
- Game Starts, The «Hi There, [ACCOUNT_NAME]» message shows up.
- Game attempts to download the Cloud Save for this user, but we get the error: AndroidJavaException: java.lang.NoSuchMethodError: no non-static method with name=’getStatusCode’ signature='()I’ in class Ljava.lang.Object;
- When we enter into our Settings Menu, sometimes the game will detect that we have been logged in (using Social.localUser.authenticated), but occasionally we will be signed out again, so we have to manually sign back in.
- We have a button in game that attempts to save the data to the cloud, but when we call the ((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate, it returns back an error with AuthenticationError, which should only happen if the user isn’t signed in.
This is happening on the Oppo AX5s on Google Play Services plugin 0.10.12, but everything works fine on a Samsung A30.
As a side note, these same devices work with this plugin on one of our other games, with the exact same code, but running on 0.10.04.
Any help on how to fix this is appreciated, as it is breaking almost all of our Google interactions on these devices.
MoodyMuffin commented Apr 16, 2021 •
I made a quick temporary fix, not beautiful, but it worked for me. Here is the idea:
In my case error happens inside AndroidSavedGameClient.cs in method ‘AddOnFailureListenerWithSignOut’
We add ‘AddOnFailureListener’ and try to call ‘getStatusCode’ from Exception object. But ‘getStatusCode’ is method for ApiException, which inherited from Exception. Exception doesn’t have this method. I think this is the problem. So I cast Exception to ApiException if it possible, and after that trying to call getStatusCode. I do it in java class and call it from Unity.
Unity method which I’m calling instead of ‘getStatusCode’:
public static int GetStatusCode(AndroidJavaObject exception) < using (var native = new AndroidJavaClass("com. .ExceptionsUtils")) < return native.CallStatic ("GetStatusCode", exception); >>
Code for native java class:
import com.google.android.gms.common.api.ApiException; import com.google.android.gms.common.api.CommonStatusCodes; @UnityCallable public class ExceptionsUtils < @UnityCallable public static int GetStatusCode(Exception ex) < if (ex instanceof ApiException) < return ((ApiException) ex).getStatusCode(); >return CommonStatusCodes.ERROR; > >
Also I replaced the same way other cases of using ‘getStatusCode’ for Exception object
hbaInfinity commented Apr 19, 2021 •
Thanks for the heads up on a way to fix this issue. I have used the code that you have provided, but I don’t seem to be having much luck getting the c# code to nicely work with the native function. I’ve double checked on how to implement native .java classes (it seems like they made it much easier than it used to be before 2018.3), although I keep getting the NoSuchMethodError on the GetStatusCode call. Do you know if there is any specific location that the java file needs to exist (e.g. Plugins/Android), or defining the package of the java file (or does it only use the Package Name), or affected by Gradle build settings?
Any pointers on this would be appreciated!
MoodyMuffin commented Apr 19, 2021
Thanks for the heads up on a way to fix this issue. I have used the code that you have provided, but I don’t seem to be having much luck getting the c# code to nicely work with the native function. I’ve double checked on how to implement native .java classes (it seems like they made it much easier than it used to be before 2018.3), although I keep getting the NoSuchMethodError on the GetStatusCode call. Do you know if there is any specific location that the java file needs to exist (e.g. Plugins/Android), or defining the package of the java file (or does it only use the Package Name), or affected by Gradle build settings?
Any pointers on this would be appreciated!
Hey
In java file I define package name, like: ‘package com.A.B.C.D;’
java file is located inside app/src/main/java/com/A/B/C/D
And in C# file I call new AndroidJavaClass(«com.A.B.C.D.ExceptionsUtils»)
Also, this package is added in proguard-unity.txt, maybe you should try it too
hbaInfinity commented Apr 19, 2021
Thanks, After double checking, the java file does indeed get exported to the app/src/main/java/com/. directory when I build a gradle project, and I have defined the package name to be the same in the Java script and the C# script. The only main difference I have between the code is the that I let Unity generate the proguard-unity.txt, and that I am unable to get @UnityCallable compiling as it «Cannot Find Symbol». From what I have read up, it seems like just an interface in the Facebook plugin, but it doesn’t seem like it does too much, and other examples I have seen do not require it.
I do hate Unity’s lack of documentation on this stuff though, which would make things much easier than just a few dot points.
jonathanlindvall commented Apr 22, 2021 •
We just ran into the exact same issue after adding a 2nd OAuth credential (to be able to test Games Services when building locally with the Debug certificate). In our case, it seems like the problem was related to Saved Games. Turns out we had a cloud save that had been uploaded from an Internal Test version of the app, signed with Play App Signing. The app signed with the Debug certificate was not able to download this cloud save and crashed with the NoSuchMethodError (getStatusCode).
We were able to solve it by deleting the Play Games data for the game through the Play Games app ( Settings > Delete Play Games account & data ). Not sure if this is the same issue that you guys are having, but it might be worth a try if you’re using multiple OAuth credentials.
mgrogin commented Apr 22, 2021 •
I’m still looking for a perfect solution but figure this will help the community find the actual problem.
based on what @MoodyMuffin said I use this c# code that has an extension function that casts the AndroidJavaObject to com.google.android.gms.common.api.ApiException without having to use a java plugin.
So far I see that the object has been of 3 types:
«com.google.android.gms.common.api.ApiException»,
«com.google.games.bridge.TokenResult»,
«java.lang.IllegalStateException» // doesnt have getStatusCode function
By doing this I was able to see this error:
I/Unity: LoadScores failed: java.lang.IllegalStateException: Max results must be between 1 and 30
I think the bug might be related to this somehow.
Waiting to hear if anyone has any improvements or better solutions
heres the code:
mgrogin commented Apr 22, 2021
There’s still a bug with public void LoadScores(ILeaderboard board, Action callback) in PlayGamesPlatform.cs
Still getting the error though..
leandersonralves commented May 19, 2021
Hi folks, until some seconds ago, I was fighting against this issue.
But, I found a problem in my code.
I was building a Metadata with a PNG cover data with a Array Lenght equals zero.
I just remove this wrong line and solved. tadãh!
I suposse that I must pass a array with length zero in case without a png cover.
mgrogin commented Jun 24, 2021
Im still getting this message «Max results must be between 1 and 30» from the HandleLoadingScores function sending rowcount=75 . I tried maxing it to 25, that get rid of the message but I’m not getting the leaderboard results. any ideas?
mgrogin commented Jun 24, 2021
@aerialninja I see you made some changes to the github
What do you think about this change? #3002 (comment)
What do we need to do to get it in the next build and to make sure it’s correct? what’s the procces?
thanks in advance!
Источник