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 <package>.BaseActivity$Companion.getANIMATION_SLIDE_FROM_RIGHT()' is inaccessible to class '<package>.MyActivity' (declaration of '<package>.MyActivity' appears in /data/app/<package>-mg7eYmJ8hX5WvkNWNZWMVg==/base.apk!classes3.dex)
As you can see there is class called BaseActivity
which looks like this:
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
}
Now every activity extends this class and often overrides the animationKind
like this:
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 <package>
versionCode <versionCode>
versionName <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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…