Java lang illegalaccesserror android

IllegalAccessError after updating Android Studio

After updating to the latest Google Services and Firebase library versions my previously stable application (99.6% crash free users) has become unstable with 25% of users beginning to experience crashes. I changed no code in my application. The only changes I made were to the Grade files to update to the latest versions. I am getting an error that I can find no information about online anywhere:

Exception java.lang.IllegalAccessError: com.google.android.gms.measurement.AppMeasurementService dalvik.system.DexFile.defineClassNative (DexFile.java) dalvik.system.DexFile.defineClass (DexFile.java:226) dalvik.system.DexFile.loadClassBinaryName (DexFile.java:219) dalvik.system.DexPathList.findClass (DexPathList.java:338) dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:54) java.lang.ClassLoader.loadClass (ClassLoader.java:511) java.lang.ClassLoader.loadClass (ClassLoader.java:469) android.app.ActivityThread.handleCreateService (ActivityThread.java:2859) android.app.ActivityThread.-wrap4 (ActivityThread.java) android.app.ActivityThread$H.handleMessage (ActivityThread.java:1427) android.os.Handler.dispatchMessage (Handler.java:102) android.os.Looper.loop (Looper.java:148) android.app.ActivityThread.main (ActivityThread.java:5421) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616) 
Exception java.lang.IllegalAccessError: Interface com.google.android.gms.internal.measurement.zzge implemented by class com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver is inaccessible (declaration of 'com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver' appears in /data/app/com.mycompanyname/base.apk) java.lang.VMClassLoader.findLoadedClass (VMClassLoader.java) java.lang.ClassLoader.findLoadedClass (ClassLoader.java:738) java.lang.ClassLoader.loadClass (ClassLoader.java:363) java.lang.ClassLoader.loadClass (ClassLoader.java:312) android.app.ActivityThread.handleReceiver (ActivityThread.java:3299) android.app.ActivityThread.-wrap17 () android.app.ActivityThread$H.handleMessage (ActivityThread.java:1771) android.os.Handler.dispatchMessage (Handler.java:106) android.os.Looper.loop (Looper.java:164) android.app.ActivityThread.main (ActivityThread.java:6753) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:482) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807) 
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript < repositories < jcenter() google() maven < url 'https://maven.fabric.io/public' >> dependencies < classpath 'com.android.tools.build:gradle:3.1.2' classpath 'io.fabric.tools:gradle:1.25.4' classpath 'com.google.gms:google-services:3.2.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files >> allprojects < repositories < jcenter() maven < url 'https://maven.google.com/' >> > task clean(type: Delete)
apply plugin: 'com.android.application' apply plugin: 'io.fabric' android < compileSdkVersion 26 buildToolsVersion '27.0.3' flavorDimensions "default" defaultConfig < minSdkVersion 15 targetSdkVersion 26 >buildTypes < release < minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' >> > dependencies < implementation fileTree(include: ['*.jar'], dir: 'libs') /*implementation 'com.android.support:appcompat-v7:23.4.0'*/ implementation 'com.android.support:support-v4:26.1.0' implementation 'com.google.firebase:firebase-appindexing:15.0.1' implementation 'com.google.firebase:firebase-crash:16.0.0' implementation 'com.google.firebase:firebase-ads:15.0.1' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.3' testImplementation 'junit:junit:4.12' >apply plugin: 'com.google.gms.google-services' 
-dontwarn com.google.android.gms.** -keep class com.firebase.** < *; >-keep class com.google.android.gms.** < *; >-keep class org.apache.** < *; >-keep class com.android.vending.billing.** -keepnames class com.firebase.** < *; >-keepnames class com.google.android.gms.** < *; >-keepnames class com.fasterxml.jackson.** < *; >-keepnames class javax.servlet.** < *; >-keepnames class org.ietf.jgss.**

Update: I thought maybe I had reached the point that I needed to multidex. But analysing the APK shows «This dex file defines 5112 classes with 30311 methods, and references 36641 methods.» Interestingly, contrasting this new bad APK with the old working one, the new one has a lot of libraries additional to it, things like play-services-basement, play-services-gass, etc.

Читайте также:  Убрать лишние символы python

Источник

Illegal Access Error Class

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Thrown if an application attempts to access or modify a field, or to call a method that it does not have access to.

[Android.Runtime.Register("java/lang/IllegalAccessError", DoNotGenerateAcw=true)] public class IllegalAccessError : Java.Lang.IncompatibleClassChangeError
[] type IllegalAccessError = class inherit IncompatibleClassChangeError

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

Constructs an IllegalAccessError with no detail message.

A constructor used when creating managed representations of JNI objects; called by the runtime.

Constructs an IllegalAccessError with the specified detail message.

Fields

Properties

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

The handle to the underlying Android instance.

Creates a localized description of this throwable.

Returns the detail message string of this throwable.

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Appends the specified exception to the exceptions that were suppressed in order to deliver this exception.

Fills in the execution stack trace.

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Returns an array containing all of the exceptions that were suppressed, typically by the try -with-resources statement, in order to deliver this exception.

Initializes the cause of this throwable to the specified value.

Prints this throwable and its backtrace to the standard error stream.

Prints this throwable and its backtrace to the specified print stream.

Prints this throwable and its backtrace to the specified print writer.

Sets the stack trace elements that will be returned by #getStackTrace() and printed by #printStackTrace() and related methods.

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Throwable)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Throwable)
IJavaPeerable.Finalized() (Inherited from Throwable)
IJavaPeerable.JniManagedPeerState (Inherited from Throwable)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Throwable)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Throwable)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Throwable)

Extension Methods

Performs an Android runtime-checked type conversion.

Источник

java.lang.IllegalAccessError: tried to access method

This happens when accessing a package scoped method of a class that is in the same package but is in a different jar and classloader.

This was my source, but the link is now broken. Following is full text from google cache:

Packages (as in package access) are scoped per ClassLoader.

You state that the parent ClassLoader loads the interface and the child ClassLoader loads the implementation. This won’t work because of the ClassLoader-specific nature of package scoping. The interface isn’t visible to the implementation class because, even though it’s the same package name, they’re in different ClassLoaders.

I only skimmed the posts in this thread, but I think you’ve already discovered that this will work if you declare the interface to be public. It would also work to have both interface and implementation loaded by the same ClassLoader.

Really, if you expect arbitrary folks to implement the interface (which you apparently do if the implementation is being loaded by a different ClassLoader), then you should make the interface public.

The ClassLoader-scoping of package scope (which applies to accessing package methods, variables, etc.) is similar to the general ClassLoader-scoping of class names. For example, I can define two classes, both named com.foo.Bar, with entirely different implementation code if I define them in separate ClassLoaders.

Источник

IllegalAccessError: Method is inaccessible to class

I’ve got very strange error, because it only happens after installing app from generated .apk . When I try to run the app through IDE, it works fine.

java.lang.IllegalAccessError: Method 'int .BaseActivity$Companion.getANIMATION_SLIDE_FROM_RIGHT()' is inaccessible to class '.MyActivity' (declaration of '.MyActivity' appears in /data/app/-mg7eYmJ8hX5WvkNWNZWMVg==/base.apk!classes3.dex) 
open class BaseActivity : AppCompatActivity() < companion object < @JvmStatic protected val ANIMATION_DEFAULT = 0 @JvmStatic protected val ANIMATION_SLIDE_FROM_RIGHT = 1 @JvmStatic protected val ANIMATION_SLIDE_FROM_BOTTOM = 2 >protected open var animationKind = ANIMATION_DEFAULT // Some other stuff > 
class MyActivity: BaseActivity() < override var animationKind = ANIMATION_SLIDE_FROM_RIGHT // Some other stuff >

The problem is that ANIMATION_SLIDE_FROM_RIGHT is inaccessible for MyActivity . I will repeat that it only happens on manually generated .apk . The funny thing is that I’m not using multidex, but error seems to show that BaseActivity is in classes3.dex . Here is my gradle file: apply plugin: ‘com.android.application’ apply plugin: ‘kotlin-android’ apply plugin: ‘kotlin-android-extensions’ apply plugin: ‘kotlin-kapt’

android < compileSdkVersion 28 defaultConfig < applicationId versionCode versionName minSdkVersion 21 targetSdkVersion 28 > buildTypes < release < minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' >> androidExtensions < experimental = true >> dependencies < // Dependencies >

I tried to play with multidexEnabled false/true , but the only change is that in false state the classes3.dex suffix disappears. UPDATE Of course when I change MyActivity ‘s animationKind property to 1 , then everything works fine. UPDATE 2 After removing @JvmStatic and protected visibility it works fine.

Источник

Оцените статью