I am trying to run Akka (typed) on Android 8. However when I try to create the ActorSystem it fails because the akka.util.Unsafe class try to access a missing "value" field on String:
// 'instance' being of type sun.misc.Unsafe
stringValueFieldOffset = instance.objectFieldOffset(String.class.getDeclaredField("value"));
Caused by: java.lang.NoSuchFieldException: No field value in class Ljava/lang/String; (declaration of 'java.lang.String' appears in /system/framework/core-oj.jar)
at java.lang.Class.getDeclaredField(Native Method)
at akka.util.Unsafe.(Unsafe.java:36)
I tried with Akka 2.6.19 and 2.5.32 but also 2.5.21 with Scala 2.11 but both fails at the same point. I am running it on Android 8.0 (which is a requirement).
Has anyone experienced the same issue and found a solution?
I cannot change the Android version. However, I can change Akka while I would like to use Akka-typed and a recent/supported version.
EDIT; I was not able to find a solution yet. However, I opened a discussion on the project: https://github.com/akka/akka/pull/23710#issuecomment-1091817062
Related
After updating org.tensorflow:tensorflow-lite-metadata, org.tensorflow:tensorflow-lite-task-vision and org.tensorflow:tensorflow-lite-support app falls with error:
java.lang.NoSuchMethodError: No static method create(Ljava/nio/ByteBuffer;Lorg/tensorflow/lite/InterpreterApi$Options;)Lorg/tensorflow/lite/InterpreterApi; in class Lorg/tensorflow/lite/InterpreterApi; or its super classes (declaration of 'org.tensorflow.lite.InterpreterApi' appears in /data/app/~~iBlhCFEsffVRgKI8jlh50w==/com.po4yka.dancer.debug-dw8TLYwUobxDEHmwOF5CSg==/base.apk!classes2.dex)
What could be wrong? I couldn't find any breaking changes in changelog.
If you're using Android Studio ML Binding, it has not been upgraded to tflite-support 0.4 yet. You should continue using tflite-support 0.3.1.
See: https://github.com/tensorflow/tflite-support/issues/824
Azure is calling:
URLEncoder.encode(encodeBase64String(...
which works fine on Android 9 and above. But on old phones I get:
Caused by: java.lang.NoSuchMethodError: No static method encodeBase64String([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
I have tried adding in :
implementation "commons-codec:commons-codec:1.14"
to build.gradle, but it does not seem to have an effect. What is the usual way to handle it when a class you didn't write that is part of an external SDK, is calling a method old phones don't support?
You should try with below code:
String encodedString = new String(Base64.encodeBase64(bytes));
We had Mockito version 2.18.3. Now I upgraded to 3.5.13.
Also Robolectric version is upgraded from 3.8 to 4.4.
So half of 700 tests started failing on different reasons. One of them is as below that mockito can't create Context class.
Other classes it could not mock now, for ex, are many interfaces of our codebase, classes, android.app.Activity, android.location.Location.
Any help will be highly appreciated. Thanks!
net.abc.def.MyTest > FirstTest FAILED
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class android.content.Context.
If you're not sure why you're getting this error, please report to the mailing list.
Java : 1.8
JVM vendor name : Private Build
JVM vendor version : 25.265-b01
JVM name : OpenJDK 64-Bit Server VM
JVM version : 1.8.0_265-8u265-b01-0ubuntu2~16.04-b01
JVM info : mixed mode
OS name : Linux
OS version : 4.4.0-57-generic
You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.
Underlying exception : org.mockito.exceptions.base.MockitoException: Could not modify all classes [class android.content.Context]
at net.abc.def.MyTest.onSetUp(FirstTest.java:51)
Caused by:
org.mockito.exceptions.base.MockitoException: Could not modify all classes [class android.content.Context]
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:153)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:366)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:175)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:377)
... 1 more
Caused by:
java.lang.IllegalStateException:
Byte Buddy could not instrument all classes within the mock's type hierarchy
This problem should never occur for javac-compiled classes. This problem has been observed for classes that are:
- Compiled by older versions of scalac
- Classes that are part of the Android distribution
at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.triggerRetransformation(InlineBytecodeGenerator.java:265)
at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.mockClass(InlineBytecodeGenerator.java:212)
at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:46)
at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:43)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:153)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:366)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:175)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:377)
at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:36)
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.createMockType(InlineByteBuddyMockMaker.java:379)
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.doCreateMock(InlineByteBuddyMockMaker.java:339)
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.createMock(InlineByteBuddyMockMaker.java:318)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:52)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:61)
at org.mockito.Mockito.mock(Mockito.java:1949)
at org.mockito.Mockito.mock(Mockito.java:1860)
... 1 more
Caused by:
java.lang.UnsupportedClassVersionError: android/os/Bundle has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at net.bytebuddy.description.method.MethodList$ForLoadedMethods.<init>(MethodList.java:109)
at net.bytebuddy.description.type.TypeDescription$ForLoadedType.getDeclaredMethods(TypeDescription.java:8715)
at net.bytebuddy.dynamic.scaffold.InstrumentedType$Factory$Default$1.represent(InstrumentedType.java:416)
at net.bytebuddy.ByteBuddy.redefine(ByteBuddy.java:782)
at net.bytebuddy.ByteBuddy.redefine(ByteBuddy.java:757)
at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.transform(InlineBytecodeGenerator.java:364)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.triggerRetransformation(InlineBytecodeGenerator.java:261)
... 16 more
We had 2 year old gradle version which was 3.3.1. So, when I tried to raise gradle version directly to the latest 4.x, some issues while running unit tests have popped up..so had to raise mockito also and that ended up with this problem.
Had become messy and did not know how to fix that.
Just changed the approach - started raising the gradle version one by one instead of jumping directly to the latest from such a old one. And that went smooth and all good now.
So if you are in the same situation..raise versions one by one instead of hopping long.
I am facing an issue while trying to apply ProGuard on a private library release - written in Kotlin. Without ProGuard, the AAR file generated works perfectly out of the box but after applying ProGuard, I have the following error:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/package/name/CustomInterface$DefaultImpls;
The CustomClass that I need implements the CustomInterface but when I try to call any method of the CustomClass, I get this error.
Already tried setting the kotlinOptions.JvmTarget=1.8 but doesn't work.
This all started with this error when running instrumentation tests:
java.lang.NoSuchMethodError: No static method closeQuietly(Ljava/net/ServerSocket;)V in class Lokhttp3/internal/Util; or its super classes (declaration of 'okhttp3.internal.Util' appears in /data/app/com.example-vKdPJoTLl49ntRbZfsRBqQ==/base.apk!classes2.dex)
at okhttp3.mockwebserver.MockWebServer$2.execute(MockWebServer.java:333)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
I went looking into the generated test.apk to see what was present/missing in dex files.
First thing I noticed is that the test apk has two .dex files. Why? I'm not using multidex (and IIRC multidex doesn't work on test apks anyways). I then added up the two "referenced method counts" and sure enough I'm over the 65k limit. So is AGP auto-multi-dexing my test apk?
Furthermore I see the "missing" method in the first dex.
Why is it listed as a "reference" not a "defined" method? It's not like there is an OkHttp Util class provided by the framework.
In the initial crash, it said it can't find method in classes2.dex. Why is it looking in classes2.dex? Why not look in both?
I'm keeping everything in my test apk (using proguard but keeping everything) (maybe this explains the +65k ref methods). So why is this getting stripped/screwed with in the first place.
UPDATE:
It turns out this method was needed in my app .apk (not the test .apk). When I updated my proguard rules for the app apk everything worked. I still don't know why this class is needed in-app?
java.lang.NoSuchMethodError:
No static method closeQuietly(java.net.ServerSocket) in class okhttp3.internal.Util;
method closeQuietly(java.net.ServerSocket) might not be in use.
to explicitly keep it:
-keep class okhttp3.internal.Util {
public static void closeQuietly(java.net.ServerSocket);
}
I don't know how I didn't know this but apparently multidex is enabled by default on API 21+
https://developer.android.com/studio/build/multidex#mdex-on-l
Therefore, if your minSdkVersion is 21 or higher multidex is enabled
by default, and you do not need the multidex support library.
So yeah, this is normal. What might be happening is that the class is just not in the first dex file.